Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Webcam Videocapture gives black frame with C++

Hello, I use the sample code for Videocapture with OpenCV 3.1 and in C++ I only get back images (same code in Python on the same Windows 10 machine works but uses cv2.pyd). I only have the OpenCV 3.1 opencv_world331 opencv_world331d dlls in the path. What am I doing wrong?

VideoCapture cap(0); // open the default camera if (!cap.isOpened()) // check if we succeeded return -1; Mat edges; namedWindow("edges", 1); for (;;) { Mat frame; cap >> frame; // get a new frame from camera cvtColor(frame, edges, COLOR_BGR2GRAY); GaussianBlur(edges, edges, Size(7, 7), 1.5, 1.5); Canny(edges, edges, 0, 30, 3); imshow("edges", edges); if (waitKey(0) >= 0) break; } // the camera will be deinitialized automatically in VideoCapture destructor return 0;

Webcam Videocapture gives black frame with C++

Hello, I use the sample code for Videocapture with OpenCV 3.1 and in C++ I only get back images (same code in Python on the same Windows 10 machine works but uses cv2.pyd). I only have the OpenCV 3.1 opencv_world331 opencv_world331d dlls in the path. What am I doing wrong?

VideoCapture cap(0); // open the default camera camera

if (!cap.isOpened()) // check if we succeeded succeeded

        return -1;

Mat edges; edges;

namedWindow("edges", 1); 1);

for (;;) { Mat frame; cap >> frame; // get a new frame from camera camera

        cvtColor(frame, edges, COLOR_BGR2GRAY);
         GaussianBlur(edges, edges, Size(7, 7), 1.5, 1.5);
         Canny(edges, edges, 0, 30, 3);
         imshow("edges", edges);
         if (waitKey(0) >= 0) break;
     }
      // the camera will be deinitialized automatically in VideoCapture destructor

return 0;

Webcam Videocapture gives black frame with C++

Hello, I use the sample code for Videocapture with OpenCV 3.1 and in C++ I only get back images (same code in Python on the same Windows 10 machine works but uses cv2.pyd). I only have the OpenCV 3.1 opencv_world331 opencv_world331d dlls in the path. What am I doing wrong?

VideoCapture cap(0); // open the default camera

camera if (!cap.isOpened()) // check if we succeeded

succeeded

            return -1;

Mat edges;

edges; namedWindow("edges", 1);

1); for (;;) { Mat frame; cap >> frame; // get a new frame from camera

camera

            cvtColor(frame, edges, COLOR_BGR2GRAY);
         GaussianBlur(edges, edges, Size(7, 7), 1.5, 1.5);
         Canny(edges, edges, 0, 30, 3);
         imshow("edges", edges);
         if (waitKey(0) >= 0) break;
     }

     // the camera will be deinitialized automatically in VideoCapture destructor
return 0;

return 0;

Webcam Videocapture gives black frame with C++

Hello, I use the sample code for Videocapture with OpenCV 3.1 and in C++ I only get back images (same code in Python on the same Windows 10 machine works but uses cv2.pyd). I only have the OpenCV 3.1 opencv_world331 opencv_world331d dlls in the path. What am I doing wrong?

Python cv2__version 3.3.0 Microsoft Visual Studio Community 2017 Version 15.4.0 OpenCV version : 3.3.1 (from C++) cout << "OpenCV version : " << CV_VERSION << endl; Prebuilt binaries downloaded today 24/10/2017 14:41 17 816 576 opencv_ffmpeg331_64.dll 24/10/2017 14:47 65 042 944 opencv_world331.dll 24/10/2017 14:50 103 105 024 opencv_world331d.dll

VideoCapture cap(0); // open the default camera

if (!cap.isOpened())  // check if we succeeded

            return -1;
Mat edges;

namedWindow("edges", 1);

for (;;)
        {
            Mat frame;
            cap >> frame; // get a new frame from camera
                    cout << mean(frame); // displays [0.00707357, 0.00703776, 0.00779948, 0] moslty black

            cvtColor(frame, edges, COLOR_BGR2GRAY);
            GaussianBlur(edges, edges, Size(7, 7), 1.5, 1.5);
            Canny(edges, edges, 0, 30, 3);
            imshow("edges", edges);
            if (waitKey(0) >= 0) break;
        }

        // the camera will be deinitialized automatically in VideoCapture destructor
return 0;

Webcam Videocapture gives black frame with C++

Hello, I use the sample code for Videocapture with OpenCV 3.1 and in C++ I only get back images (same code in Python on the same Windows 10 machine works but uses cv2.pyd). I only have the OpenCV 3.1 opencv_world331 opencv_world331d dlls in the path. What am I doing wrong?

Python cv2__version 3.3.0
Microsoft Visual Studio Community 2017 Version 15.4.0
OpenCV version : 3.3.1 (from C++)  cout << "OpenCV version : " << CV_VERSION << endl;
Prebuilt binaries downloaded today 
24/10/2017  14:41        17 816 576 opencv_ffmpeg331_64.dll
24/10/2017  14:47        65 042 944 opencv_world331.dll
24/10/2017  14:50       103 105 024 opencv_world331d.dll

opencv_world331d.dll


VideoCapture cap(0); // open the default camera

if (!cap.isOpened())  // check if we succeeded

            return -1;
Mat edges;

namedWindow("edges", 1);

for (;;)
        {
            Mat frame;
            cap >> frame; // get a new frame from camera
                    cout << mean(frame); // displays [0.00707357, 0.00703776, 0.00779948, 0] moslty black

            cvtColor(frame, edges, COLOR_BGR2GRAY);
            GaussianBlur(edges, edges, Size(7, 7), 1.5, 1.5);
            Canny(edges, edges, 0, 30, 3);
            imshow("edges", edges);
            if (waitKey(0) >= 0) break;
        }

        // the camera will be deinitialized automatically in VideoCapture destructor
return 0;