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;
}
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.