无法保存从网络摄像头捕获的图像(OpenCV 2.3 的 imwrite 编译错误)
Can't save an image captured from webcam (imwrite compile error with OpenCV 2.3)
我正在使用OpenCV 2.3制作简单的网络摄像头程序,并被编译错误卡住。如有任何意见,我将不胜感激。
在编译后,我在imwrite(在下面的代码中的read函数中)得到以下错误:这个使用imwrite保存图像的示例在我的环境中工作,这表明OpenCV 2.3中的imwrite应该在我的环境中工作。
错误:error: invalid initialization of reference of type ‘const cv::_InputArray&’ from expression of type ‘cv::Mat*’
/usr/local/include/opencv2/highgui/highgui.hpp:110: error: in passing argument 2 of ‘bool cv::imwrite(const std::string&, const cv::_InputArray&, const std::vector<int, std::allocator<int> >&)’
代码摘录:
#include <iostream>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
using namespace std;
using namespace cv;
//IplImage* SampleClassA::dispImg = NULL;
Mat* SampleClassA::dispImg = NULL;
int read()
{
Mat* sharedImg;
sharedImg = getFrame();
if (sharedImg)
{
if (dispImg == NULL)
{
SampleClassA::dispImg = sharedImg;
}
Mat outMat;
outMat = imwrite("./out/sample.jpg", sharedImg);
}
sleep(100);
return 1;
}
Mat* getFrame()
//IplImage* ReadRealTime::getFrame()
{
if (!capture.isOpened()) // Actual capturing part is omitted here.
{
return NULL;
}
Mat frame;
capture >> frame;
return &frame;
}
</code>
顺便说一句,我很困惑imwrite需要2个参数还是3个参数。下面的链接和我的机器上的highgui.hpp都是3个参数,但我上面引用的示例代码(来自ros.org)只使用了2个(这是因为我也在做同样的事情)。http://opencv.itseez.com/modules/highgui/doc/reading_and_writing_images_and_video.html?highlight=imwrite imwrite
p。如果你订阅了OpenCV@yahoogroups.com,请原谅我在这里发布了同样的问题。我这样做的原因是,这个网站似乎更具互动性,方便各种用途。
第三个参数是可选的(格式相关参数数组)。你得到的错误是因为'sharedImage'的类型是Mat*,不能自动转换为'const cv::_InputArray&',这是imwrite的预期类型。如果更仔细地查看示例,您将看到作为second传入的参数类型实际上是一个'Mat'(而不是Mat*)。
相关文章:
- OpenCV Android C++ imwrite not found
- OpenCV imwrite 函数导致'undefined symbol'
- 使用imwrite OpenCV时断言失败
- 如何使用imwrite OpenCV 3.1将图像写入目录?
- OpenCV imwrite不会保存图像
- Opencv 未定义的符号用于架构 cv:imwrite Mac osX high Sierra.
- OpenCV imwrite 不写入图像
- 无法使用cv :: imwrite保存垫子图像在JNI本机代码OPENCV中
- OPENCV IMWRITE保存黑色PNG
- Opencv:用imwrite保存一个双矩阵
- 在opencv中使用imwrite保存图像时,会将图像全部写入黑色,但imshow会正确显示
- OpenCV:imwrite在保存时更改通道像素值
- OpenCV imwrite 保存完整的黑色 jpeg
- opencv中的imwrite提供了一个黑/白图像
- 无法在OpenCV中使用imwrite写入图像
- 无法保存从网络摄像头捕获的图像(OpenCV 2.3 的 imwrite 编译错误)
- 在OpenCV中使用cv::imwrite运行时错误
- OpenCV无法使用imwrite写入图像
- OpenCV imwrite()不保存图像
- 无法在OpenCV中使用imwrite写入灰度图像