Ask Your Question
0

cv::Exception at memory location 0x003AEBB8

asked 2013-08-27 08:21:46 -0500

lolaalol gravatar image

When i run my program in VS 2012 ( in 2010 everything was working ) this is the error im getting :

Unhandled exception at at 0x7698C41F in test.exe: Microsoft C++ exception: cv::Exception at memory location 0x0034EE30.

and in my console program i see this : OpenCV Error : Assertion failed (size.width)0 && size.height)0) in unknow function, file C:\slave\builds\WinInstallerMegaPack\src\opencv\modules\highgui\src\window.cpp

When i debugging my code, its craching here : imshow("Img Source", ImgSource);

here my full code ( the same exact code working in vs 2010 )

#include <opencv2\core\core.hpp>

include <opencv2\highgui\highgui.hpp>

include <opencv2\imgproc\imgproc.hpp>

include <iostream>

using namespace cv; using namespace std;

int main() {

Mat ImgSource;
Mat ImgGris;
Mat ImgDest, ImgCanny;
int NbreObjetTrouve, NbrePointContours;
Moments PointM;

vector<vector<Point>> Contours;  //Pour garder les valeurs des points sur chacun des contours.
vector<Point> PointApprox;      // Approximation du nombre de points pour décrire une forme.
vector<Vec3f> Cercles;
Point PointMilieu;

ImgSource = imread("cercles.jpg", CV_LOAD_IMAGE_COLOR);

namedWindow("Img Source");
namedWindow("Img Destination 1");


imshow("Img Source", ImgSource);

GaussianBlur(ImgSource, ImgSource, Size(5,5), 1);
cvtColor(ImgSource, ImgGris, CV_BGR2GRAY);
//cvtColor(ImgSource, ImgDest, CV_RGB2GRAY);
//imshow("Img Destination 1", ImgGris);
//waitKey(0);

//threshold(ImgGris, ImgGris, 175, 255, CV_THRESH_BINARY_INV);
Canny(ImgGris, ImgCanny, 50,100);

imshow("Img Destination 1", ImgCanny);
imshow("Img Destination 1", ImgGris);
waitKey(0);

findContours(ImgCanny, Contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);

NbreObjetTrouve = Contours.size();

HoughCircles(ImgGris, Cercles, CV_HOUGH_GRADIENT, 2, 50, 100);
//Quelles sont les objets qui sont rectangulaires ?

for (int i = 0; i < Contours.size(); i++)
{
    for( size_t j = 0; j < Cercles.size(); j++ )
    {
        Point center(Cercles[j][0], Cercles[j][1]);
        int radius = Cercles[j][2];

        // circle center
        circle( ImgSource, center, 3, Scalar(0,255,0), -1, 8, 0 );

// circle outline circle( ImgSource, center, radius, Scalar(255,0,0), 3, 8, 0 );

    }
    imshow("Img Source", ImgSource);
    waitKey(0);

    cout << "Perimetre[" << i << "]: " << arcLength(Mat(Contours[i]),true) << endl;
    cout << "Aire[" << i << "]: " << contourArea(Mat(Contours[i])) << endl;
    //approxPolyDP(Mat(Contours[i]), PointApprox, 0.02, true);
    approxPolyDP(Mat(Contours[i]), PointApprox, arcLength(Mat(Contours[i]), true)*0.02, true);

    //Calcul du point milieu de chaque objet
    PointM = moments(Contours[i]);
    PointMilieu.x = PointM.m10/PointM.m00; //Calcul la coordonnée x
    PointMilieu.y = PointM.m01/PointM.m00; // Calcul la coordonnée y

    if (PointApprox.size() == 3)
    {
        cout << "Triangle" << endl;
        putText(ImgSource, "T", PointMilieu, CV_FONT_NORMAL, 1, Scalar(255,0,0), 2);
        imshow("Img Source", ImgSource);

    }
    else
    {
        if (PointApprox.size() == 4)
        {
            cout << "Rectangle" << endl;
            putText(ImgSource, "R", PointMilieu, CV_FONT_NORMAL, 1, Scalar(0,0,255), 2);
            imshow("Img Source", ImgSource);

        }
        else
        {
            putText(ImgSource, "A", PointMilieu, CV_FONT_NORMAL, 1, Scalar(0,0,255), 2);
            imshow("Img Source", ImgSource);

        }
    }
}

/*vector<vector<Point>>::iterator Iterateur = Contours.begin();

int i = 0;
while (Iterateur != Contours.end()) 
{
    NbrePointContours = Iterateur->size();
    cout << "Nbre de point de l'objet [" << i << "] : " << NbrePointContours << endl;
    Iterateur++;
    i++;

}*/


//threshold(ImgGris, ImgGris,127,255,CV_THRESH_BINARY_INV);

//imshow("Img Destination 1", ImgGris);
//waitKey(0);

/*for (int i = 0; i < 180; i+=10)
{
    inRange(ImgHSV, Scalar(i,0,0), Scalar(i+10,255,255), ImgGris);
    imshow("Img Destination ...
(more)
edit retag flag offensive close merge delete

Comments

1

please check, if the image was actually loaded:

if ( ImgSource.empty() ) cerr &lt;&lt; "empty image!" &lt;&lt; endl;
berak gravatar imageberak ( 2013-08-27 08:31:25 -0500 )edit

if ( ImgSource.empty() ) cout < "Fuck " << endl;

in debug mode, im going in this if

lolaalol gravatar imagelolaalol ( 2013-08-27 08:39:31 -0500 )edit

so, the usual : set the working dir in the debugger settings, or use an absolute path for imread ...

berak gravatar imageberak ( 2013-08-27 09:28:04 -0500 )edit

1 answer

Sort by » oldest newest most voted
0

answered 2013-08-27 08:30:21 -0500

Check two things:

  1. Are you using vc11? vc10 is only supported in visual studio 2010, which means that you should adapt your path variable and your project settings to include the correct directories for the lib and dll files.
  2. When you read in your image, you are using a relative path. Microsoft has a habbit of changing the working directory between versions. Make sure to start with an absolete path like C:/test_image.png.

Your error is basically pointing to the fact that you want to visualize a Mat object that doesn't exist so I am guessing it is the second problem.

edit flag offensive delete link more

Comments

im using the folder vc11, i tryed to use a absolete path like you : C:/cercles.jpg and i still get the error

lolaalol gravatar imagelolaalol ( 2013-08-27 08:40:52 -0500 )edit

did you change your project settings? and your path variable?

StevenPuttemans gravatar imageStevenPuttemans ( 2013-08-27 08:44:46 -0500 )edit

and make sure the file is actually there ... i know it sounds stupid but people have made this mistake before...

StevenPuttemans gravatar imageStevenPuttemans ( 2013-08-27 08:45:58 -0500 )edit

project setting ? if i linked all openCv include/lib to my project ? yes

path variable you are talking about the image or the environment path variable ? i have not changed the environment path ( can't not change it ), and yes the file is there.

lolaalol gravatar imagelolaalol ( 2013-08-27 08:49:06 -0500 )edit

Your system path variable should be changed to include the actuall dll path of openCV. It would have to have a directory like C:/OpenCV_installation/build/x64/vc11/bin/. If it doesn't then your system will never be able to find the corresponding dll files to your libs you have linked.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-08-27 08:57:05 -0500 )edit

In earlier version of OpenCv i never changed the system path to make it work.

lolaalol gravatar imagelolaalol ( 2013-08-27 09:03:34 -0500 )edit

Then the only way to make it work is to copy all dll files to your working directory, which is actualy stupid, because you will eventually need to do that for each pc you have. All the manuals out there tell you to alter the path variable, so I am not joking...

StevenPuttemans gravatar imageStevenPuttemans ( 2013-08-27 09:18:11 -0500 )edit
Login/Signup to Answer

Question Tools

Stats

Asked: 2013-08-27 08:21:46 -0500

Seen: 15,193 times

Last updated: Aug 27 '13