Ask Your Question

ManuVISION's profile - activity

2019-03-25 08:22:47 -0600 received badge  Popular Question (source)
2018-02-21 12:04:03 -0600 answered a question How can i fill the gaps in the foreground and improve foreground extraction?

A morphological open with a small kernel to remove all small speckles Find the largest closed contour and fit a convex

2018-02-21 11:54:35 -0600 commented question Obtain continuous closed contour

Apply edge sharpening as pre processing using Filter2D. Then many edges become visible. Then find the contours and fit

2018-02-21 11:45:14 -0600 commented question Extracting Contours from Image - Python

Since it is a closed one, finding the largest contour will get you the box

2018-02-21 11:35:55 -0600 answered a question how can I align Face Images

I have implemented it using DLib and OpenCV https://github.com/ManuBN786/Face-Alignment-using-Dlib-OpenCV It corrects a

2017-06-24 02:03:12 -0600 commented question MSER Non Maxima Suppression is not supressing all the regions

I tried various ways and put a break statement also. But its not working. What is the correct way of doing it ??

2017-06-15 01:50:09 -0600 asked a question MSER Non Maxima Suppression is not supressing all the regions

I have removed non maxima regions from the vector "bbox" . But when I plot it shows the regions which still contain non maxima regions. If I measure the bbox.size() before & after non max suppression it says 4677 & 3582 respectively.Why its not able to remove all the non maximas ?? I have taken area and the start and end x & y co ordinates as the criterion.

Complete code is here: https://stackoverflow.com/questions/4...

Note: The same method in python yields much lesser regions and suppresses it all. Is there a difference between detectRegions in python & c++ ??

C++ :

Mat src = imread("/home/clabs/MANU/right_side/53.jpg",CV_LOAD_IMAGE_UNCHANGED);

Mat gray;

Mat src1 = src.clone();

cvtColor(src, gray, CV_RGB2GRAY);

Ptr<MSER> ms = MSER::create();

vector<Rect> bbox,filtered;
vector<vector<Point> > regions;
vector <int> vec;

ms->detectRegions(gray,regions,bbox);


for (int k = 0; k < bbox.size(); k++)
{
   rectangle(src,bbox[k], CV_RGB(0, 255, 0));
}

imwrite("Unsupressed.jpg",src);

cout<<bbox.size()<<"Befor Delete"<<endl;
for (int i = 0; i<bbox.size(); i++){
    for(int j = 0; j<bbox.size(); j++){

        if( (bbox[i].x > bbox[j].x) && (bbox[i].y > bbox[j].y) && ((bbox[i].x+bbox[i].width) < (bbox[j].x+bbox[j].width)) && ((bbox[i].y+bbox[i].height) < (bbox[j].y+bbox[j].height)) && (bbox[i].area() < bbox[j].area())){



            bbox.erase(bbox.begin() + i );

        }


    }
}

cout<<bbox.size()<<" After"<<endl;
cout<<vec.size()<<endl;

for (int k = 0; k < bbox.size(); k++)
{
    rectangle(src1,bbox[k], CV_RGB(255,0,0));
   //cout<<k<<endl;
}


imshow("mser", src1);
imwrite("NoN.jpg",src1);



waitKey(0);

return 0;

}

2017-04-12 15:04:16 -0600 commented question TLD tracking too slow

Thanks for the code. I used the selectROI for manual selection. After that there is no tracking. What am I missing here ?? Someone plz tell

2017-04-12 15:01:49 -0600 answered a question How to count the number of faces detected in live video by openCV using python?

For that you need to track all the detected faces in each frame and add new ones that are found. Then you need an efficient counting algorithm to count the tracked vectors. Not an easy thing which can be done if few days

2017-04-12 14:46:55 -0600 asked a question Multiple tracking of people detected is not working. How to use MultiTracker??

I dont understand how to use the MultiTracker class in Opencv. I followed the example in MultiTracker documentation of OpenCV 3.2

Its not able to track at all.

Here is the code :

vector<rect> found, found_filtered;

        hog.detectMultiScale(img, found, 0, Size(4,4), Size(8,8), 1.05, 2);

        // Avoid non maxima supression

        size_t i, j;
        for (i = 0; i < found.size(); i++)
        {
            Rect r = found[i];
            for (j = 0; j < found.size(); j++)
                if (j != i && (r & found[j]) == r)
                    break;
            if (j == found.size())
                found_filtered.push_back(r);
        }

        // Draw Rectangles around detected objects in green
        for (i = 0; i < found_filtered.size(); i++)
        {
            Rect r = found_filtered[i];
            r.x += cvRound(r.width*0.1);
            r.width = cvRound(r.width*0.8);
            r.y += cvRound(r.height*0.06);
            r.height = cvRound(r.height*0.9);
            rectangle(img, r.tl(), r.br(), cv::Scalar(0, 255, 0), 2);
        } 

        vector<Rect2d> v2, objects; // for tracking

        for (size_t i = 0; i<found_filtered.size(); i++) {
            objects.push_back(found_filtered[i]); //Rect2d has a constructor for Rect . Convert Rect to Rect 2d
        }



        cout <<  v2.size() << endl;

                     MultiTracker trackers("KCF");

                     // initialize the tracker
                      trackers.add(img,objects);


                     //update the tracking result
                      trackers.update(img);


                      // draw the tracked object
                     for(unsigned i=0;i<trackers.objects.size();i++)
                     rectangle(img, trackers.objects[i], Scalar( 255, 0, 0 ), 2, 1 );

         imshow("Plotted", img);

        int key6 = waitKey(40);
    }
2017-04-12 14:30:45 -0600 answered a question How not to detect a face from others

Set aspect ratio as the criterion. Set a range for height and width. Make sure height is say thrice more than width so that the pushing person is always upright and standing and gets bounded in a rectangle( with h = 3* width)

2017-04-12 14:24:33 -0600 answered a question How to separate objects wich have the same color

Once you have detected both, check for aspect ratio. If its more then divide the detected image into half.

2017-04-12 10:09:03 -0600 commented answer How can I crop a projected image from the camera view?

selectROI can help. Plz search in the documentation

2017-04-12 08:06:27 -0600 commented question Unable to track faces. How to update trackers ???

Thanks. I already tried MultiTracking for people tracking a while ago. No good results. Can u please help where i'm going wrong here?? The code is in the link: http://answers.opencv.org/question/124457/why-this-code-is-not-able-to-track-people/ (http://answers.opencv.org/question/12...)

2017-04-12 07:24:31 -0600 commented question Track only 1 target among multiple targets

Since u say MultiTracking is very easy. Can u please help me do it for tracking multiple faces: http://answers.opencv.org/question/139492/unable-to-track-faces-how-to-update-trackers/ (http://answers.opencv.org/question/13...) Thanks in advance

2017-04-12 07:21:56 -0600 asked a question Unable to track faces. How to update trackers ???

I am doing a multiple faces detection & tracking. But the trackers are not updating properly.

The code runs without errors when compiling. During runtime I get the below message (not error tho)

''Trackers are initialized correctly.

unable to track"

Here is the code:

    // Detect faces
    std::vector<Rect> faces;
    Rect2d face_rect2d;
    face_cascade.detectMultiScale( image, faces, 1.2, 2, 0|CV_HAAR_SCALE_IMAGE, Size(min_face_size, min_face_size),Size(max_face_size, max_face_size) );



  for(unsigned int i = 0; i < faces.size(); ++i)
  {        


    face_rect2d = faces[i];

    rectangle(image,face_rect2d, Scalar( 255, 255, 0 ), 1, 4 ); // Draw the detections


    Ptr<Tracker> tracker = Tracker::create( "MEDIANFLOW" ); // Create tracker

    if (tracker.empty())
{
    std::cerr << "***Error in the instantiation of the tracker...***\n";
    return -1;
    }



      // Check if they are initialized
     if (!tracker->init(image, face_rect2d))
     {
    std::cerr << "***Could not initialize tracker...***\n";
    return -1;
 }
 else
 {

        std::cout << "Trackers are initialized correctly." << std::endl;
     }



     // Check if they are updated

     if (!(tracker->update(image, face_rect2d))) {
                printf("unable to track\n"); 
              }



     cv::rectangle(image,face_rect2d, cv::Scalar(255, 0, 255), 2, 1);

  }
2017-04-09 12:23:52 -0600 answered a question How to install Opencv_contrib for opencv 3.1?
2017-04-09 12:21:12 -0600 answered a question Building OpenCV 3.2 with opencv_contrib for Python 3.6 on Window
2017-04-09 12:15:29 -0600 answered a question Face Tracking, pupils detection, Face rotation
2017-04-09 12:13:45 -0600 answered a question how do we know whether opencv_contrib is successfully installed or not?

#include <opencv2 tracking.hpp="">

try initializing the tracker with

Ptr<tracker> tracker = Tracker::create( "MEDIANFLOW" );

if the error is : tracker was not defined in this scope. Then your contrib files are not installed

2017-04-09 12:11:28 -0600 answered a question Object tracking while moving

https://www.youtube.com/watch?v=pj-Qu... The code is in the description of the video

2017-04-09 12:09:53 -0600 answered a question How can I crop a projected image from the camera view?

Create an ROI around the object and crop the ROI out of it

2017-04-01 15:35:35 -0600 marked best answer How to do multi object tracking with Kalman ??

I have used kalman.cpp in the openCV 3.1 inbuilt to successfully track a single object. But how to do the same for multiple objects any idea ??

If necessary I will post the code here. Thanks in advance.

2017-04-01 15:34:16 -0600 commented question OpenCV Error: Assertion failed in matrix.cpp line 522, /matrix.cpp:522: error: (-215)

I figured out the solution by plotting each of the corner points in rectangular ROI, one such point was outside the dimensions of the image. So it crashed

2017-04-01 15:32:26 -0600 received badge  Supporter (source)
2017-04-01 15:32:03 -0600 received badge  Scholar (source)
2017-04-01 15:25:07 -0600 asked a question OpenCV Error: Sizes of input arguments do not match (The operation is neither 'array op array'

I have tried to create an ROI above the detected face to place a hat over there.

Where face is the detected face from webcam feed

Part of the code looks like this:

Mat mask;

mask = imread("Hat.jpeg");

// Create an ROI above the head. Rec is the co ordinates of the rectangle created above the head

Rect Rec(abs(face.x-face.width0.08),abs(face.y face.height0.29),abs(face.width0.08+face.width+face.width0.08),abs(face.height*0.29));

rectangle(image,Rec,Scalar(255,255,0),1,8);

// To Place the hat first find the center

Point center(Rec.x +Rec.width0.5,Rec.y +Rec.height0.5 );

circle(image,center, 3, Scalar(255, 255,0), -1, 8);

// Now replace the ROI with the hat image i.e mask

image = putMask(image,center,Size(Rec.width,Rec.height));

imshow( "window1",image );

// The putMask function is like this:

Mat putMask(Mat src,Point center,Size face_size)

{

Mat mask1,src1;

resize(mask,mask1,face_size);    

// ROI selection

 Rect roi(center.x - face_size.width/2, center.y - face_size.width/2, face_size.width, face_size.width);

src(roi).copyTo(src1);

// to make the white region transparent

Mat mask2,m,m1;

cvtColor(mask1,mask2,CV_BGR2GRAY);

threshold(mask2,mask2,230,255,CV_THRESH_BINARY_INV); 

vector<Mat> maskChannels(3),result_mask(3);

split(mask1, maskChannels);

bitwise_and(maskChannels[0],mask2,result_mask[0]);

bitwise_and(maskChannels[1],mask2,result_mask[1]);

bitwise_and(maskChannels[2],mask2,result_mask[2]);

merge(result_mask,m );         //    imshow("m",m);

mask2 = 255 - mask2;

vector<Mat> srcChannels(3);

split(src1, srcChannels);

bitwise_and(srcChannels[0],mask2,result_mask[0]);

bitwise_and(srcChannels[1],mask2,result_mask[1]);

bitwise_and(srcChannels[2],mask2,result_mask[2]);

merge(result_mask,m1 );        //    imshow("m1",m1);

addWeighted(m,1,m1,1,0,m1);    //    imshow("m2",m1);

m1.copyTo(src(roi));

return src;

}

It compiles without errors. But when i execute it crashes with error:

OpenCV Error: Sizes of input arguments do not match (The operation is neither 'array op array' (where arrays have the same size and type), nor 'array op scalar', nor 'scalar op array') in binary_op, file /home/user/OpenCV_Installed/opencv-3.2.0/modules/core/src/arithm.cpp, line 225 terminate called after throwing an instance of 'cv::Exception' what(): /home/user/OpenCV_Installed/opencv-3.2.0/modules/core/src/arithm.cpp:225: error: (-209) The operation is neither 'array op array' (where arrays have the same size and type), nor 'array op scalar', nor 'scalar op array' in function binary_op

until I call putMask functions, the code has no errors. After putMask, the error shows up

Someone plz help, I have been stuck here for days !! plz

2017-03-31 08:39:10 -0600 received badge  Editor (source)
2017-03-31 08:37:30 -0600 asked a question OpenCV Error: Assertion failed in matrix.cpp line 522, /matrix.cpp:522: error: (-215)

I am trying to create an ROI above the face detected to place a hat like shown in the image, click here to see the image: The ROI is created above the detected face

I have made sure that the ROI created is withing the bounds of the image. It looks like this:

if (0<=face.x && 0<=face.x-face.width*0.08<=image.cols && 0<=face.x+face.width+face.width*0.08<=image.cols 
         && 0<=face.y && 0<=face.y-face.height*0.28<=image.rows)
    {
      Mat ROI_hat = image(Rect(abs(face.x-face.width*0.08),abs(face.y-face.height*0.28),abs(face.x+face.width+face.width*0.08),abs(face.y)));
      rectangle(image,Point(abs(face.x-face.width*0.08),abs(face.y-face.height*0.28)),Point(abs(face.x+face.width+face.width*0.08),abs(face.y)),Scalar(255, 0, 0), 1, 4);
      cout<<"Within the bounds of Image"<<endl;
    }
    else{
     cout<<" Out of bounds of Image "<<endl;
        }

There are no negative values and for every frame it says ROI is withing the bounds. But I still get assertion error:

OpenCV Error: Assertion failed (0 <= roi.x && 0 <= roi.width && roi.x + roi.width <= m.cols && 0 <= roi.y && 0 <= roi.height && roi.y + roi.height <= m.rows) in Mat, file /home/user/OpenCV_Installed/opencv-3.2.0/modules/core/src/ma‌​trix.cpp, line 522 terminate called after throwing an instance of 'cv::Exception' what(): /home/user/OpenCV_Installed/opencv-3.2.0/modules/core/src/ma‌​trix.cpp:522: error: (-215) 0 <= roi.x && 0 <= roi.width && roi.x + roi.width <= m.cols && 0 <= roi.y && 0 <= roi.height && roi.y + roi.height <= m.rows in function Mat Aborted (core dumped)

Can someone please help me ??the roi is created above face detected

2017-03-09 04:40:14 -0600 commented question Why this code is not able to track people ??

it would be very nice if you give me an idea of how to display the tracked onjects

2017-01-31 00:39:18 -0600 asked a question Why this code is not able to track people ??

Dear All,

I have used HOG SVM for people detection and and KCF filter for multitracking (inbuilt OpenCV 3.1 MultiTracker API). The code runs without any errors but is unable to track.

If I check the output to see if the trackers are initialized i.e " ok = 1 " . It shows 1 all the time, meaning the trackers are initialized for the detected objects Any help in this will be greatly useful.

the code is posted below :

using namespace cv; using namespace std;

int main(int argc, const char** argv) { // Create empty input img, foreground and background image and foreground mask. Mat img, foregroundMask, backgroundImage, foregroundImg, original;

cv::HOGDescriptor hog;
hog.setSVMDetector(cv::HOGDescriptor::getDefaultPeopleDetector());
// capture video from source 0, which is web camera, If you want capture video from file just replace //by
VideoCapture cap("20160624_130000_CH1_0.avi");
// VideoCapture cap("768x576.avi");

for (;;) {  // Instead of an infinite for loop use total no of frames
    bool ok = cap.grab();

    if (ok == false) {

        //std::cout << "Video Capture Fail" << std::endl;


    }
    else {

        // obtain input image from source
        cap.retrieve(img, CV_CAP_OPENNI_BGR_IMAGE);
        // Just resize input image if you want
        resize(img, img, Size(640, 480));
        //resize(img, img, Size(320, 240));
        // imshow( "Video Captured", img );
        vector<Rect> found, found_filtered;

        hog.detectMultiScale(img, found, 0, Size(8, 8), Size(32, 32), 1.05, 2);

        // Avoid non maxima supression

        size_t i, j;
        for (i = 0; i < found.size(); i++)
        {
            Rect r = found[i];
            for (j = 0; j < found.size(); j++)
                if (j != i && (r & found[j]) == r)
                    break;
            if (j == found.size())
                found_filtered.push_back(r);
        }

        /*for (i = 0; i < found_filtered.size(); i++)
        {
            Rect r = found_filtered[i];
            r.x += cvRound(r.width*0.1);
            r.width = cvRound(r.width*0.8);
            r.y += cvRound(r.height*0.06);
            r.height = cvRound(r.height*0.9);
            rectangle(img, r.tl(), r.br(), cv::Scalar(0, 255, 0), 2);
        } */

        vector<Rect2d> v2, objects; // for tracking

        for (size_t i = 0; i<found_filtered.size(); i++) {
            v2.push_back(found_filtered[i]); //Rect2d has a constructor for Rect
        }



    //  cout <<  v2.size() << endl;
        Ptr<MultiTracker> trackers = makePtr<MultiTracker>("KCF");
        trackers->add(img, v2);

        bool ok = trackers->update(img);


        //cout << objects.size() << endl;
        if (!ok) {
            // one of the trackers failed, now unfortunately, you will have to:
            // * create a new Multitracker instance with current image and current detections
            trackers = makePtr<MultiTracker>("KCF");
            // * make a new peopledetection
            // * copy detections to tracking Rect2ds again, and 
            trackers->add(img,objects);
        } 

        cout << ok << endl;

        for (unsigned i = 0; i<trackers->objects.size(); i++)
            rectangle(img, trackers->objects[i], Scalar(255, 0, 0), 2, 1);



        imshow("Plotted", img);

        int key6 = waitKey(40);
    }

}

}

2017-01-10 08:39:55 -0600 commented answer Why does the foreground image from background subtraction look transparent?

I faced a similar situation i.e multiple blobs for same person, one above waist and another below. Use of morphological operations and filling with holes solved the problem.

2017-01-10 08:29:26 -0600 commented answer MultiTracker's trackers initialization for first frame

Thanks for the reply. I did the same and every time it shows same error as Multitracker has no member objects.

If I check the cout<<ok <="" p="">

The output is always 1 means trackers are initialized.

Plz tell me where I am going wrong

2017-01-06 03:38:51 -0600 commented answer MultiTracker's trackers initialization for first frame

thanks berak. Now how to draw rectangles around tracked objects ?? if I use the below for (unsigned i = 0; i < trackers.v2.size(); i++) { rectangle(img,trackers.v2[i], Scalar(255, 0, 0), 2, 1);}

the error show is MultiTracker has no member named v2. How to resolve this and draw rectangles around tracked objects ?? }

2016-11-24 05:20:13 -0600 asked a question MultiTracker's trackers initialization for first frame

I followed the example mentioned in link of Opencv 3.1 How to initialize the trackers for the first frame ??? i mean in the example in the link they have used selectRoi for selection of objects befor the for loop. How to do the same with HOG SVM ??? someone plz help