fanfuhan OpenCV 教學101 ~ opencv-101-HOG特徵描述子之多尺度 檢測/定位/標記

fanfuhan OpenCV 教學101 ~ opencv-101-HOG特徵描述子之多尺度 檢測/定位/標記

fanfuhan OpenCV 教學101 ~ opencv-101-HOG特徵描述子之多尺度 檢測/定位/標記

資料來源: https://fanfuhan.github.io/

https://fanfuhan.github.io/2019/05/17/opencv-101/

GITHUB:https://github.com/jash-git/fanfuhan_ML_OpenCV


HOG(定向梯度直方圖)特徵本身不支持旋轉不變性,通過金字塔可以支持多尺度檢測實現尺度空間不變性,OpenCV中支持HOG描述子多尺度檢測。


C++

#include <opencv2/opencv.hpp>
#include <iostream>

using namespace cv;
using namespace std;

int main(int argc, char** argv) {
	Mat src = imread("D:/images/pedestrian_02.png");
	if (src.empty()) {
		printf("could not load image..\n");
		return -1;
	}
	imshow("input", src);
	HOGDescriptor *hog = new HOGDescriptor();
	hog->setSVMDetector(hog->getDefaultPeopleDetector());
	vector<Rect> objects;
	hog->detectMultiScale(src, objects, 0.0, Size(4, 4), Size(8, 8), 1.05);
	for (int i = 0; i < objects.size(); i++) {
		rectangle(src, objects[i], Scalar(0, 0, 255), 2, 8, 0);
	}
	imshow("result", src);
	waitKey(0);
	return 0;
}


Python

"""
HOG特征描述子之多尺度检测
"""

import cv2 as cv

src = cv.imread("images/pedestrian.png")
hog = cv.HOGDescriptor()
hog.setSVMDetector(cv.HOGDescriptor_getDefaultPeopleDetector())
# detect people in image
(rects, weights) = hog.detectMultiScale(src, winStride=(4, 4),
                                        padding=(8, 8), scale=1.55,
                                        useMeanshiftGrouping=False)

for (x, y, w, h) in rects:
    cv.rectangle(src, (x, y), (x + w, y + h), (0, 255, 0), 2)

cv.imshow("hog-detector", src)

cv.waitKey(0)
cv.destroyAllWindows()

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *