Projet

Général

Profil

Feature #8914 » main.cpp

Anonyme, 19/11/2017 15:57

 
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <stdio.h>

using namespace cv;
using namespace std;

int main()
{
Mat image, gray, traitement;

string nom;
cout << "Ecrivez le nom de l'image : template.png\n ";
cin >> nom;


image = imread( nom, 1 );

if (image.empty())
{
cout << "Image cannot be loaded..!!" << endl;
return -1;
}

cvtColor( image, traitement, CV_BGR2HSV);

//permet de s?lectionner la couleur verte
inRange(traitement, Scalar(40, 90, 0), Scalar(70, 255, 255), gray);
GaussianBlur( gray, gray, Size(7, 7), 0, 0 );

//permet de detecter les contours
Mat thresh;
threshold( gray, thresh, 127, 255, 0);
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
findContours( thresh, contours, hierarchy, RETR_TREE, CHAIN_APPROX_SIMPLE);

//permet de dessiner les contours
int idx = 0;
for( ; idx >= 0; idx = hierarchy[idx][0] )
{
drawContours( image, contours, idx, Scalar(0,255,0), 9, 8, hierarchy );
}


// affiche le r?sultat
namedWindow( "Detection", CV_WINDOW_AUTOSIZE );
imshow( "Detection", image);

// cree une image resultat
imwrite( "resultat.png", image);

waitKey(0);
return 0;
}






(2-2/3)