Using Mat objects in OpenCV2.4.9 in MS VS 2008 [closed]

asked 2014-06-26 19:21:50 -0600

bob h gravatar image

Hello, I'm trying to utilize OpenCV 2.4.9 in MS Visual Studio 2008. The problem I have is that I cannot pass images into a Mat object (either from my camera or from files). For instance the following code returns "No image found. Check path!":

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace std;
using namespace cv;

int main( int argc, char** argv)
{
   cv::Mat baboon = cv::imread("C:\\OpenCV249\\sources\\samples\\cpp\\baboon.jpg",0);

   if (!baboon.data)
   {
      cout << "No image found! Check path." << endl;
      cv::waitKey(10000);
      return -1;
   }
   else
   {
      cv::namedWindow("Window",CV_WINDOW_AUTOSIZE);
      cv::imshow("Window",baboon);
      cv::waitKey();
      return 0;
   }

}

I am able to read images in using the older code:

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>

using namespace std;
using namespace cv;

int main( int argc, char** argv)
{
    IplImage *img = cvLoadImage("C:\\OpenCV249\\sources\\samples\\cpp\\baboon.jpg"
,CV_LOAD_IMAGE_UNCHANGED);
    while(1)
    {
        cvNamedWindow("Window",CV_WINDOW_AUTOSIZE);
        cvShowImage("Window",img);
        cvWaitKey(10);
    }
}

Nevertheless, I would like to work with the newer classes. I have tried converting IplImage to Mat, but that also fails (i.e. nothing is passed). I get this error running both .jpg files and .png files. I have checked to ensure that this path leads me to the image. Also, I have tried running in both debug and release modes (and have made sure to change the linked .lib files as needed). Here is the entry for OpenCV in the PATH enviornmental variable: "C:\OpenCV249\build\x64\vc10\bin\;"

I'm wondering if the .dll's in the new version of OpenCV are not compatible with MS VS 2008? If so, is there any way around this? I would prefer to use the newer version.

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by sturkmen
close date 2020-09-27 08:48:46.238168

Comments

2

if you run into that kind of trouble, you most likely have a linking problem.

C:\OpenCV249\build\x64\vc10\bin\ <--> VS 2008 (do you see the mismatch?)

you can't use vs2010 stuff with vs2008. also x64 vs x86

berak gravatar imageberak ( 2014-06-27 01:13:49 -0600 )edit
2

Solution is to rebuild the sourcecode using the vc8 compiler. That will do the trick but you will not be able to use the prebuilt binaries unless you upgrade to visual studio 2010.

StevenPuttemans gravatar imageStevenPuttemans ( 2014-06-27 07:03:37 -0600 )edit
1

aren't there prebuild libs for vs2008 anymore ? (that would be vc9, iirc)

but yes, building the libs from src, using the same compiler you plan to use later will definitely solve it.

berak gravatar imageberak ( 2014-06-27 07:10:21 -0600 )edit
1

Yeah there should be vc9 prebuilt functions also, but I have learned that building them yourself always has advantages.

StevenPuttemans gravatar imageStevenPuttemans ( 2014-06-27 07:35:12 -0600 )edit

Hi, im also fresher to this tool, like you i did sample program in opencv2.4.9 with c++ vs2008, as usual like while im working with iplimage no problem im getting 100% output, coming to mat object im getting runtime error that is "microsoft visual studio, c runtime library has detected a fatal error in filename.exe." i dont why it s happening, tell me any solution, may i felt is this any compactibility problelm? tel anybody, thank you

govardhana padavala gravatar imagegovardhana padavala ( 2014-08-27 01:18:44 -0600 )edit

Please open your own question. First read the FAQ to have an idea what to include to get a decent answer ...

StevenPuttemans gravatar imageStevenPuttemans ( 2014-08-27 04:01:08 -0600 )edit