I'm on OSX Mavericks with a Macbook Air 2013.
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/video/tracking.hpp>
int main()
{
cv::VideoCapture cap;
cap.open(0);
if( !cap.isOpened() )
{
std::cerr << "***Could not initialize capturing...***\n";
return -1;
}
cv::Mat frame;
while(1){
cap >> frame;
if(frame.empty()){
std::cerr<<"frame is empty"<<std::endl;
break;
}
cv::imshow("", frame);
cv::waitKey(10);
}
return 1;
}
The camera initializes properly (isOpened returns true), however it keeps returning empty frames. However, retrieving frames from a file instead of a camera works fine.
Also, using the C API's cvQueryFrame seems to work fine!
Any ideas on how I can debug my problem?
Edit: The code below seems to get the camera working fine. Anyone know why?
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/video/tracking.hpp>
using namespace cv;
using namespace std;
int main()
{
VideoCapture cap;
cap.open(0);
namedWindow("Window");
if( !cap.isOpened() )
{
std::cerr << "***Could not initialize capturing...***\n";
return -1;
}
cv::Mat frame;
while(1){
cap >> frame;
if(!(frame.empty())){
imshow("Window", frame);
}
waitKey(10);
}
return 1;
}