search
尋找貓咪~QQ 地點 桃園市桃園區 Taoyuan , Taoyuan

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

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 
#include 

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 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()


熱門推薦

本文由 jashliaoeuwordpress 提供 原文連結

寵物協尋 相信 終究能找到回家的路
寫了7763篇文章,獲得2次喜歡
留言回覆
回覆
精彩推薦