Save image, C++
I am trying to save a color image from a SoftKinetic DS311 camera, using OpenCV.
However, the imagefile that is saved is black.
CvCapture *capture = cvCreateCameraCapture(0);
cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, 640);
cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, 480);
// Get one frame
IplImage* frame;
for (int i = 0; i < 25; i++)
{
frame = cvQueryFrame(capture);
}
printf("Image captured \n");
cvSaveImage("test.jpg", frame);
printf("Image Saved \n");
This is the part of the code that is supposed to save the .jpeg The program is in a function that is called continously in the main loop, so it should not be because the camera is not initialized?
OpenCV 2.4.X or OpenCV3?
OpenCV 2.4.9 :)
Can you please use C++ and not C? Maybe it is because it is old? Use cv::Mat instead of IplImage*, cv::imwrite instead of cvSaveImage, cv::VideoCapture instead of CvCapture, capture >> frame instead of cvQueryFrame, etc...
Just for fun, could you add the following just after your printf:
cv::imshow("Some title", frame); waitKey(0);
If you haven't already done so, it will show you the image that is about to be saved. So you will be able to determine whether it is the saving function (maybe missing plugin for jpg) or something else. If it isn't that, I don't know (I am not an OpenCV master yet ;) )
By the way, You are saving just the last frame, since the save function is outside the for loop.
I now changed it, I didn't realize I had it mixed up :/
VideoCapture cap(0);
However, the problem is the same, it only shows a black image. Would you like to see the entire code? I added it here in a .txt file http://www.myupload.dk/showfile/c4l3m0.txt