Question

I do realise that this problem is pretty common, but I have spent around 4 days so far, trying to fix it on my own, using all the smart advice I found on the Internet and - unfortunately - I've failed.

I managed to make openCV2.4.6 work with my VisualStudio 2012, or at least that's what I assumed after I was able to stream a video from my webcam with this example:

#include "stdafx.h"
#include "opencv2/opencv.hpp"

int main( int argc, const char** argv )
{
CvCapture* capture;
IplImage* newImg;

while (true)
{
capture = cvCaptureFromCAM(-1);
newImg = cvQueryFrame( capture );

cvNamedWindow("Window1", CV_WINDOW_AUTOSIZE);    
cvShowImage("Window1", newImg);

int c = cvWaitKey(10);
if( (char)c == 27 ) { exit(0); }   
}

cvReleaseImage(&newImg); 
return 0;

}

Everything worked fine, so I decided to play around with it and I made an attempt to use a simple image processing operation such as converting rgb to grayscale. I modified my code to following:

#include "stdafx.h"
#include "opencv2/opencv.hpp"


int main( int argc, const char** argv )
{
CvCapture* capture;
IplImage* img1;
IplImage* img2;

while (true)
{
capture = cvCaptureFromCAM(-1);
img1 = cvQueryFrame( capture );
img2 = cvCreateImage(cvGetSize(img1),IPL_DEPTH_8U,1);
cvCvtColor(img1,img2,CV_RGB2GRAY);

cvNamedWindow("Window1", CV_WINDOW_AUTOSIZE);
cvNamedWindow("Window2", CV_WINDOW_AUTOSIZE);

cvShowImage("Window1", img1);
cvNamedWindow("Window2", CV_WINDOW_AUTOSIZE);

int c = cvWaitKey(10);
if( (char)c == 27 ) { exit(0); }

}

cvReleaseImage(&img1);
cvReleaseImage(&img2);


return 0;

}

And that's the place where the nightmare started. I keep getting the

Unhandled exception at at 0x000007FEFD57AA7D in opencvbegginer.exe: Microsoft C++ exception: cv::Exception at memory location 0x000000000030F920.

I did some research and tried few solutions, such as exchanging opencv_core246.lib to opencv_core246d.lib, etc. For a second I hoped it might work, but the reality punched me again with msvcp100d.dll missing. I tried to update all redistributable packages, but it didn't change the fact I keep getting this error. I tried to find out how to fix it another way and I found some forum on which they tell to go to C/C++ properties and change the Runtime Library to MTd, so... I tried this as well, but - as you can notice by now - it didn't work.

At this current moment I just ran out of ideas on how to fix this, so I would be really grateful for any help.

Cheers

PS. Important thing to add: when I got the unhandled exception, opencv 'spoke to me', saying

OpenCV Error: Bad argument in unknown function, file ......\scr\opencv\modules\core\src\array.cpp, line 1238

However, I already assumed way back then that I'm just not clever enough with my idiot-resistant code and I tried few other pieces of code that were written by competent people - unfortunately, I keep getting exactly the same error (the rest is the same as well, after I change the things mentioned above).

Was it helpful?

Solution

If img1 == NULL, then it crashes on cvGetSize(img1). Try enclosing the code after cvQueryFrame in an if (img1 != NULL).

However, if it returns NULL for every frame, it means there is something wrong with your camera/drivers/way you capture the frames.

You should also move the cvNamedWindow outside of the loop, since there is no need for it to be recreated for every frame.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top