PERF_TEST(HOGFixture, HOG) { Mat src = imread(getDataPath("gpu/hog/road.png"), cv::IMREAD_GRAYSCALE); ASSERT_TRUE(!src.empty()) << "can't open input image road.png"; vector<cv::Rect> found_locations; declare.in(src).time(5); if (RUN_PLAIN_IMPL) { HOGDescriptor hog; hog.setSVMDetector(hog.getDefaultPeopleDetector()); TEST_CYCLE() hog.detectMultiScale(src, found_locations); std::sort(found_locations.begin(), found_locations.end(), RectLess()); SANITY_CHECK(found_locations, 1 + DBL_EPSILON); } else if (RUN_OCL_IMPL) { ocl::HOGDescriptor ocl_hog; ocl_hog.setSVMDetector(ocl_hog.getDefaultPeopleDetector()); ocl::oclMat oclSrc(src); OCL_TEST_CYCLE() ocl_hog.detectMultiScale(oclSrc, found_locations); std::sort(found_locations.begin(), found_locations.end(), RectLess()); SANITY_CHECK(found_locations, 1 + DBL_EPSILON); } else OCL_PERF_ELSE }
void test_it( const Size & size ) { char key = 27; Scalar reference( 0, 255, 0 ); Scalar trained( 0, 0, 255 ); Mat img, draw; Ptr<SVM> svm; HOGDescriptor hog; HOGDescriptor my_hog; my_hog.winSize = size; VideoCapture video; vector< Rect > locations; // Load the trained SVM. svm = StatModel::load<SVM>( "my_people_detector.yml" ); // Set the trained svm to my_hog vector< float > hog_detector; get_svm_detector( svm, hog_detector ); my_hog.setSVMDetector( hog_detector ); // Set the people detector. hog.setSVMDetector( hog.getDefaultPeopleDetector() ); // Open the camera. video.open(0); if( !video.isOpened() ) { cerr << "Unable to open the device 0" << endl; exit( -1 ); } bool end_of_process = false; while( !end_of_process ) { video >> img; if( img.empty() ) break; draw = img.clone(); locations.clear(); hog.detectMultiScale( img, locations ); draw_locations( draw, locations, reference ); locations.clear(); my_hog.detectMultiScale( img, locations ); draw_locations( draw, locations, trained ); imshow( "Video", draw ); key = (char)waitKey( 10 ); if( 27 == key ) end_of_process = true; } }
void HOGTrainer::testIt(const string fileName) { if (trained != "") { char key = 27; Scalar sReference(0, 255, 0); Scalar sTrained(0, 0, 255); Mat img, draw; Ptr<SVM> svm; HOGDescriptor hog; HOGDescriptor my_hog; my_hog.winSize = size; VideoCapture *video; vector<Rect> locations; // Load the sTrained SVM. svm = StatModel::load<SVM>(trained); // Set the sTrained svm to my_hog vector<float> hog_detector; getSVMDetector(svm, hog_detector); my_hog.setSVMDetector(hog_detector); // Set the people detector. hog.setSVMDetector(hog.getDefaultPeopleDetector()); // Open the camera. video = new VideoCapture(fileName); if (!video->isOpened()) { cerr << "Unable to open the device 0" << endl; exit(-1); } bool end_of_process = false; while (!end_of_process) { video->read(img); if (img.empty()) break; draw = img.clone(); locations.clear(); hog.detectMultiScale(img, locations); drawLocations(draw, locations, sReference); locations.clear(); my_hog.detectMultiScale(img, locations); drawLocations(draw, locations, sTrained); imshow("Video", draw); key = (char) waitKey(10); if (27 == key) end_of_process = true; } } }
OCL_PERF_TEST(HOGFixture, HOG) { UMat src; imread(getDataPath("gpu/hog/road.png"), cv::IMREAD_GRAYSCALE).copyTo(src); ASSERT_FALSE(src.empty()); vector<cv::Rect> found_locations; declare.in(src); HOGDescriptor hog; hog.setSVMDetector(hog.getDefaultPeopleDetector()); OCL_TEST_CYCLE() hog.detectMultiScale(src, found_locations); std::sort(found_locations.begin(), found_locations.end(), RectLess()); SANITY_CHECK(found_locations, 3); }
OCL_TEST_P(HOG, GetDescriptors) { HOGDescriptor hog; hog.gammaCorrection = true; hog.setSVMDetector(hog.getDefaultPeopleDetector()); std::vector<float> cpu_descriptors; std::vector<float> gpu_descriptors; OCL_OFF(hog.compute(img, cpu_descriptors, hog.winSize)); OCL_ON(hog.compute(uimg, gpu_descriptors, hog.winSize)); Mat cpu_desc(cpu_descriptors), gpu_desc(gpu_descriptors); EXPECT_MAT_SIMILAR(cpu_desc, gpu_desc, 1e-1); }
OCL_TEST_P(HOG, Detect) { HOGDescriptor hog; hog.winSize = winSize; hog.gammaCorrection = true; if (winSize.width == 48 && winSize.height == 96) hog.setSVMDetector(hog.getDaimlerPeopleDetector()); else hog.setSVMDetector(hog.getDefaultPeopleDetector()); std::vector<Rect> cpu_found; std::vector<Rect> gpu_found; OCL_OFF(hog.detectMultiScale(img, cpu_found, 0, Size(8, 8), Size(0, 0), 1.05, 6)); OCL_ON(hog.detectMultiScale(uimg, gpu_found, 0, Size(8, 8), Size(0, 0), 1.05, 6)); EXPECT_LT(checkRectSimilarity(img.size(), cpu_found, gpu_found), 0.05); }