cv::HOGDescriptor::HOGDescriptor( Size winSize, Size blockSize, 
    Size blockStride, Size cellSize, int nbins, int derivAperture = 1,
    double winSigma = -1, int histogramNormType = HOGDescripter::L2Hys, 
    double L2HysThreshold = 0.1, bool gammaCorrection = false,
    int nievels = HOGDescripter::DEFAULT_NLEVELS,
    bool signedGradient = false )

假设输入的图片是 64 x 128 的,cell 就会有 8 x 16 = 128个,block 就有 (8-2+1) x (16 - 2 + 1) = 105 个,每个 block 有 36 维向量,总共就是 105 x 36 = 3780维向量,这个向量就是对应这张图片的 HOG 特征。

winSize 窗口大小,就是图像的大小,如64 x 128 的图像。
blockSize,如2x2。
blockStride,每次窗口移动的距离一个size,如8x8。
cellSize,如8x8。
nbins,
derivAperture,
winSigma,
histogramNormType = HOGDescripter::L2Hys,
L2HysThreshold = 0.1,
gammaCorrection = false,是否伽马矫正。
HOGDescripter::DEFAULT_NLEVELS,
signedGradient = false,

主要是前面几个窗口的参数,其他参数和数学公式有关可以暂时忽略。

#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;

void test()
{
	Mat srcImage = imread("xingren.jpg");
	Mat grayImage, dstImage;
	cvtColor(srcImage, grayImage, COLOR_BGR2GRAY);
	resize(grayImage, dstImage, Size(64, 128));

	HOGDescriptor dectector(Size(64, 128), Size(16, 16), Size(8, 8), Size(8, 8), 9);

	// HOG的描述子
	vector<float> descriptors;
	vector<Point> locations;
	dectector.compute(dstImage, descriptors, Size(0, 0), Size(0, 0), locations);
	printf("HOG descriptors: %d\n", descriptors.size());
	imshow("dstImage", dstImage);
}

int main(int argc, char** argv)
{
	Mat srcImage = imread("xingren1.jpg");
	//imshow("srcImage", srcImage);

	HOGDescriptor hog = HOGDescriptor();
	hog.setSVMDetector(hog.getDefaultPeopleDetector());

	vector<Rect> peoples;
	hog.detectMultiScale(srcImage, peoples, 0, Size(8, 8), Size(32, 32), 1.05, 2);

	Mat result = srcImage.clone();
	for (size_t i = 0; i < peoples.size(); i++)
	{
		rectangle(result, peoples[i], Scalar(0, 0, 255), 2, 8, 0);
	}
	imshow("result", result);

	waitKey(0);
	return 0;
}

opencv_C++ HOG 特征检测示例

相关文章:

  • 2021-11-20
  • 2021-11-16
  • 2022-01-02
  • 2021-06-09
  • 2021-11-05
  • 2021-07-20
  • 2021-10-09
猜你喜欢
  • 2021-07-30
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-29
  • 2022-12-23
相关资源
相似解决方案