Error with cv::read - c++

Hello I am developing an application on Qt where I implement SURF algorithm on GPU.
When I put this:
FileStorage file1("requete.txt", cv::FileStorage::READ);
file1[path.toStdString()] >> descriptor1;
where "requete.txt" contains descriptors, I have the following error "between" the two lines of code:
penCV Error: Unspecified error (The node does not represent a user object (unknown type?)) in cvRead, file /home/dev/Téléchargements/opencv-new/opencv-2.4.10/modules/core/src/persistence.cpp, line 4991
terminate called after throwing an instance of 'cv::Exception'
what(): /home/dev/Téléchargements/opencv-new/opencv-.4.10/modules/core/src/persistence.cpp:4991: error: (-2) The node does not represent a user object (unknown type?) in function cvRead
What should I do to get rid of the error?

Related

How to use OpenCV with highGUI on QtCreator?

I am trying to display a basic image that is loaded off disk using the highgui module within the cv2 library.
I am able to do this when making a Qt Widgets application but the Qt window becomes redundant; however when using a console application I obtain this error:
OpenCV Error: Assertion failed (size.width>0 && size.height>0) in imshow, file /build/opencv-ISmtkH/opencv-2.4.9.1+dfsg/modules/highgui/src/window.cpp, line 269
terminate called after throwing an instance of 'cv::Exception'
what(): /build/opencv-ISmtkH/opencv-2.4.9.1+dfsg/modules/highgui/src/window.cpp:269: error: (-215) size.width>0 && size.height>0 in function imshow
Here is my code:
int main ()
{
cv::Mat inputImg = cv::imread("/home/pi/scrot1.png");
cv::imshow("Display Image", inputImg);
}
I have written a script in python that can be run via terminal and it calls the high gui module. I would like to write this in C++ but I cannot seem to be able to load a basic image!
EDIT:
The path was actually invalid. However, even with the correct path I cannot see the image with HighGui.
The error means that the image is not loaded correctly.
You can check this using:
if(image.empty()) {
// not loaded correctly
}
You need to be sure that:
the path is valid
the image is not corrupted
you have the privileges to access that folder
To actually display the image, you need to use cv::waitKey() after the imshow.

opencv Unrecognized or unsupported array type in function cvGetMat (c++)

i'm trying to detect a face using a cascade classifier (haarcascade_frontalface_alt_tree.xml), but this line
cascade.detectMultiScale(img, vec, 1.1, 2, CV_HAAR_FIND_BIGGEST_OBJECT, cv::Size(40, 40), cv::Size(125, 160));
gives me this error:
OpenCV Error: Bad flag (parameter or structure field) (Unrecognized or unsupported array type) in cvGetMat, file /home/rigu10/opencv-2.4.9/modules/core/src/array.cpp, line 2482
terminate called after throwing an instance of 'cv::Exception'
what(): /home/rigu10/opencv-2.4.9/modules/core/src/array.cpp:2482: error: (-206) Unrecognized or unsupported array type in function cvGetMat
the image img is a cv::Mat created using imread() and vec is a vector<cv::Rect>.
i'm woring on debian with opencv 2.4.9, but the same code works fine in macos using the same version of opencv.

opencv: getting a sequence of images piped from gphoto2

I'm trying to get the output of gphoto2 movie capture over to my opencv program over a pipe
gphoto2 --capture-movie --stdin | ./myexe
My first attempt was to do it like this:
while(1)
{
std::stringstream ss;
ss << "/dev/stdin";
cv::Mat m = cv::imread(ss.str());
namedWindow( "LiveView", WINDOW_AUTOSIZE );
imshow( "LiveView", m );
waitKey(1);
}
But sadly, while compiling works, executing doesn't, I am getting an
OpenCV Error: Bad flag (parameter or structure field) (Unrecognized or unsupported array type) in cvGetMat, file /build/buildd/opencv-2.4.2+dfsg/modules/core/src/array.cpp, line 2482 terminate called after throwing an instance of 'cv::Exception'
what(): /build/buildd/opencv-2.4.2+dfsg/modules/core/src/array.cpp:2482: error: (-206) Unrecognized or unsupported array type in function cvGetMat
I saw something similar asked here, but it doesn't work for me - compiling fails at
readbytes=read(fileno(stdin),ca,BUFSIZE);
error: no matching function for call to ‘read(int, char [10240], int)’
I'm quite a novice to c++/opencv, so I'm probably missing some includes or something.
Because I'm a new user, I cannot comment to ask for help/clarification over there, so I decided to ask a new question instead.
This piping seems to be bad coding practice. Use the libgphoto API to extract the images/movie and use that with your OpenCV stuff.
It's easier than it sounds. See this blogpost: http://sepharads.blogspot.nl/2011/11/camera-tethered-capturing-using.html

error retrieving background image from BackgroundSubtractorMOG2

I'm trying to get the background image from BackgroundSubtractorMOG2:
bg->getBackgroundImage(back);
but I get a Thread 1 SIGABRT (which as a c++ n00b puzzles me)
and this error:
OpenCV Error: Assertion failed (nchannels == 3) in getBackgroundImage, file /Users/hm/Downloads/OpenCV-2.4.4/modules/video/src/bgfg_gaussmix2.cpp, line 579
libc++abi.dylib: terminate called throwing an exception
(lldb)
I'm not sure what the problem is, suspecting it's something to do with the nmixtures paramater, but I've left that as the default(3). Any hints ?
It looks like you need to use 3 channel images rather than grayscale. Make sure the image type you are using is CV_8UC3 or if you are reading from a file use cv::imread('path/to/file') with no additional arguments.

OpenCV Error: Bad argument (Array should be CvMat or IplImage) in cvGetSize

I have successfully written a video processing program. I used ubuntu and Netbeans for programming. When I run this program on netbeans it runs perfectly and gives expected output.
I built executable file of this program both in debug and release mode and tried to run them in the command line. Now I get the following error. But Netbeans doesn't complain about this. Could someone point out what might be the problem?
OpenCV Error: Bad argument (Array should be CvMat or IplImage) in cvGetSize, file /home/<user>/trunk/opencv/modules/core/src/array.cpp, line 1238
terminate called after throwing an instance of 'cv::Exception'
what(): /home/<user>/trunk/opencv/modules/core/src/array.cpp:1238: error: (-5) Array should be CvMat or IplImage in function cvGetSize
thank you in advance
Can you check if the input argument to cvGetSize is:
a NULL pointer? What is the result of querying/retrieving the frame?
a CvSeq?
a 1- or 3-dimensional array?
Usually it is the first.
That's the way OpenCV talks to you - it's more often the runtime exception than a compiler error.