66window .title ("Matching shapes" )
77window .geometry ('350x200' )
88
9- def image1 (): # getting image 1
9+
10+ def image1 (): # getting image 1
1011 photo1 = askopenfilename ()
1112 global gray1
1213 img1 = cv2 .imread (photo1 )
13- img1 = cv2 .resize (img1 ,(500 ,500 ))
14+ img1 = cv2 .resize (img1 , (500 , 500 ))
1415 gray1 = cv2 .cvtColor (img1 , cv2 .COLOR_RGB2GRAY )
15-
1616
17- def image2 (): # getting image 2
17+
18+ def image2 (): # getting image 2
1819 photo2 = askopenfilename ()
1920 global gray2
2021 img2 = cv2 .imread (photo2 )
21- img2 = cv2 .resize (img2 ,(500 ,500 ))
22+ img2 = cv2 .resize (img2 , (500 , 500 ))
2223 gray2 = cv2 .cvtColor (img2 , cv2 .COLOR_RGB2GRAY )
23-
2424
25- def proceeds (): # detecting shape matching using contours
25+
26+ def proceeds (): # detecting shape matching using contours
2627 ret , threshold = cv2 .threshold (gray1 , 127 , 255 , 0 )
2728 ret , threshold2 = cv2 .threshold (gray2 , 127 , 255 , 0 )
2829 contours , hierarchy , rem1 = cv2 .findContours (threshold , 2 , 1 )
@@ -31,7 +32,9 @@ def proceeds(): # detecting shape matching using contours
3132 cnt2 = contours [0 ]
3233 ret = cv2 .matchShapes (cnt1 , cnt2 , 1 , 0.0 )
3334 print (ret )
34- label = tk .Label (window , text = "Probability of shapes matching: " + str (1 - ret )).grid (row = 4 ,column = 1 )
35+ label = tk .Label (window , text = "Probability of shapes matching: " +
36+ str (1 - ret )).grid (row = 4 , column = 1 )
37+
3538
3639label = tk .Label (window , text = "Image 1" ).grid (row = 1 , column = 0 )
3740label = tk .Label (window , text = "Image 2" ).grid (row = 2 , column = 0 )
@@ -40,9 +43,9 @@ def proceeds(): # detecting shape matching using contours
4043b2 = tk .Button (window , text = 'choose image 2' , command = image2 )
4144proceed = tk .Button (window , text = 'Proceed' , command = proceeds )
4245
43- b1 .grid (row = 1 ,column = 1 )
44- b2 .grid (row = 2 ,column = 1 )
45- proceed .grid (row = 3 ,column = 1 )
46+ b1 .grid (row = 1 , column = 1 )
47+ b2 .grid (row = 2 , column = 1 )
48+ proceed .grid (row = 3 , column = 1 )
4649
4750window .mainloop ()
4851cv2 .destroyAllWindows ()
0 commit comments