HOG特征显示C++ OpenCV代码

参考:http://download.csdn.net/detail/u011285477/9472067

#include   
#include   
#include   
#include   
#include "opencvtest.h"

using namespace std;
using namespace cv;

// HOGDescriptor visual_imagealizer
// adapted for arbitrary size of feature sets and training images
Mat get_hogdescriptor_visual_image(Mat& origImg,
	vector& descriptorValues,//hog特征向量
	Size winSize,//图片窗口大小
	Size cellSize,
	int scaleFactor,//缩放背景图像的比例
	double viz_factor)//缩放hog特征的线长比例
{
	Mat visual_image;//最后可视化的图像大小
	resize(origImg, visual_image, Size(origImg.cols*scaleFactor, origImg.rows*scaleFactor));

	int gradientBinSize = 9;
	// dividing 180° into 9 bins, how large (in rad) is one bin?
	float radRangeForOneBin = 3.14 / (float)gradientBinSize; //pi=3.14对应180°

	// prepare data structure: 9 orientation / gradient strenghts for each cell
	int cells_in_x_dir = winSize.width / cellSize.width;//x方向上的cell个数
	int cells_in_y_dir = winSize.height / cellSize.height;//y方向上的cell个数
	int totalnrofcells = cells_in_x_dir * cells_in_y_dir;//cell的总个数
	//注意此处三维数组的定义格式
	//int ***b;
	//int a[2][3][4];
	//int (*b)[3][4] = a;
	//gradientStrengths[cells_in_y_dir][cells_in_x_dir][9]
	float*** gradientStrengths = new float**[cells_in_y_dir];
	int** cellUpdateCounter = new int*[cells_in_y_dir];
	for (int y = 0; y des;//HOG特征向量

	Mat dst;
	resize(src, dst, Size(width, height));//规范图像尺寸
	imshow("src", src);
	hog.compute(dst,des);//计算hog特征
	Mat background = Mat::zeros(Size(width,height),CV_8UC1);//设置黑色背景图,因为要用白色绘制hog特征

	Mat d = get_hogdescriptor_visual_image(background,des,hog.winSize,hog.cellSize,3,2.5);
	imshow("dst",d);
	imwrite("hogvisualize.jpg",d);
	waitKey();

	return 0;
}


你可能感兴趣的:(基于视觉的目标识别+跟踪,C++,opencv学习)