开发者

Can't save an image captured from webcam (imwrite compile error with 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.

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

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:

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> >&)’

code excerpt:

#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;
        开发者_JAVA百科}
        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, 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. 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜