我正在使用 OpenCV 2.3 制作简单的网络摄像头程序,但遇到了编译错误。任何想法将不胜感激。
编译后,我在 imwrite 处收到以下错误(在下面代码的 read 函数中)。
这个样本 https://code.ros.org/svn/opencv/trunk/opencv/samples/cpp/stereo_match.cpp使用 imwrite 保存图像适用于我的环境,这表明 OpenCV 2.3 中的 imwrite 应该适用于我的环境。
error:
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 https://code.ros.org/svn/opencv/trunk/opencv/samples/cpp/stereo_match.cpp)仅使用 2 个(这是因为我也在做同样的事情)。http://opencv.itseez.com/modules/highgui/doc/reading_and_writing_images_and_video.html?highlight=imwrite#imwrite http://opencv.itseez.com/modules/highgui/doc/reading_and_writing_images_and_video.html?highlight=imwrite#imwrite
附注请原谅我在这里发布了与我发送给的问题相同的问题[电子邮件受保护] /cdn-cgi/l/email-protection如果您正在订阅它。我这样做的原因是因为这个网站对于各种目的来说似乎更具互动性和便利性。