开发者

Are 2 simultaneous webcam windows possible with openCV?

I am applying common image transforms to my live webcam capture. I want to display the original webcam 开发者_运维百科in one window and the image with the transforms applied to in another window. However, I am getting same image (filtered) on both windows, I am wondering if I am limited by the OpenCV API or if I am missing something? My code snippet looks like -

/* allocate resources */
cvNamedWindow("Original", CV_WINDOW_AUTOSIZE);
cvNamedWindow("Filtered", CV_WINDOW_AUTOSIZE);
CvCapture* capture = cvCaptureFromCAM(0);

do {    
    IplImage* img = cvQueryFrame(capture);
    cvShowImage("Original", img);           

    Filters* filters = new Filters(img);
    IplImage* dst = filters->doSobel();
    cvShowImage("Filtered", dst);

    cvWaitKey(10);      
} while (1);

/* deallocate resources */
cvDestroyWindow("Original");
cvDestroyWindow("Filtered");
cvReleaseCapture(&capture);


Its possible! Try copying img to another IplImage before sending it to processing and see if that works first.

Yes, I know what you're going to say. But just try that first and see if it does what you want. The code below is just to illustrate what you should do, I don't know if it will work:

/* allocate resources */
cvNamedWindow("Original", CV_WINDOW_AUTOSIZE);
cvNamedWindow("Filtered", CV_WINDOW_AUTOSIZE);
CvCapture* capture = cvCaptureFromCAM(0);    

do {    
    IplImage* img = cvQueryFrame(capture);
    cvShowImage("Original", img);           

    IplImage* img_cpy = cvCreateImage(cvGetSize(img), 8, 3);
    img_cpy = cvCloneImage(img);

    Filters* filters = new Filters(img_cpy);
    IplImage* dst = filters->doSobel();
    cvShowImage("Filtered", dst);

    /* Be aware that if you release img_cpy here it might not display 
     * the data on the window. On the other hand, not doing it now will
     * cause a memory leak.
     */
    //cvReleaseImage( &img_cpy );  

    cvWaitKey(10);      
} while (1);

/* deallocate resources */
cvDestroyWindow("Original");
cvDestroyWindow("Filtered");
cvReleaseCapture(&capture);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜