我是 OpenCV 的新手,正在 try catch 图像,然后将其保存到文件中。我在下面发布代码供您引用。
正在保存 jpg 文件,但它是黑色的。
// 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
所有功能都成功了。我在 XP 和 Vista 中都尝试过上面的代码——结果都是黑色图像。请让我知道我错过了什么。
最佳答案
如果你使用C++,最好使用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
关于c++ - 在 OpenCV 中保存图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/851679/