c++ - 在 OpenCV 中保存图像

标签 c++ opencv computer-vision

我是 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/

相关文章:

c++ - 外部全局变量仍未在此范围内声明

c++ - 如何使用指针对随机地址进行操作?

c++ - 使用 boost::array 中的 std::string::assign 与 std::array 的不兼容性

image - OpenCV - 从图像中删除水平点或线导致图像质量较低

opencv - 如何使用 opencv2.3 获取 r,g,b 值

opencv - 如何从边缘图像中获取顶点

c++ - LibRdKafka:commited_offset 始终为 -1001

opencv - 读取4 channel tif文件时,值不同于SKIMAGE、TIFFFILE等

python - OpenCV Hough行不显示

c++ - 使用 OpenCV 进行相机校准