Created
December 13, 2011 06:48
-
-
Save yoggy/1470956 to your computer and use it in GitHub Desktop.
OpenCV cv::HOGDescriptor & cv::gpu::HOGDescriptor sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SDKDDKVer.h> | |
#include <Windows.h> | |
#pragma warning(disable:4819) | |
#pragma warning(disable:4996) | |
// for OpenCV2 | |
#include "opencv2/imgproc/imgproc.hpp" | |
#include "opencv2/objdetect/objdetect.hpp" | |
#include "opencv2/gpu/gpu.hpp" | |
#include "opencv2/highgui/highgui.hpp" | |
#ifdef _DEBUG | |
#pragma comment(lib, "opencv_core231d.lib") | |
#pragma comment(lib, "opencv_imgproc231d.lib") | |
#pragma comment(lib, "opencv_objdetect231d.lib") | |
#pragma comment(lib, "opencv_gpu231d.lib") | |
#pragma comment(lib, "opencv_features2d231d.lib") | |
#pragma comment(lib, "opencv_highgui231d.lib") | |
#else | |
#pragma comment(lib, "opencv_core231.lib") | |
#pragma comment(lib, "opencv_imgproc231.lib") | |
#pragma comment(lib, "opencv_objdetect231.lib") | |
#pragma comment(lib, "opencv_objdetect231d.lib") | |
#pragma comment(lib, "opencv_gpu231.lib") | |
#pragma comment(lib, "opencv_features2d231.lib") | |
#pragma comment(lib, "opencv_highgui231.lib") | |
#endif | |
//#define USE_VIDEO_CAPTURE | |
//#define USE_GPU | |
int main(int argc, char** argv) | |
{ | |
cv::Mat src_img; | |
#ifdef USE_VIDEO_CAPTURE | |
cv::VideoCapture capture; | |
capture.set(CV_CAP_PROP_FRAME_WIDTH, 640); | |
capture.set(CV_CAP_PROP_FRAME_HEIGHT, 480); | |
capture.open(0); | |
#else | |
cv::Mat target_img = cv::imread("..\\img\\test_hog.jpg"); | |
#endif | |
#ifdef USE_GPU | |
cv::gpu::GpuMat src_gpu, mono_gpu; | |
cv::gpu::HOGDescriptor hog; | |
hog.setSVMDetector(cv::gpu::HOGDescriptor::getDefaultPeopleDetector()); | |
#else | |
cv::HOGDescriptor hog; | |
cv::Mat mono_img; | |
hog.setSVMDetector(cv::HOGDescriptor::getDefaultPeopleDetector()); | |
#endif | |
std::vector<cv::Rect> found; | |
while(true) { | |
#ifdef USE_VIDEO_CAPTURE | |
capture >> src_img; | |
#else | |
src_img = target_img.clone(); | |
#endif | |
#ifdef USE_GPU | |
src_gpu.upload(src_img); | |
cv::gpu::cvtColor(src_gpu, mono_gpu, CV_BGR2GRAY); | |
hog.detectMultiScale(mono_gpu, found); | |
#else | |
cv::cvtColor(src_img, mono_img, CV_BGR2GRAY); | |
hog.detectMultiScale(mono_img, found); | |
#endif | |
for(unsigned i = 0; i < found.size(); i++) { | |
cv::Rect r = found[i]; | |
rectangle(src_img, r.tl(), r.br(), cv::Scalar(0,255,0), 2); | |
} | |
cv::imshow("test", src_img); | |
int c = cv::waitKey(1); | |
if( c == 27) break; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment