-3

I am training out the tutorial in opencv.

it had no error when compile.

I know the code for the tutorial is for opencv2.4 and I had change the coding for cvquery and videoframe.

My output is like this

.

My webcam is working fine but it not showing anything in my result.

sebenalern
  • 2,515
  • 3
  • 26
  • 36
Daren li
  • 1
  • 3
  • The statements "This is my code" and "I had change the coding" seem to contradict each other. – Dan Mašek Apr 02 '16 at 14:49
  • Sorry , at first i plan to attach my code , but it keep coming out with error . Thank for informing me the contradict message . I really wish to solve this – Daren li Apr 02 '16 at 15:07
  • If you have problem attaching it here directly, put it on [pastebin](http://pastebin.com/) or some similar site and add a link. – Dan Mašek Apr 02 '16 at 15:10

1 Answers1

0

If you wish to perform face detection using HaarCascades, you can use this code:

  #include <opencv2/objdetect/objdetect.hpp>
     #include <opencv2/highgui/highgui.hpp>
     #include <opencv2/imgproc/imgproc.hpp>
     #include <iostream>
     #include <stdio.h>
     using namespace std;
     using namespace cv;
     CascadeClassifier facecascade;

     int main()
     {
       Mat frame;
      facecascade.load("haarcascade_frontalface_alt.xml");
      if(facecascade.empty())
      {
        cout<<"Error";

      }

       VideoCapture cap(0);
       int i=0,j=0,k=0;
         while(1)
         {
          cap>>frame;  
          Mat frame_gray;
         cvtColor(frame,frame_gray,CV_BGR2GRAY);
         vector<Rect>faces;

         facecascade.detectMultiScale(frame_gray,faces,1.1,2,0|CV_HAAR_SCALE_IMAGE,Size(70,70));
         if(faces.size()>0)
         {

         for(i=0;i<faces.size();i++)
            {
            rectangle(frame_gray,faces[i],Scalar(200,200,250),2,8,0);

            }
         char no[5];
         sprintf(no,"No. of faces detected = %d",int(faces.size()));
         putText(frame_gray,no,Point(10,30),FONT_HERSHEY_TRIPLEX,1,Scalar(255,255,255),1);
            imshow("out",frame_gray);
          char c= waitKey(5);
           if(c=='b')
           break;
         }
            return 0;
       }
Saransh Kejriwal
  • 2,467
  • 5
  • 15
  • 39
  • Since I don't know what changes you've made to the OpenCV sample code, I cannot point out what you might be doing incorrectly. Try working my code, and see if you get a result – Saransh Kejriwal Apr 05 '16 at 04:01