简体   繁体   中英

Reducing lag during blob detection of real-time, binary b/w webcam feed using cvblobslib and opencv(c++)

I'm building a skin-detection algorithm that takes constant, real-time feed with a webcam, converts it to a binary image (based on the skin color of the person's face), and filters out the noise by only showing focusing on the largest blobs (using CvBlobsLib). The output of my code, however, shows a lot of lag, and I'm not sure what to change to make it faster.

Here's (the important part of) my code:

Mat frame;
IplImage ipl, *res = new IplImage;
CBlobResult blobs;
CBlob *currentBlob;
cvNamedWindow("output");

for(;;){

    cap >> frame; //get a new frame from camera
    cvtColor(frame, lab, CV_BGR2Lab);//frame now in L*a*b*
    inRange(lab, BW_MIN, BW_MAX, bw);//frame now only shows "skin values"...BW_MIN/BW_MAX determined earlier
    ipl = bw; //IplImage header

    blobs = CBlobResult(&ipl, NULL, 0);
    blobs.Filter(blobs, B_EXCLUDE, CBlobGetArea(), B_LESS, 10000);
    res = cvCreateImage(cvGetSize(&ipl), IPL_DEPTH_8U, 3);
    cvMerge(&ipl, &ipl, &ipl, NULL, res);
    cvShowImage("output", res);
    if(waitKey(5) >= 0) break;

    }

cvDestroyWindow("output");

I convert Mat to IplImage because CvBlobsLib only works with the IplImage type.

Does anyone see a way that I could make this faster? I've just recently heard other blob detection libraries do a better job with real-time video, but I'd be interested to see if there's something I'm simply overlooking in my code.

You can decrease the resolution of the camera capture using set method

set(CV_CAP_PROP_FRAME_WIDTH , double width)

and

set(CV_CAP_PROP_FRAME_HEIGHT , double height)

If your default capture resolution is too high, this can increase the detection speed considerably.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM