69 MatchBase(
const char *targetName,
const char *fileName)
74 target = cvLoadImage(fileName, CV_LOAD_IMAGE_UNCHANGED);
78 MatchBase(
const char *targetName,
const char *fileName,
79 int posX,
int posY,
int sizeX,
int sizeY)
84 IplImage *container = cvLoadImage(fileName, CV_LOAD_IMAGE_UNCHANGED);
88 cvGetSubRect(container, &roi, cvRect(posX,posY,sizeX,sizeY));
90 target = cvCreateImage(cvSize(sizeX, sizeY), container->depth, container->nChannels);
94 cvReleaseImage(&container);
101 virtual void Match(
const IplImage *src) =0;
140 MatchImage(
const char *targetName,
const char *fileName,
double t=0.995)
145 int posX,
int posY,
int sizeX,
int sizeY,
double t=0.995)
155 MHDBGMSG(__FILE__,__LINE__,__PRETTY_FUNCTION__);
163 MHDBGMSG(__FILE__,__LINE__,__PRETTY_FUNCTION__);
167 cvMatchTemplate(src,
target,
result, CV_TM_CCORR_NORMED);
169 MHDBGMSG(__FILE__,__LINE__,__PRETTY_FUNCTION__);
171 for (
int x=0;x<
result->width;x++) {
172 for (
int y=0;y<
result->height;y++) {
179 MHDBGMSG(__FILE__,__LINE__,__PRETTY_FUNCTION__);
201 class BGMatchers :
public std::vector<GCPointer<MatchImage> > {
202 #define NUM_THREADS 2
206 const std::vector<GCPointer<MatchImage> > *
matchers;
216 for (const_iterator i=_this->
matchers->begin();
233 WaitForMultipleObjects(NUM_THREADS,
threadIds, TRUE, INFINITE);
243 for (
unsigned int i=0;i<size(); i++) {
292 CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0));
298 storage = cvCreateMemStorage(0);
313 cannySrc = cvCreateImage(cvGetSize(src), IPL_DEPTH_8U, 1);
315 forDisplay = cvCreateImage(cvGetSize(src), IPL_DEPTH_8U, 3);
325 CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0));
330 for ( ; contours!=0; contours = contours->h_next) {
334 double curResult = cvMatchShapes(contours,
trgtContour, CV_CONTOURS_MATCH_I1);
335 if (curResult>0.0 && curResult<
result)
result=curResult;
338 std::cout <<
"contours: "
339 << contours->total <<
" "
344 double normedRes = (curResult - .2) / .2;
346 normedRes = min(max(normedRes, -1.0), 1.0);
348 normedRes = std::min(std::max(normedRes, -1.0), 1.0);
350 CvScalar color = CV_RGB(127+127*normedRes, 127+127*normedRes, 127-127*normedRes);
352 if (curResult < .4) {
354 cvDrawContours((CvArr*)
forDisplay, contours, color, color, -1, 1 , 8);
363 std::cout <<
"cvMatchShapes: " <<
result << std::endl;