transportation informatics group university of klagenfurt matching.pdf · 2009. 12. 24. ·...
TRANSCRIPT
-
Transportation Informatics Group, ALPEN-ADRIA University of Klagenfurt
Machine VisionMachine VisionTransportation Informatics Group
University of Klagenfurt
Alireza Fasih, 2009
12/24/2009 1Address: L4.2.02, Lakeside Park, Haus B04, Ebene 2, Klagenfurt-Austria
-
T l t M t hi
Transportation Informatics Group, ALPEN-ADRIA University of Klagenfurt
Template Matching2D Shape Based Matching2D Shape Based Matching
12/24/2009 2Gray Level Correlation-Based Matching
-
T l t M t hi
Transportation Informatics Group, ALPEN-ADRIA University of Klagenfurt
Template Matching
If t d d d i ti f th t l t i d t thIf standard deviation of the template image compared to the source image is small enough, template matching may be used.Templates are most often used to identify printed characters, n mbers and other small simple objectsnumbers, and other small, simple objects.
12/24/2009 3
-
Method
Transportation Informatics Group, ALPEN-ADRIA University of Klagenfurt
Method
x,yI(x,y) O(x,y)
x,yCorrelation
Template Image
Input Image Output Image
The matching process moves the template image to all possible positions in a larger source image and computes a numerical index that indicates how well the template matches the image in that p gposition.
Match is done on a pixel-by-pixel basis.
12/24/2009 4
-
Template Correlation
Transportation Informatics Group, ALPEN-ADRIA University of Klagenfurt
Template Correlation
RowT ColT
∑ ∑= =
++=RowT
i
ColT
jjipixleSjyixpixleTdiffyxSAD
.
0
.
0)),(.),,(.(),(
RowS ColS. .
∑ ∑= =
=x y
yxSADyxres0 0
),(),(
ySum of Absolute Difference
x
∑ ∑RowS ColS
SADW. .
)()( ∑ ∑= =
=x y
yxSADyxW0 0
),(),(
12/24/2009 5
-
T l t M t hi i O CV
Transportation Informatics Group, ALPEN-ADRIA University of Klagenfurt
Template Matching in OpenCV
• Template Matching Procedure– Loading the Search Image
Loading the Template Image– Loading the Template Image– Making a Result Image– Calling the Template Matching Functiong p g– Finding the Minimum Value in Result Image– Drawing a Rectangle
12/24/2009 6
-
Template Matching in OpenCV
Transportation Informatics Group, ALPEN-ADRIA University of Klagenfurt
Template Matching in OpenCV/* load reference image */img = cvLoadImage( "c:\\image1 bmp" CV LOAD IMAGE COLOR );img = cvLoadImage( c:\\image1.bmp , CV_LOAD_IMAGE_COLOR );
/* load template image */tpl = cvLoadImage( "c:\\tmp1.bmp", CV_LOAD_IMAGE_COLOR );
/* t i ' ti *//* get image's properties */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;
/* create new image for template matching computation */res = cvCreateImage( cvSize( res width res height ) IPL DEPTH 32F 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 );
c MinMa Loc( res &min al &ma al &minloc &ma loc 0 )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 ),
12/24/2009 7
cvScalar( 0, 0, 255, 0 ), 1, 0, 0 );
-
A ti d Li it ti
Transportation Informatics Group, ALPEN-ADRIA University of Klagenfurt
Assumptions and Limitations1. Template is completely located in source image1. Template is completely located in source image2. Partial template matching was not performed (at boundaries, within image)3. Rotation and scaling will cause poor matches
TemplateData Set 1 Data Set 2
12/24/2009 8Data Set 3 Data Set 4 Data Set 5
-
D t S t 1
Transportation Informatics Group, ALPEN-ADRIA University of Klagenfurt
Data Set 1
Correlation Map with Peak Source Image, Found Correlation Map with Peak gRectangle, and Correlation Map
12/24/2009 9
-
D t S t 2
Transportation Informatics Group, ALPEN-ADRIA University of Klagenfurt
Data Set 2
Correlation Map with Peak Source Image and Found Rectangle
12/24/2009 10
-
D t S t 3
Transportation Informatics Group, ALPEN-ADRIA University of Klagenfurt
Data Set 3
Correlation Map with Peak Source Image and Found Rectangle
12/24/2009 11
-
D t S t 4
Transportation Informatics Group, ALPEN-ADRIA University of Klagenfurt
Data Set 4
Source Image and FoundCorrelation Map with Peak Source Image and Found Rectangle
12/24/2009 12
-
D t S t 5
Transportation Informatics Group, ALPEN-ADRIA University of Klagenfurt
Data Set 5
Correlation Map with Peak Source Image
12/24/2009 13
-
D t S t 5 R lt
Transportation Informatics Group, ALPEN-ADRIA University of Klagenfurt
Data Set 5, Result
Threshold set to 0.800 Threshold set to 0.200
12/24/2009 14
-
Transportation Informatics Group, ALPEN-ADRIA University of Klagenfurt
Th k f iThank you for your attention
12/24/2009 15