How to set 'nmixures' and 'bShadowDetection' values in 'BackgroundSubtractorMOG2'?

asked 2017-04-01 13:17:51 -0600

meg gravatar image

I am using OpenCV 3.1 but the problem is that i am unable to make object of BackgroundSubtractorMOG2 class. I have written a function to detect face, eyes, nose and hand(with fingers and count the fingers). The problem is that visual studio gives an error saying that BackgroundSubtractorMOG2 is abstract class. Can someone please help me with that, I am also getting an error int the following lines:

 bg.operator ()(frame, fore); 
 bg.operator()(frame, fore, 0);

Following is my code. How can i resolve this issue. Thank in advance.

#include <opencv/cv.h>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/objdetect.hpp>
#include <opencv2/video/background_segm.hpp>

#include <iostream>
#include<algorithm>
#include <vector>

using namespace std;
using namespace cv;

String face_cascade_name = "haarcascade_frontalface_alt.xml";
String eyes_cascade_name = "haarcascade_eye_tree_eyeglasses.xml";
String nose_cascade_name = "haarcascade_mcs_nose.xml";
CascadeClassifier face_cascade;
CascadeClassifier eyes_cascade;
CascadeClassifier nose_cascade;
double dist(Point x, Point y)
{
    return (x.x - y.x)*(x.x - y.x) + (x.y - y.y)*(x.y - y.y);
}
pair<Point, double> circleFromPoints(Point p1, Point p2, Point p3)
{
    double offset = pow(p2.x, 2) + pow(p2.y, 2);
    double bc = (pow(p1.x, 2) + pow(p1.y, 2) - offset) / 2.0;
    double cd = (offset - pow(p3.x, 2) - pow(p3.y, 2)) / 2.0;
    double det = (p1.x - p2.x) * (p2.y - p3.y) - (p2.x - p3.x)* (p1.y - p2.y);
    double TOL = 0.0000001;
    if (abs(det) < TOL) { cout << "POINTS TOO CLOSE" << endl; return make_pair(Point(0, 0), 0); }

    double idet = 1 / det;
    double centerx = (bc * (p2.y - p3.y) - cd * (p1.y - p2.y)) * idet;
    double centery = (cd * (p1.x - p2.x) - bc * (p2.x - p3.x)) * idet;
    double radius = sqrt(pow(p2.x - centerx, 2) + pow(p2.y - centery, 2));

    return make_pair(Point(centerx, centery), radius);
}
void detectAndDisplay(Mat image)
{
    std::vector<Rect> faces;
    Mat image_gray;

    cvtColor(image, image_gray, CV_BGR2GRAY);
    equalizeHist(image_gray, image_gray);

    face_cascade.detectMultiScale(image_gray, faces, 1.1, 2, 0 | CV_HAAR_SCALE_IMAGE, Size(30, 30));

    cout << faces.size() << std::endl;

    for (size_t i = 0; i < faces.size(); i++) {
        rectangle(image, Point(faces[i].x, faces[i].y), Point(faces[i].x + faces[i].width, faces[i].y + faces[i].height), Scalar(255, 0, 0), 3, 8);

        Mat faceROI = image_gray(faces[i]);
        vector<Rect> eyes;
        vector<Rect> noses;
        eyes_cascade.detectMultiScale(faceROI, eyes, 1.1, 2, 0 | CV_HAAR_SCALE_IMAGE, Size(30, 30));
        nose_cascade.detectMultiScale(faceROI, noses, 1.1, 2, 0 | CV_HAAR_SCALE_IMAGE, Size(30, 30));
        cout << noses.size() << std::endl;
        for (size_t j = 0; j < eyes.size(); j++) {
            Point center(faces[i].x + eyes[j].x + eyes[j].width*0.5, faces[i].y + eyes[j].y + eyes[j].height*0.5);
            int radius = cvRound((eyes[j].width + eyes[j].height)*0.25);
            circle(image, center, radius, Scalar(0, 255, 0), 4, 8, 0);
        }
        for (size_t j = 0; j < noses.size(); j++) {
            Point center(faces[i].x + noses[j].x + noses[j].width*0.5, faces[i].y + noses[j].y + noses[j].height*0.5);
            int radius = cvRound((noses ...
(more)
edit retag flag offensive close merge delete

Comments

read this post

LBerger gravatar imageLBerger ( 2017-04-01 13:22:46 -0600 )edit