I am trying to capture the video from the camera onto disk. I have a script that works on a Retina MacBook Pro 18-inch, Late 2013 but does not work on MacBook Pro 13-inch, Mid 2010. Both have similar environments: running on Maverick and have OpenCV 2.4.7 installed. However, I cannot get the older Macbook to write to disk correctly. The file size of output remains constant (414 bytes) and does not grow.
What is the problem that I'm having? What should I look into or check?
#include "opencv2/opencv.hpp"
using namespace cv;
#define fps 15
int main(int, char**)
{
VideoCapture cap(0); // open the default camera
VideoWriter m_vw;
bool m_isRecording = true;
if(!cap.isOpened()) // check if we succeeded
return -1;
Mat edges;
namedWindow("edges",1);
int skip = 30;
int n=0;
for(;;)
{
Mat frame;
cap >> frame; // get a new frame from camera
std::cout << "skip: " << skip << std::endl;
if (frame.empty()) {
if(frame.rows != 480 && frame.cols != 640){ exit(0); }
std::cout << "no frame" << std::endl;
if (cap.grab()) {
std::cout << "grab" << std::endl;
if (cap.retrieve(frame)) {
imshow("edges", frame);
}
}
} else if (skip-- > 0) {
std::cout << "hi" << std::endl;
} else {
edges = frame;
double width = cap.get(CV_CAP_PROP_FRAME_WIDTH);
double height = cap.get(CV_CAP_PROP_FRAME_HEIGHT);
if (m_isRecording && !m_vw.isOpened()) {
m_vw = cv::VideoWriter("~/ctrythis.avi", CV_FOURCC('M','J','P','G'), fps, cv::Size(width,height), true);
std::cerr << m_vw.isOpened()<<std::endl;
}
putText( edges, "caption",
cv::Point( width/4, height/2),
CV_FONT_HERSHEY_COMPLEX, 1, cv::Scalar(255, 255, 255) );
imshow("edges", edges);
std::cerr << n++ << " " << m_vw.isOpened() << std::endl;
m_vw << edges;
}
if(waitKey(1000/fps) >= 0) break;
}
// the camera will be deinitialized automatically in VideoCapture destructor
return 0;
}