uso OpenCv para encontrar un área que coincida con una plantilla en una imagen de referencia. Cuando el código de encontrar a la bruja zona coinciden con una plantilla dibujar un rectángulo alrededor de la zona, pero lo que quiero es cuando el código doesnt encontrar el área del código duerma dibujar cualquier rectánguloOpenCV. Dibujo de rectángulo al hacer coincidir
código:
IplImage *res;
CvPoint minloc, maxloc;
double minval, maxval;
int img_width, img_height;
int tpl_width, tpl_height;
int res_width, res_height;
NSString *path = [[NSBundle mainBundle] pathForResource:@"reference" ofType:@"jpg"];
reference.image = [UIImage imageWithContentsOfFile:path];
NSString *pathPatron = [[NSBundle mainBundle] pathForResource:@"template" ofType:@"jpg"];
template.image = [UIImage imageWithContentsOfFile:pathPatron];
IplImage *img = [self CreateIplImageFromUIImage:original.image];//
IplImage *tpl = [self CreateIplImageFromUIImage:patron.image];
img_width = img->width;
img_height = img->height;
tpl_width = tpl->width;
tpl_height = tpl->height;
res_width = img_width - tpl_width + 1;
res_height = img_height - tpl_height + 1;
res = cvCreateImage(cvSize(res_width, res_height), IPL_DEPTH_32F, 1);
/* choose template matching method to be used */
cvMatchTemplate(img, tpl, res, CV_TM_SQDIFF);
cvMinMaxLoc(res, &minval, &maxval, &minloc, &maxloc, 0);
/* draw red rectangle */
cvRectangle(img,
cvPoint(minloc.x, minloc.y),
cvPoint(minloc.x + tpl_width, minloc.y + tpl_height),
cvScalar(0, 0, 255, 0), 1, 0, 0);
/* display images */
reference.image = [self UIImageFromIplImage:img];
cvReleaseImage(&img);
cvReleaseImage(&tpl);
cvReleaseImage(&res);
Gracias de antemano
ok muchas gracias – josiland
@josiland qué cambios haces .pLease publicar eso también. – Gypsa