OpenCV Humanoid Detection Hog

Source: Internet
Author: User
Tags scalar

#include"iostream"#include"Queue"using namespacestd; #include"opencv2/opencv.hpp"#include"Windows.h"#include"opencv2/core/core.hpp"#include"opencv2/highgui/highgui.hpp"#include"opencv2/imgproc/imgproc.hpp"#include"opencv2/objdetect/objdetect.hpp"using namespaceCV;intMain () {Try{iplimage*pframe =NULL; Cvcapture*pcapture =NULL; //pcapture = cvcreatecameracapture (-1); //pcapture = Cvcapturefromcam (0);Pcapture = Cvcapturefromfile ("c:\\c_c++ Code\\photo and video\\textvideo2.flv"); //pcapture = Cvcapturefromfile ("c:\\c_c++ Code\\photo and video\\textvideo1.flv");        if(!pcapture) {cout<<"File opened fail ..."<<Endl; return-1;        } Mat img;        Hogdescriptor Hog;        Rect R; intNnum =0;        Hog.setsvmdetector (Hogdescriptor::getdefaultpeopledetector ()); Vector<Rect>Found,found1; intI, J; Charstr[ -];  while(Pframe =Cvqueryframe (pcapture)) {Nnum++; Mat img= Cvarrtomat (Pframe,0);//iplimage turn into Mat                        if(Nnum >=3)            {                //for testingHog.detectmultiscale (IMG, found);                Found1.clear (); //-------------------to remove nested rectangular boxes------------------------                 for(i =0; I < found.size (); i++) {R=Found[i];  for(j =0; J < Found.size (); J + +)                    {                        if(I! = J && ((r&found[j]) = =r)) { Break; }                    }                    if(J = =found.size ())                    {Found1.push_back (R); }                }                //Draw Rectangle box for people travelling                 for(i =0; I < found1.size (); i++) {R=Found1[i]; Rectangle (img, R, Scalar (0,255,0),1); } nnum=0; }                         for(inti =0; I < found1.size (); i++) {R=Found1[i]; Rectangle (img, R, Scalar (0,255,0),1); } sprintf (str,"The track count is:%d", Found1.size ()); Puttext (IMG, str, cvpoint ( -, -), Cv_font_hershey_plain,0.8, Cv_rgb (0,0, -),1,8); Imshow ("Track people", IMG); if(Cvwaitkey ( *) >=0)                 Break; }    }    Catch(Exception &e) {cout<< e.what () <<Endl; }    return 1;}

Effect:

Picture Humanoid test:

#include"iostream"#include"Queue"using namespacestd; #include"opencv2/opencv.hpp"#include"Windows.h"#include"opencv2/core/core.hpp"#include"opencv2/highgui/highgui.hpp"#include"opencv2/imgproc/imgproc.hpp"#include"opencv2/objdetect/objdetect.hpp"intMainintargcChar**argv)    {Mat img; Vector<Rect>found; IMG= Imread ("c:\\c_c++ Code\\photo and Video\\text006.jpg");    Hogdescriptor Defaulthog;    Defaulthog.setsvmdetector (Hogdescriptor::getdefaultpeopledetector ()); //for testingDefaulthog.detectmultiscale (IMG, found); //Draw Rectangle, frame traveler     for(inti =0; I < found.size (); i++) {Rect R=Found[i]; Rectangle (img, R, Scalar (0,255,0),1); } Namedwindow ("Detecting Pedestrians", cv_window_autosize); Imshow ("Detecting Pedestrians", IMG); Waitkey (0); return 0;}

Border nesting to remove weight:

intMainintargcChar**argv)    {Mat img; Vector<Rect>found, foundrect; IMG= Imread ("c:\\c_c++ Code\\photo and Video\\text007.jpg");    Hogdescriptor Defaulthog;    Defaulthog.setsvmdetector (Hogdescriptor::getdefaultpeopledetector ()); //for testingDefaulthog.detectmultiscale (IMG, found); //Traverse found to find rectangles that are not nested     for(inti =0; I < found.size (); i++) {Rect R=Found[i]; intj =0;  for(; J < Found.size (); j + +){            //Roll out loops if nested            if(J! = I && (R & found[j]) = =R) Break; }        if(J = =found.size ())        {Foundrect.push_back (R); }    }    //draw a rectangle, circle a pedestrian     for(inti =0; I < foundrect.size (); i++) {Rect R=Foundrect[i]; Rectangle (img, r.tl (), R.Br (), Scalar (0,0,255),3); } Namedwindow ("Detecting Pedestrians", cv_window_autosize); Imshow ("Detecting Pedestrians", IMG); Waitkey (0); return 0;}
intMain () {Mat image= Imread ("c:\\c_c++ Code\\photo and Video\\text007jpg"); Imshow ("Hog", image); if(Image.empty ()) {cout<<"Read image failed"<<Endl; }    //1. Defining Hog ObjectsHogdescriptor Hog (Size ( -, the), Size ( -, -), Size (8,8), Size (8,8),9); //2. Set up the SVM classifierHog.setsvmdetector (Hogdescriptor::getdaimlerpeopledetector ());//using a trained pedestrian detection classifier//3. Detecting pedestrian areas on the test imageStd::vector<cv::rect>regions; Hog.detectmultiscale (image, regions,0, Cv::size (8,8), Cv::size ( +, +),1.05,1); //Show     for(size_t i =0; I < regions.size (); i++{cv::rectangle (image, Regions[i], Cv::scalar (0,0,255),2); } cv::imshow ("Hog", image); Cv::waitkey (0); return 0;}

OpenCV Humanoid Detection Hog

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.