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 1", ImgGris);
cout << "Hue intervalle : " << i << " a " << i + 10 << endl;
waitKey(500);
}
//inRange(ImgHSV, Scalar(25,0,0), Scalar(35,255,255), ImgDest);
//imshow("Img Destination 1", ImgDest);
waitKey(0);
*/
return 0;
}