简体   繁体   English

使用cvblobslib和opencv(c ++)减少实时二进制黑白网络摄像头订阅源的斑点检测期间的延迟

[英]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). 我建立一个皮肤检测算法,需要恒定的,实时的饲料有一个摄像头,将其转换为二进制图像(基于人的脸部的肤色),并只 显示 集中在过滤掉噪音最大Blob(使用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. 我将Mat转换为IplImage,因为CvBlobsLib仅适用于IplImage类型。

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. 如果您的默认捕获分辨率太高,则可以大大提高检测速度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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