6
6
window .title ("Matching shapes" )
7
7
window .geometry ('350x200' )
8
8
9
- def image1 (): # getting image 1
9
+
10
+ def image1 (): # getting image 1
10
11
photo1 = askopenfilename ()
11
12
global gray1
12
13
img1 = cv2 .imread (photo1 )
13
- img1 = cv2 .resize (img1 ,(500 ,500 ))
14
+ img1 = cv2 .resize (img1 , (500 , 500 ))
14
15
gray1 = cv2 .cvtColor (img1 , cv2 .COLOR_RGB2GRAY )
15
-
16
16
17
- def image2 (): # getting image 2
17
+
18
+ def image2 (): # getting image 2
18
19
photo2 = askopenfilename ()
19
20
global gray2
20
21
img2 = cv2 .imread (photo2 )
21
- img2 = cv2 .resize (img2 ,(500 ,500 ))
22
+ img2 = cv2 .resize (img2 , (500 , 500 ))
22
23
gray2 = cv2 .cvtColor (img2 , cv2 .COLOR_RGB2GRAY )
23
-
24
24
25
- def proceeds (): # detecting shape matching using contours
25
+
26
+ def proceeds (): # detecting shape matching using contours
26
27
ret , threshold = cv2 .threshold (gray1 , 127 , 255 , 0 )
27
28
ret , threshold2 = cv2 .threshold (gray2 , 127 , 255 , 0 )
28
29
contours , hierarchy , rem1 = cv2 .findContours (threshold , 2 , 1 )
@@ -31,7 +32,9 @@ def proceeds(): # detecting shape matching using contours
31
32
cnt2 = contours [0 ]
32
33
ret = cv2 .matchShapes (cnt1 , cnt2 , 1 , 0.0 )
33
34
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
+
35
38
36
39
label = tk .Label (window , text = "Image 1" ).grid (row = 1 , column = 0 )
37
40
label = tk .Label (window , text = "Image 2" ).grid (row = 2 , column = 0 )
@@ -40,9 +43,9 @@ def proceeds(): # detecting shape matching using contours
40
43
b2 = tk .Button (window , text = 'choose image 2' , command = image2 )
41
44
proceed = tk .Button (window , text = 'Proceed' , command = proceeds )
42
45
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 )
46
49
47
50
window .mainloop ()
48
51
cv2 .destroyAllWindows ()
0 commit comments