1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
IplImage* hough = cvCreateImage(cvGetSize(msk),IPL_DEPTH_8U,1); // initialisation de l'image où afficher les lignes
cvZero(hough); // initialisation image en noir
CvMat* storage = cvCreateMat(1,5,CV_32FC2); // création d'une matrice de stockage avec 1ligne,5colonnes pour n'avoir que les 5plus longues lignes de l'image
// Le type CV_32FC2 est obligatoire pour la matrice
CvSeq* lines = 0; // initialisation de la séquence de ligne
// lancement du calcul des lignes avec threshold=10
lines = cvHoughLines2(skel,stor,CV_HOUGH_STANDARD,1,CV_PI/180,10);
for(int i = 0; i < lines->total; i++) { // on parcours toutes les lignes pour les afficher
float* line = (float*)cvGetSeqElem(lines,i);
float rho = line[0];
float theta = line[1];
CvPoint pt1, pt2;
double a = cos(theta), b = sin(theta);
double x0 = a*rho, y0 = b*rho;
pt1.x = cvRound(x0 + 1000*(-b));
pt1.y = cvRound(y0 + 1000*(a));
pt2.x = cvRound(x0 - 1000*(-b));
pt2.y = cvRound(y0 - 1000*(a));
cvLine(hough,pt1,pt2,CV_SCALAR_BLANC,1,8);
} |
Partager