5

I'm having some difficulties trying to use OpenCV with visual studio 2008 (Professional Edition). I believe I've done everything necessary to run a OpenCV sample, but it crashes due to a run-time error. This is driving me insane, I hope someone can help.

But first things first.

My Installation Procedure

  1. Downloaded OpenCV 2.4.5 from sourcefourge.net.

  2. When prompted, I chose "Z:\Games instalados\OpenCV" as my "Extract to" option in the .exe downloaded from the above link.

  3. Went to "Control Panel" -> "System" -> "Advanced System Settings", then clicked on the "Environment Variables" in the "Advanced" tab. In the "System Variables" box I highlighted "Path" and clicked on "Edit...". In the new window I added to the end of the text in "Variable Value" my installation directory with a ";" before it, namely ";Z:\Games instalados\OpenCV\opencv\build\x86\vc11\bin" (without the double quotes). Here's a screenshot: screenshot.

  4. Created a new project in Visual Studio 2008: File -> New -> Project..., chose "Other Languages" -> "Visual C++ -> "Win32" as the project type; "Win32 Console Application" as the template. new project Clicked "next" in the new window, then chose "Console Application", "Empty Project" and then "Finish". new window
  5. In the "Solution Explorer", right-clicked my program and chose "Properties". Then "Configuration Properties" -> "C/C++" -> "General", and on Additional Include Directories I've added:
    • Z:\Games instalados\OpenCV\opencv\build\include
    • Z:\Games instalados\OpenCV\opencv\build\include\opencv
    • Z:\Games instalados\OpenCV\opencv\build\include\opencv2 "Additional Include
  6. Now in "Configuration Properties" -> "C/C++" -> "Linker" -> "General", in the "Additional Library Directories" I've added "Z:\Games instalados\OpenCV\opencv\build\x86\vc11\lib". Additional Library
  7. Now in "Configuration Properties" -> "C/C++" -> "Linker" -> "Input", in the "Additional Dependencies" I've added:
    • opencv_calib3d245.lib
    • opencv_contrib245.lib
    • opencv_core245.lib
    • opencv_features2d245.lib
    • opencv_flann245.lib
    • opencv_gpu245.lib
    • opencv_highgui245.lib
    • opencv_imgproc245.lib
    • opencv_legacy245.lib
    • opencv_ml245.lib
    • opencv_nonfree245.lib
    • opencv_objdetect245.lib
    • opencv_photo245.lib
    • opencv_stitching245.lib
    • opencv_superres245.lib
    • opencv_ts245.lib
    • opencv_video245.lib
    • opencv_videostab245.lib
    • opencv_calib3d245d.lib
    • opencv_contrib245d.lib
    • opencv_core245d.lib
    • opencv_features2d245d.lib
    • opencv_flann245d.lib
    • opencv_gpu245d.lib
    • opencv_highgui245d.lib
    • opencv_imgproc245d.lib
    • opencv_legacy245d.lib
    • opencv_ml245d.lib
    • opencv_nonfree245d.lib
    • opencv_objdetect245d.lib
    • opencv_photo245d.lib
    • opencv_stitching245d.lib
    • opencv_superres245d.lib
    • opencv_ts245d.lib
    • opencv_video245d.lib
    • opencv_videostab245d.lib (Please note that I didn't added "opencv_ffmpeg245.lib", despite what the screenshot shows). Additional Dependencies
  8. Right-clicked "Source Files" -> "Add" -> "Existing Item" and added the "Z:\Games instalados\OpenCV\opencv\samples\cpp\cout_mat.cpp" file. Added cout_mat

The Problem

  1. Built the project, no problems here, "Build succeeded".
  2. "Debug" -> "Start Debugging". The following appears: The error http://s8.postimg.org/wdkubk5o3/the_error.jpg Full size image for the error: http://s8.postimg.org/wdkubk5o3/the_error.jpg

I've also tried with the hough lines sample, but it didn't worked as well (even with the image in the same folder as the .exe imread() wouldn't find the image).

Any help would be greatly appreciated.

If I've not made some of the installation steps clear enough, please post a comment.

Reason this question is suited for stackoverflow.com

I've detailed a full installation procedure (from scratch) for the latest release of OpenCV to be used with Visual Studio 2008. If anyone solves this question we will have a complete, working tutorial for anyone having the same necessity (use latest OpenCV with visual studio 2008), and possibly (because of the depth in the installation procedure) a general guide for installing the latest OpenCV with most Visual Studio versions (not just the 2008, since the tutorial wouldn't change much, and the reader could easily adapt it).

Community
  • 1
  • 1
JLagana
  • 1,224
  • 4
  • 14
  • 33
  • "general guide for installing the latest OpenCV with most Visual Studio versions (not just the 2008, since the tutorial wouldn't change much, and the reader could easily adapt it)." What is wrong with the maintained OpenCV installation guide on the OpenCV [Website](http://docs.opencv.org/doc/tutorials/introduction/windows_visual_studio_Opencv/windows_visual_studio_Opencv.html) – GPPK May 16 '13 at 07:39
  • That was my first approach. But the results were the same. – JLagana May 16 '13 at 17:28
  • Please edit your post so it properly shows the error that appears. – Bull May 17 '13 at 04:48
  • Is the image too small? you can go to: http://s8.postimg.org/wdkubk5o3/the_error.jpg – JLagana May 17 '13 at 19:03
  • 1
    Due to the title, all the installion information, and the vc9 v's vc11 issue, I missed the point that this problem was specific to opencv\samples\cpp\cout_mat.cpp. I get the same error if I try `cv::Mat m; cout << m;` with opencv 2.4.4. It seems this is an opencv issue - found another with the problem at http://answers.opencv.org/question/6094/using-cout-with-mat-object/. They rebuilt opencv and it apparently fixed the problem. – Bull May 18 '13 at 12:09
  • Hi, may I know if yours is working with microsoft visual studio 2008 using OpenCV with vc11? Mine seems to give me error when I use vc11 and I read some says that for Microsoft Visual Studio 2008, it will have to be vc9 instead. – AuroraBlaze Dec 12 '14 at 06:45

2 Answers2

1

I would suggest if you want to test proper installation of opencv. Just load a simple.jpg image in opencv and display it. If this works then you can start debugging the program which is crashing. You can debug it by successively enabling the cout. May be first just enable the default cout in example cout_mat.cpp and comment rest of it.
Here is the simple load program you can try to test your installation.

int main(int argc, char*argv[])
{

    cvNamedWindow("My_Win", CV_WINDOW_AUTOSIZE);
    IplImage *img = cvLoadImage("C:\\vid_an2\\Desert.jpg", CV_LOAD_IMAGE_UNCHANGED );

    std::cout<<"Info About Image"<<std::endl;

    std::cout<<"Size of Image "<<img->nSize<<std::endl;
    std::cout<<"Image channels "<<img->nChannels<<std::endl;
    std::cout<<"Image Width "<<img->width<<std::endl;
    std::cout<<"Image Height "<<img->height<<std::endl;
    std::cout<<"Image Depth "<<img->depth<<std::endl;
    std::cout<<"Image WidhtStep "<<img->widthStep<<std::endl;
    std::cout<<"Image Size "<<img->imageSize<<std::endl;

    cvShowImage("My_Win", img);

    cvWaitKey(0);

    // Free the resources.
    cvDestroyAllWindows();
    cvReleaseImage(&img);
return 0;
}
praks411
  • 1,972
  • 16
  • 23
  • This code works fine. Does this unequivocally means that I correctly installed OpenCV? Because I still can't run cout_mat.cpp (sample from OpenCV). – JLagana May 17 '13 at 13:37
  • In other words, should I start looking for errors in "cout_mat.cpp", because my installation works fine? – JLagana May 17 '13 at 13:48
  • I quickly tried cout_mat.cpp. I think the problem is not with installation of opencv. But most possibly it is related to operator<< which is use to cout(display on console) Mat object directly. If you disable all cout statement which put Mat object the code works fine. Could be some issue with overloading << operator. – praks411 May 17 '13 at 14:56
  • I've a small question i am trying to install opencv 2.4.13 and it includes only vc11 and vc12 and I am using visual studio2010 so can I use vc11 in visual studio2010 ?? – Sara Oct 28 '16 at 10:28
1

Since you are using VS2008, change Z:\Games instalados\OpenCV\opencv\build\x86\vc11 to Z:\Games instalados\OpenCV\opencv\build\x86\vc9. The vc11 folder is for VS2012, vc9 is for VS2008.

Bull
  • 11,771
  • 9
  • 42
  • 53
  • Changed it, the same run-time error still shows while trying to run cout_mat.cpp. – JLagana May 17 '13 at 13:34
  • After changing the path environment variable did you restart visual studio so that it picks up the new environment (actually because of dll loading you may need to reboot)? Can you single step with the debugger to where the access violation occurs? – Bull May 18 '13 at 01:07