@@ -5,10 +5,10 @@ def select_roi (event,x,y,flags,param):
5
5
global refpt #Global refrences
6
6
7
7
if event == cv2 .EVENT_LBUTTONDOWN : # When the left mouse button is cliked
8
- refpt = [(x , y )]
8
+ refpt = [(x , y )]
9
9
10
10
elif event == cv2 .EVENT_LBUTTONUP : # When the left mouse button is released
11
- refpt .append ((x , y )) # recording the last coordinates
11
+ refpt .append ((x , y )) # recording the last coordinates
12
12
cv2 .rectangle (img_main ,refpt [0 ],refpt [1 ],(0 ,255 ,0 ),2 )
13
13
cv2 .imshow ("frame" ,img_main )
14
14
print ("Selection Successful" )
@@ -22,7 +22,7 @@ def select_roi (event,x,y,flags,param):
22
22
cv2 .namedWindow ("frame" )
23
23
cv2 .setMouseCallback ("frame" ,select_roi )
24
24
25
- i = 1 # Numbering for saving images
25
+ i = 1 # Numbering for saving images
26
26
27
27
while True :
28
28
cv2 .imshow ("frame" ,img_main )
@@ -32,8 +32,8 @@ def select_roi (event,x,y,flags,param):
32
32
33
33
if var == ord ('c' ): # Crop selected images
34
34
35
- if len (refpt )== 2 :
36
- roi = clone2 [refpt [0 ][1 ]: refpt [1 ][1 ], refpt [0 ][0 ]: refpt [1 ][0 ]] # [x1:x2 , y1:y2]
35
+ if len (refpt ) == 2 :
36
+ roi = clone2 [ refpt [0 ][1 ] : refpt [1 ][1 ] , refpt [0 ][0 ] : refpt [1 ][0 ] ] # [x1:x2 , y1:y2]
37
37
cv2 .namedWindow ("Crop" )
38
38
cv2 .imshow ("Crop" ,roi )
39
39
print ("Cropped" )
@@ -42,7 +42,7 @@ def select_roi (event,x,y,flags,param):
42
42
43
43
if var2 == ord ('s' ): # Saving cropped image
44
44
cv2 .imwrite ("Data/cropped image{}.png" .format (i ),roi )
45
- i = i + 1
45
+ i = i + 1
46
46
print ("image saved\n " )
47
47
cv2 .destroyWindow ("Crop" )
48
48
img_main = clone .copy ()
0 commit comments