1 | initial version |
Better don't use C-style API anymore, it is more verbose, error-prone, no performance benefits and will be deprecated in the future(deprecate c api).
Here is the codes of c++ api, much easier and cleaner(we don't need goto again, because of the power of RAII, c++ programmers rarely need to use goto in their codes).
#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";
std::cerr << "Current parameter's value: \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;
}
run on MacOSX 10.8.x