opencv: getting a sequence of images piped from gphoto2 - c++

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

Related

Error with cv::read

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?

OpenCV - Unknown array type in function cvarrToMat

I'm using OpenCVinside one of my projects (iOS app). I'm trying to use cvMatchTemplate (Link : Documentation ) . For some reason I'm getting this error :
OpenCV Error: Bad argument (Unknown array type) in cvarrToMat, file /Volumes/build-storage/build/master_iOS-mac/opencv/modules/core/src/matrix.cpp, line 943
libc++abi.dylib: terminating with uncaught exception of type cv::Exception: /Volumes/build-storage/build/master_iOS-mac/opencv/modules/core/src/matrix.cpp:943: error: (-5) Unknown array type in function cvarrToMat
Running this code:
cv::Mat mOriginal, mTemp,res;
UIImageToMat(original, mOriginal);
UIImageToMat(temp, mTemp);
// Crashing at this line
cvMatchTemplate(&mOriginal, &mTemp, &res, CV_TM_CCOEFF_NORMED);
Any help would be greatly appreciated. Thank you.
#Miki too humble to post his answer :)
Don't use obsolete C api. Use cv::matchTemplate
Working code:
cvMatchTemplate(mOriginal, mTemp, res, CV_TM_CCOEFF_NORMED);

How do I initialize a matchTemplateBuff in OpenCV?

I'm writing a pattern matching code using OpenCV with CUDA on Mac OS X. After ~ 70 frames, it slows down a lot. Using mach_absolute_time() I've been able to track the culprit (Initially I thought it was a disk access issue):
gpu::matchTemplate(currentFrame,
correlationTargets[i]->correlationImage,
temporaryImage,
CV_TM_CCOEFF_NORMED);
I believe this is caused by some memory issue inside matchTemplate. After a lot of search, I found the matchTemplateBuf structure which is presumably for memory reuse. Since the problem seems memory releated, I think using this may be the solution. However, the following code crashes:
gpu::MatchTemplateBuf mtBuff;
[...]
for(...) {
gpu::matchTemplate(correlationTargets[i]->croppedImage,
correlationTargets[i]->correlationImage,
correlationTargets[i]->maxAllocation,
CV_TM_CCOEFF_NORMED, mtBuff);
With error:
OpenCV Error: Gpu API call (Unknown error code [Code = 9999]) in convolve, file /Users/sermarc/Downloads/opencv-2.4-3.8/modules/gpu/src/imgproc.cpp, line 1431 libc++abi.dylib: terminating with uncaught exception of type cv::Exception: /Users/sermarc/Downloads/opencv-2.4-3.8/modules/gpu/src/imgproc.cpp:1431: error: (-217) Unknown error code [Code = 9999] in function convolve
I believe this is because the matchTemplateBuff is not properly initialized. However, I cannot find any information or example that shows it being set on a valid state.
The code works with:
gpu::matchTemplate(correlationTargets[i]->croppedImage,
correlationTargets[i]->correlationImage,
correlationTargets[i]->maxAllocation,
CV_TM_CCOEFF_NORMED);

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.