Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to take "cv::Mat frame" inside contours?

Hi I want to tracking human using detectMultiScale inside contours, how to do that?

This is my code, loot at the last line:

    cv::Mat frame;
    cv::Mat blurred;
    cv::Mat fg;     
    cv::Mat bgmodel;
    cv::Mat threshfg;
    cv::Mat blob;
    cv::Mat blobarray[10000];
    int pixblob = 0;
    int tot_bgr = 0;
    int tot_ex_bgr = 0;
    int green0 = 0;
    int green1 = 0;
    int green2 = 0;
    int green3 = 0;

    cv::namedWindow("Frame");   
    cv::namedWindow("Background Model");
    cv::namedWindow("Blob");

    cv::VideoCapture cap("campus.avi"); 

    cv::BackgroundSubtractorMOG2 bgs;                       
        bgs.nmixtures = 3;
        bgs.history = 500;
        bgs.bShadowDetection = true;                            
        bgs.nShadowDetection = 0;                               
        bgs.fTau = 0.25;                                        

    std::vector<std::vector<cv::Point>> contours;               

    cv::CascadeClassifier human;
    assert(human.load("hogcascade_pedestrians.xml"));
    for(;;){
        cap >> frame;   

        cv::GaussianBlur(frame,blurred,cv::Size(3,3),0,0,cv::BORDER_DEFAULT);

        bgs.operator()(blurred,fg);                         
        bgs.getBackgroundImage(bgmodel);                                

        cv::erode(fg,fg,cv::Mat(),cv::Point(-1,-1),1);                         
        cv::dilate(fg,fg,cv::Mat(),cv::Point(-1,-1),3); 

        cv::threshold(fg,threshfg,70.0f,255,CV_THRESH_BINARY);

        cv::findContours(threshfg,contours,CV_RETR_EXTERNAL,CV_CHAIN_APPROX_SIMPLE);
        cv::cvtColor(threshfg,blob,CV_GRAY2RGB);
        cv::drawContours(blob,contours,-1,cv::Scalar(255,255,255),CV_FILLED,8);
        blob.copyTo(blobarray[(int)cap.get(CV_CAP_PROP_POS_FRAMES)]);

        int cmin = 20; 
        int cmax = 1000;
        bool FOD1 = true;
        bool FOD2 = true;
        std::vector<cv::Rect> rects;

        for(int cnum = 0; cnum < contours.size(); cnum++){

            if(contours[cnum].size() > cmin && contours[cnum].size() < cmax){       

                human.detectMultiScale(???, rects);

What should I replace ??? with? I wanna take Mat from frame inside contours. I'll appreciate any help here, thanks. :)

NB: sorry for my english. LOL