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;
Try to display the
frame
image instead ofedges
. You blur the original image, which erases the edges, so the Canny filter might return nothing.where is that "sample" code from ? (we might have to correct that !)
the prebuild libs are for VS2015 only. if you want to use VS2017, you will have to build the opencv libs from src
@berak thanks will build them.
... and please report back !
@berak generated the librairies, removed the prebuilt, and to be sure not using the aggregated worldopencv dlls but the separated ones. Still the same problem. One difference I noted between python and C++ is that under Python CAP_PROP_BRIGHTNESS returns 128.0 while under C++ I get 0 for CV_CAP_PROP_BRIGHTNESS. I tried to set CV_CAP_PROP_BRIGHTNESS to 128 in C++ but reading it immediately after still gives 0. Similarly CAP_PROP_MODE give -1 in Python and CV_CAP_PROP_MODE gives 0. The four CC is different too -466162819.0 in Python, 8.44715e+08 in C++. Any clue?
C++ MODE 0 FOURCC 8.44715e+08 BRIGHTNESS 0 BRIGHTNESS AFTER SET 0
@berak I stopped Python Idle and tried and it worked. Not sure why it started working, because I restarted Python and both worked. Could it be conflict of webcam access even though the python webcam code was not running?