无法保存从网络摄像头捕获的图像(使用OpenCV 2.3的imwrite编译错误) [英] Can't save an image captured from webcam (imwrite compile error with OpenCV 2.3)

查看:666
本文介绍了无法保存从网络摄像头捕获的图像(使用OpenCV 2.3的imwrite编译错误)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用OpenCV 2.3做简单的网络摄像头程序,被编译错误困住。任何想法将不胜感激。

I'm making simple webcam program using OpenCV 2.3 and got stuck by the compile error. Any idea will be appreciated.

编译时,我在imwrite(在下面的代码中的read函数中)得到以下错误。

Upon compile, I get the following error at imwrite (in read function in the code below).

本示例使用imwrite保存图像在我的环境中工作,这表示在OpenCV 2.3中的imwrite应该在我的环境中工作。

This sample that uses imwrite to save an image works on my environment, which indicates imwrite in OpenCV 2.3 should work on my env.

错误:

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>

Btw,我很困惑imwrite是否需要2个参数或3.以下链接和highgui。 hpp在我的机器上说3 args,但我上面引用的示例代码(从ros.org )只使用2(这是因为我做的相同)。
http://opencv.itseez.com /modules/highgui/doc/reading_and_writing_images_and_video.html?highlight=imwrite#imwrite

Btw, I'm confused whether imwrite takes 2 arguments or 3. Both the following link and highgui.hpp on my machine say 3 args, but the sample code I cited above (from ros.org) uses only 2 (which is because I'm doing the same). http://opencv.itseez.com/modules/highgui/doc/reading_and_writing_images_and_video.html?highlight=imwrite#imwrite

ps。原谅我的帖子发布相同的问题,我发送到OpenCV@yahoogroups.com如果你订阅它。

ps. Forgive my posting the same question here with the one I sent to OpenCV@yahoogroups.com if you are subscribing to it. The reason I did this is because this website seems more interactive and convenient for various purposes.

推荐答案

第三个参数是可选的的格式相关参数)。
你得到的错误是因为'sharedImage'是Mat *类型,不能自动转换为'cntc :: :: InputArray&',这是imwrite的预期类型。如果仔细看看例子,你会看到以秒为单位传递的参数类型实际上是一个Mat(不是Mat *)。
希望这有帮助。

The third param is optional (array of format dependent parameters). The error you are getting is because 'sharedImage' is of type Mat* that can't cast automatically to 'const cv::_InputArray&', the expected type for imwrite. If look at the example more carefully, you'll see that the type of the parameter passed in as second is actually a 'Mat' (not a Mat*). Hope this helps.

这篇关于无法保存从网络摄像头捕获的图像(使用OpenCV 2.3的imwrite编译错误)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆