OpenCV shows both incoming video and modified video in separate windows

It should be easy. I have a video stream coming from my webcam. I just play with image conversion, etc. I would like to be able to view the source images (video input) in one window and the converted video in another. The problem is that as soon as I start to capture video, and not just individual images, the converted video is displayed in the original video window. I do not understand why.

cvNamedWindow("in", CV_WINDOW_AUTOSIZE);
cvNamedWindow("out", CV_WINDOW_AUTOSIZE);

CvCapture *fc = cvCaptureFromCAM(0);

IplImage* frame = cvQueryFrame(fc);

if (!frame) {
    return 0;
}

IplImage* greyscale = cvCreateImage(cvGetSize(frame), IPL_DEPTH_8U, 1);
IplImage* output = cvCreateImage(cvGetSize(frame),IPL_DEPTH_32F , 1);

while(1){

    frame= cvQueryFrame(fc);
    cvShowImage("in", frame);

    // manually convert to greyscale
    for (int y = 0; y < frame->height; y++) {
        uchar* p = (uchar*) frame->imageData + y* frame->widthStep; // pointer to row
        uchar* gp = (uchar*) greyscale->imageData + y*greyscale->widthStep;  
        for(int x = 0; x < frame->width; x++){
            gp[x] = (p[3*x] + p[3*x+1] + p[3*x+2])/3;   // average RGB values 
        }
    }

    cvShowImage("out", greyscale);

    char c = cvWaitKey(33);
    if (c == 27) {
        return 0;
    }
}

In this simple example, both video streams eventually appear in shades of gray ... The pointer and image values ​​for the frame and gray scale are completely different. If I stop showing grayscale in the "out" window, then the frame will appear in color.

, Sobel "out" , "in" "out" Sobel!

?

+3
2

. , , CV_WINDOW_AUTOSIZE ? , OpenCV 2.1 ( , ). , 0 CV_WINDOW_AUTOSIZE , .

+1

openCV 2.0 mandriva 2010 CV_WINDOW_AUTOSIZE, 0.

cvCvtColor(frame,grayscale,CV_RGB2GRAY) , .

0

Source: https://habr.com/ru/post/1770628/


All Articles