OpenCV webcam capture problem

前端 未结 8 599
逝去的感伤
逝去的感伤 2020-12-30 10:47

I\'ve installed OpenCV 2.2 and now I can\'t get webcam capture to work. It worked ok in 2.1. OpenCV detects a webcam, doesn\'t report any errors or warnings, but each frame

相关标签:
8条回答
  • 2020-12-30 10:47

    The issue was with the camera I used, MSFT LifeCam. I tried Logitech C210 and 120 and they both work fine.

    0 讨论(0)
  • 2020-12-30 10:57

    You might try a look at this post as well.

    To put it simple, changing

    from

    import cv

    to

    import cv2.cv as cv

    worked for me. See also the post here.

    0 讨论(0)
  • 2020-12-30 11:04

    I am using cvtColor and found that

    cvtColor(image,image,CV_BGR2RGB); didn't work.

    But the good news is that this change work !!

    cvtColor(image,image,**COLOR_BGR2RGB**);
    

    Also include:

    include opencv2/imgproc/imgproc.hpp
    

    and in the .pro file the library:

    -lopencv_imgproc 
    
    0 讨论(0)
  • 2020-12-30 11:07

    I found the solution after a very long search.

    The problem is that if doesn't have a delay between showing the frames happen this problem.

    The solution is put cvWaitKey(20); in loop.

    0 讨论(0)
  • 2020-12-30 11:07

    Try this:

    VideoCapture cap(0); // open the default camera
    if(!cap.isOpened())  // check if we succeeded
    {
      cout<<"Cam not captured\n";
    }
    
    Mat frame;
    namedWindow("frame");
    for(;;)
    {
        cap >> frame; // get a new frame from camera
        imshow("frame", frame);
    
        if(waitKey(10) >= 0) break;
    }
    
    return 0;
    
    0 讨论(0)
  • 2020-12-30 11:08

    Here is the Solution.

    Every image frame captured is being converted into grayscale image in the first line below. Commenting and running the code alone will show an error since since you are not capturing any processed image into the edges frame, which is being displayed in imshow.

    Hence comment the cvtColor line and change the second parameter in imshow to frame. This will allow you to display the colour video from the webcam.

    cvtColor(frame, edges, CV_BGR2GRAY);
    
    imshow("edges", frame);
    
    0 讨论(0)
提交回复
热议问题