Possible bug in OpenCV2.4 capturing frames from video - c++

Could it be that there is a bug in OpenCV2.4 highgui for capturing frames from video in windows?
I installed both the precompiled libraries, the ones compiled by me, I can compile everything perfectly and I can run my programs if
they are image based. The problem is only for videos. OpenCV crashes in this function always:
virtual IplImage* retrieveFrame(int)
{
unsigned char* data = 0;
int step=0, width=0, height=0, cn=0;
if(!ffmpegCapture ||
!icvRetrieveFrame_FFMPEG_p(ffmpegCapture,&data,&step,&width,&height,&cn)) <-------CRASHES HERE
return 0;
cvInitImageHeader(&frame, cvSize(width, height), 8, cn);
cvSetData(&frame, data, step);
return &frame;
}
This is inside the class cap_ffmpeg.cpp and is called by VideoCapture.
I tried versions 2.4.2 and 2.4.9. My programes were working finde with opencv2
More information
Windows 7
Build the projects with cmake (important as it could be that cmake is not building/finding the right codecs)
VisualStudio 9 2008
OpenCV 2.4.2
EDIT
It looks like it is actually a bug, so, how can I solve this problem and change my code to be able to read avi files?

As a temporary solution I decided to re-encode the videos so OpenCV doesn't use the ffmpeg. I used VirtualDub with the microsoft video 1 compression, which uses "msvidc32.dll" driver.
It works with all my videos so it is enough by now as I can keep working with OpenCV in windows.

I had similar problem. I downloaded VirtualDub, but it did not open one of my avi video because of its FMP4 encode. So in the end, the solution that solved the problem was to install ffdshow, a decoder for windows. See this link: http://www.moviecodec.com/video-codecs/fmp4-codec-with-virtualdub-45814/
Then I do not need to use VirtualDub anymore to re-encode my video anymore!

if your using x64. Please use opencv_ffmpeg245_64.dll this solves may solve the problem. Or rename opencv_ffmpeg245_64.dll to opencv_ffmpeg245.dll may solve the problem.

Related

dlib object detection always return zero results on iOS

I have been using dlib object detection successfully on mac. Now I want to use it in an iOS app. However, after spending countless hours, dlib object detector always returns zero rectangles.
ifstream fin(dataDir + "/object_detector.svm", ios::binary);
typedef dlib::scan_fhog_pyramid<dlib::pyramid_down<6> > image_scanner_type;
dlib::object_detector<image_scanner_type> detector;
dlib::deserialize(detector, fin);
vector<dlib::rectangle> dets = detector(dlibImage);
To make sure it’s not due to a different image, I am using exact same image for which detector returns 1 hit on mac. I have also printed uchar from part of the image in both mac and iOS, and it’s returning same values. So image data is exactly the same.
Probably dlib library is not built correctly for iOS. I have tried multiple approaches for this. From /example/build dir, below command was invoked.
cmake -G Xcode ..
cmake --build . --config Release
It generated dlib.xcodeproj project in dlib_build dir. I opened the project in xcode, changed architecture to iOS (armv7, arm64) and rebuild the library. This library was linked to my project. I got zero results with this approach. dlib was built in debug mode; I did not get any assertion errors.
Second approach tried was to use dlib/all/source.app in my project. I used all the proprocessing flags that are used by cmake or dlib.xcodeproj project. No errors, but still no matches.
I have compared build settings of my xcode project with examples.xcodeproj generated by cmake and it’s same. Also checked the xcode project from https://github.com/zweigraf/face-landmarking-ios, but no help.
Strange thing is detector takes couple of seconds to process and comes back with zero matches. So it’s doing something. I wish there was a debug logging that I can turn on for the detector.
I am out of ideas. Will appreciate if anyone can help. dlib is a wonderful library, I just wish it would have been easier to work with on iOS.
dlib is working fine on iOS too. Kicking myself for it, but I mixed up the detector instances. The detector on which I called below line was not used for object detection.
dlib::deserialize(detector, fin);
I was just using an empty detector instance, and it was returning 0 detections. By empty detector, I mean it was defined but deserialize method was not invoked. It would have been nice if dlib returned an error or warning, if a detector not loaded with object_detector.svm file is used for detection.
I have observed the same behavior with shape detector too. If sp.dat is not loaded, it silently reports 0 parts detected. Posting this as answer, in case someone else also makes such a silly mistake.

VideoCapture::read always returns false

I'm running OS X El Capitan and trying to use OpenCV VideoCapture to read an .avi file. I've tried it on both opencv 2.4.1 and 3, both of which have the same outcome.
cv::VideoCapture capture("filename.avi");
cv::Mat currentFrame, prevFrame;
bool capPrevSuccess = capture.read(prevFrame);
bool capCurrSuccess = capture.read(currentFrame);
I've verified that the filename.avi is in the current working directory and I don't see any errors in the console.
I'm beginning to wonder if it's something with my machine. I have a similar problem running VideoReader in MATLAB on the same machine. I believe MATLAB uses OpenCV VideoReader as well, perhaps they're connected.
Error using VideoReader/init (line 619) Failed to initialize internal
resources.
Error in VideoReader (line 172)
obj.init(fileName);
EDIT: Looks like this has something to do with the video files I'm using. I downloaded an mp4 video, and had no trouble with it. Unfortunately I need to use the video files I'm using (all .avi), yet they all seem to not work with VideoCapture.

XIMEA: openCV 2.4.9 can not find Ximea camera although it works fine with other programs

Although XIMEA camera(MQ013CG-E2) is ok and it is working with sample simple demo programs(for Win x64) from ximea.com, the next code always print "ximea camera not found":
VideoCapture cap;
if (!cap.open(CV_CAP_XIAPI)) cout << "ximea camera not found";
the same for :
CvCapture* capture = cvCreateCameraCapture(CV_CAP_XIAPI);
if (!capture) cout << "ximea camera not found";
If simple Logitech web-camera is connected then code above shows it exists (with CV_CAP_ANY flag). But ximea-camera is unreachable from openCV. OpenCV is build using cmake with option "WITH_XIMEA" by minGW from official source.
Have someone ever read something from ximea camera via openCV? I know this kind of cameras is not very popular, I could not even find tag "ximea" here (creating new tag requires 1500 reputation so no "ximea" tag here too).
UPD: I can transfer info from camera to openCV via xiApi.h-functions. So camera definitely works.
UPD2: I have been provided today with new MSVS-project example from ximea, which includes new openCV 2.4.9 libs. It contains code:
capture = cvCaptureFromCAM(0); //0=default, -1=any camera, 1..99=your camera
if (!capture) cout << "no camera detected" << endl;
I compiled it in MSVS it and exe-file started to work with ximea cam as expected using opencv-libs provided by ximea. But when I am trying to compile the same code in Eclipse and use opencv-libs created by MinGW with "WITH_XIMEA" option, it always shows "no camera detected". I checked all settings in CMake, Eclipse project "compiler includes" and "MinGW linker libs" twice but still can not understand where is my mistake.
I spent some time checking here and there all settings and decided to compile openCV by MSVS, not by minGW. Then I got error with "xiExt.h" (I missed it while minGW compilation process), I googled it and found this bug report. Then I commented one line in source code, compiled it by minGW and.. it started to work!
It is only openCV 2.4.9 proplem since 2.4.10 does not contain this buggy #include "xiExt.h" anymore.

Issue with running open CV face detection on Mac mountain lion

I ran into an issue getting the standard open CV face detection (facedetect) working. The web cam light comes on but noting happens, the program is launched with a tiny sized window like this:
I am working from an excellent blog post and sample code. Here I what I have done:
Install OpenCV & get OpenCV source
brew tap homebrew/science
brew install --with-tbb opencv
wget http://downloads.sourceforge.net/project/opencvlibrary/opencv-unix/2.4.6/opencv-2.4.6.tar.gz
tar xvzf opencv-2.4.6.tar.gz
Run the facedetect sample with the standard classifier.
cd ~/opencv-2.4.6/samples/c
chmod +x build_all.sh
./build_all.sh
./facedetect --cascade="../../data/haarcascades/haarcascade_frontalface_alt.xml"
I can modify the C++ sample code and recompile and run, but I have no idea what the issue is.
Does anyone have a suggestion?
Update The issue is the image from cvQueryFrame is empty:
IplImage* iplImg = cvQueryFrame( capture );
frame = iplImg;
if( frame.empty() )
{
cout << "FRAME EMPTY\n"; // This is getting logged
break;
}
Update: It works ok when the source is a static image, so the issue is something related to the webcam source.
You can try to localise the problem, did you try to capture an image from the and web cam show it, without running any other operation?
It seems there is a problem capturing image from the web cam via OpenCV, this kind of problems may happen due to hardware, for instance on my friends macbook pro captured image was 320x240 and on mine it was 640x480. My friend just changed a simple configuration from settings of the camera and his problem was solved. Your problem might be something like this.
Or you can try to run face detector just with some images, you need to change the code such that it loads an image from your disk and try to detect face on them. If it doesn't work that way either we can say that your problem is not camera, there is a bigger issue, or if it works we can surely say that the problem is web cam.
EDIT
If you are using IplImage type be sure to get couple more images from the camera, sometimes first image is empty.
This was due to a bug in OpenCV - its been fixed ( bug report here http://code.opencv.org/issues/3156) , but the version in homebrew/science is from before the fix.
You can get install a newer version by editing the brew formula for opencv ( based on this pull request https://github.com/Homebrew/homebrew-science/pull/540 )
edit /usr/local/Library/Formula/opencv.rb , and replace these lines:
url 'http://downloads.sourceforge.net/project/opencvlibrary/opencv-unix/2.4.6.1/opencv-2.4.6.1.tar.gz'
sha1 'e015bd67218844b38daf3cea8aab505b592a66c0'
with these ones
url 'https://github.com/Itseez/opencv/archive/2.4.7.1.tar.gz'
sha1 'b6b0dd72356822a482ca3a27a7a88145aca6f34c'
Then do
brew remove opencv
brew install opencv
Works on Mavericks (for me at least), should work on Mountain Lion
UPDATE: the version of OpenCV in homebrew/science has now been updated, so this answer is now out of date!
brew upgrade opencv
will make homebrew get the latest version, with fixed webcam capture.

OpenCV cvLoadImage() does not load images in visual studio debugger?

I am trying to work out a simple hello world for OpenCV but am running out of ideas as to why it is not working.
When I compile and run this code:
#include <cv.h>
#include <highgui.h>
int main(int argc, char* argv[])
{
IplImage* img = cvLoadImage( "myjpeg.jpg" );
cvNamedWindow( "MyJPG", CV_WINDOW_AUTOSIZE );
cvShowImage("MyJPG", img);
cvWaitKey(0);
cvReleaseImage( &img );
cvDestroyWindow( "MyJPG" );
return 0;
}
I get a grey box about 200x200 instead of the indicated .jpg file. If I use a different jpg I get the same kind of window, and if I put an invalid filename in, I get a very tiny window (expected).
I am using Visual Studio 2008 under Windows 7 Professional.
Most of the sample programs seem to work fine, so I am doubly confused how that code loads the sample jpgs just fine but in the code above it does not work (even tried the sample jpeg).
Update
The executables produced by compiling work fine, however the Visual Studio 2008 debugger loads a null pointer into img every time I try to run the debugger - regardless if the file location is implicit or explicit.
It really seems like there's a problem with the path to myjpeg.jpg since the current directory could be different when you're running under the debugger.
By default, the current directory that the Visual Studio debugger uses is the directory containing the .vcproj file, but you can change it in the project properties (Debugging -> Working Directory).
Are you 100% sure that you pass the absolute path correctly? Try to pass the same path to fopen and see if it also returns NULL. If so, then the path is incorrect.
If you want to see exactly what file is the library trying to open you can use Project Monitor with a filter on myjpeg.jpg.
Which version of OpenCV are you using? I've tried your code on the latest (OpenCV2.0) and it works fine. You can download OpenCV2.0 from here.
If you want the latest build, you can get check it out with SVN from here.
Try to add HAVE_JPEG into preprocessor definitions.
I encountered the same problem. The Debug version does not load the image, but when I compile and link it as a Release it works. I hope this helps