I am new to OpenCV, and trying to capture an image, and then save it to a file. I am posting the code for your reference, below.
The jpg file is being saved, but it is black.
// Capture the Image from the webcam CvCapture *pCapturedImage = cvCreateCameraCapture(0); // Get the frame IplImage *pSaveImg = cvQueryFrame(pCapturedImage); // Save the frame into a file cvSaveImage("test.jpg". ,pSaveImg); // A JPG FILE IS BEING SAVED // OF 6KB , BUT IT IS BLACK
All of the functions are succesful. I have tried the above code in both XP and Vista - the result is a black image on both. Please let me know what I am missing out.
Using the PIL module to save image to file in Pythonsave() function. This function is used to export an image to an external file. But to use this function, first, we should have an object which contains an image. We can set the format using the format parameter.
cv2. imwrite() method is used to save an image to any storage device. This will save the image according to the specified format in current working directory.
OpenCV provides imwrite() function to save an image to a specified file. The file extension represents the image format. Here, "Destination" is where we want to save the image. In this program, we save the image as "Lakshmi.
The Mat class of OpenCV library is used to store the values of an image. It represents an n-dimensional array and is used to store image data of grayscale or color images, voxel volumes, vector fields, point clouds, tensors, histograms, etc.
If you use C++, it is best to use C++ interface:
using namespace cv; // Capture the Image from the webcam VideoCapture cap(0); // Get the frame Mat save_img; cap >> save_img; if(save_img.empty()) { std::cerr << "Something is wrong with the webcam, could not get frame." << std::endl; } // Save the frame into a file imwrite("test.jpg", save_img); // A JPG FILE IS BEING SAVED
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With