Basic Face Detection, Opencv 3 Visual Studio 2015

Follow

My favourite

  • Opencv tutorial people detection
  • Head people cascade download
  • Opencv tutorial optical flow
  • Opencv Video stabilization
  • Opencv car dataset download
  • Opencv tutorial Transparent mask
  • Opencv videowriter
  • Opencv FFMPEG
  • Opencv Canny edge and hough lines
  • Basic Opencv Face Detection Tutorial

    Basic Opencv C++ tutorial how to detect the face from video image and any source you can achieve.
    If you have little bit skills with programing you can just achieve the result under 10 minutes. I would like to reccomend also the installation by NUGET package. It is the fastest approach in Visual Studio how to start coding with opencv.. 

    Problem with CascadeClassifier detectMultiScale Opencv 3.0.0. Windows prebuild libs

    Problem is that in many cases with 32 bit Opencv 3.0.0 Windows version in debug and in release mode. I thing any of haarcascade_xxx return vector<Rect> Faces (testing number of cascades is 7). The length of the vector is incomprehensibly bigger than I can expect with my parameters and experiences with previous Opencv version..

    vector<Rect> of detection is to big 

    This is some kind of bug that I try to find in opencv source. What is surprising is fact that 64 bit version of Opencv works fine in my case. 

     I am using Visual Studio 2015 with 64 bit Opencv 3.0.0

     Here is my tutorial how to install Opencv 3.0.0 libs for Visual Studio 2015. 
    Install Opencv for Visual Studio 2015
    You can simple prepare the project inside the Visual Studio 2015 by Nuget Packages. This approach is easy for beginers and better than standard installation with all the environmental variables problems. Just follow the installation steps inside here 

    Face detection basic Opencv C++ code example

    There is nothing special, but you can also find the example how to replace the face with transparent mask or any pictures. This is at least fun. 
    
    
    
    #include <opencv2/core.hpp>
    #include <opencv2/highgui.hpp>
    #include <opencv2/videoio.hpp>
    #include <opencv2/objdetect.hpp>
    #include <opencv2/imgproc.hpp>
    #include <iostream>
    
    using namespace cv;
    using namespace std;
    
    
    int main(int argc, char** argv)
    {
     // capture from web camera init
    
     VideoCapture cap(0);
     cap.open(0);
    
     Mat img;
    
    // Load cascate classifier placed in sulution folder
     CascadeClassifier detector;
     string cascadeName = "haarcascade_frontalface_alt.xml";
     bool loaded = detector.load(cascadeName);
    // Parameters of detectMultiscale Cascade Classifier
     int groundThreshold = 2;
     double scaleStep = 1.1;
     Size minimalObjectSize(80, 80);
     Size maximalObjectSize(200, 200);
    
    // Vector of returned faces
     vector found;
    
     for (;;)
     {
     
          // Image from camera to Mat
    
          cap >> img;
         // Convert input to greyscale 
          Mat image_grey;
          cvtColor(img, image_grey, CV_BGR2GRAY);
    
          // why not
          found.clear();
      
          // Detect faces
          detector.detectMultiScale(image_greyHead, found, scaleStep, groundThreshold, 0         | 2, minimalObjectSize,maximalObjectSize);
          // Draw the results into mat retrieved from webcam
          if (found.size() > 0) {
                for (int i = 0; i <= found.size() - 1; i++) {
                 rectangle(img, found[i].br(), found[i].tl(), Scalar(0, 0, 0), 1, 8, 0);
                 }
          }
    
        //Show the results
    
         imshow("wooohooo", img);
         int key2 = waitKey(20);
    
     }
     return 0;
    }
    
    

    12 comments:

    1. I have got this error:xxx.cpp(56): error C2065: 'image_greyHead': undeclared identifier

      Can you share the value of this identifier?

      ReplyDelete
    2. 'image_greyHead': undeclared identifier what should i do?

      ReplyDelete
      Replies
      1. Replace image_greyHead to image_grey lol

        Delete
    3. also point to the correct folder for the haar classifer

      ReplyDelete
    4. The throw : Read access to offense.

      this이(가) 0x445FF8였습니다.

      If you have a program for this exception handler can continue safely.


      template inline
      Point_<_Tp> Rect_<_Tp>::br() const
      {
      return Point_<_Tp>(x + width, y + height); <<error part
      }

      ReplyDelete
    5. I got exception like "Unhandled exception at 0x000007FEFD619E5D in OpenCVTest.exe: Microsoft C++ exception: cv::Exception at memory location 0x00000000001BF1F0."
      what should I do

      ReplyDelete
    6. mine gives error on vector. I fixed it vector found. but why it cant detect my face?

      ReplyDelete
    7. This comment has been removed by the author.

      ReplyDelete
      Replies
      1. This comment has been removed by the author.

        Delete

    ad

    Follow by Email

    Powered by Blogger.