has a strange side effect. My camera won't work without it.
For C++ version, just call namedWindow("test",1) outside the main loop makes it work.
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main(int, char**) {
VideoCapture cap(0); // open the default camera
// check if we succeeded
if (!cap.isOpened()) {
cout << "Error: Camera is not opened!" << endl;
return -1;
}
Mat frame;
// Strange bug in OpenCV 2.4.6.1: the camera won't work without doing this ???
namedWindow("test", 1);
// Main loop
for (;;) {
cap >> frame; // get a new frame from camera
cout << "frame size: " << frame.rows << "," << frame.cols << endl;
if (frame.rows > 0 && frame.cols > 0) {
imshow("test", frame);
}
if (waitKey(30) >= 0) break;
}
return 0;
}