Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

#include<opencv2/opencv.

hpp>
#include <opencv2/highgui/highgui.hpp>
#include<iostream>
#define MAX 500
CvPoint2D32f corners[MAX];
CvPoint2D32f corners2[MAX];

int main()

{
int i, corner_count = 150, corner_count2 = 150;
double th1 = 50, th2 = 200;
CvMemStorage *storage = cvCreateMemStorage(0);
CvSeq *lines = 0;

IplImage *img, *mono, *dst, *src3, *img2;


IplImage *eig_tmp, *temp_img;
IplImage *color_dst;

img = cvLoadImage("juliIzq08.jpg");

mono = cvCreateImage(cvSize(img->width, img->height), 8, 1);


cvCvtColor(img, mono, CV_BGR2GRAY);
//cvNamedWindow("ventana1");
//cvShowImage("ventana1", mono);

src3 = cvCreateImage(cvSize(img->width, img->height), 8, 1);


cvCanny(mono, src3, th1, th2, 3);
cvNamedWindow("ventana1");
cvShowImage("ventana1", src3);

dst = cvCreateImage(cvSize(img->width, img->height), IPL_DEPTH_32F, 1);


cvCornerHarris(mono, dst, 7, 7, 0.04);
cvNamedWindow("ventana2");
cvShowImage("ventana2", dst);

img2 = cvCloneImage(img);
eig_tmp = cvCreateImage(cvSize(img->width, img->height), IPL_DEPTH_32F, 1);
temp_img = cvCreateImage(cvSize(img->width, img->height), IPL_DEPTH_32F, 1);
cvGoodFeaturesToTrack(mono, eig_tmp, temp_img, corners, &corner_count, 0.1,
15);
printf("MinEigenVal corner count=%d\n", corner_count);
for (i = 0; i < corner_count; i++)
cvCircle(img, cvPointFrom32f(corners[i]), 3, CV_RGB(255, 0, 0), 2, 8,
0);
cvNamedWindow("ventana3", CV_WINDOW_AUTOSIZE);
cvShowImage("ventana3", img);

cvFindChessboardCorners(img2, cvSize(7, 7), corners2, &corner_count2,


CV_CALIB_CB_ADAPTIVE_THRESH);
printf("puntos findchess %d \n", corner_count2);
for (i = 0; i < corner_count2; i++)
printf("%.2f %.2f \n", corners2[i].x, corners[i].y);
cvDrawChessboardCorners(img2, cvSize(7, 7), corners2, corner_count2, 1);
cvNamedWindow("ventana4");
cvShowImage("ventana4", img2);

color_dst = cvCreateImage(CvSize(img->width, img->height), 8, 3);


cvCvtColor(src3, color_dst, CV_GRAY2BGR);
lines = cvHoughLines2(src3, storage, CV_HOUGH_STANDARD, 1, CV_PI / 100, 100,
0, 0);
for (i = 0; i < MIN(lines->total, 100); i++)
{
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(color_dst, pt1, pt2, CV_RGB(255, 0, 0), 1, CV_AA, 0);
}
cvNamedWindow("ventana5", 1);
cvShowImage("ventana5", color_dst);
cvWaitKey(0);
cvReleaseImage(&img);
}

You might also like