Skip to content
This repository was archived by the owner on Nov 30, 2022. It is now read-only.

Commit b6e8c14

Browse files
Updated crop.py
1 parent b4ee208 commit b6e8c14

File tree

1 file changed

+6
-6
lines changed
  • Image-Processing/ImageCropper

1 file changed

+6
-6
lines changed

Image-Processing/ImageCropper/crop.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ def select_roi (event,x,y,flags,param):
55
global refpt #Global refrences
66

77
if event == cv2.EVENT_LBUTTONDOWN: # When the left mouse button is cliked
8-
refpt = [(x,y)]
8+
refpt = [(x , y)]
99

1010
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
1212
cv2.rectangle(img_main,refpt[0],refpt[1],(0,255,0),2)
1313
cv2.imshow("frame",img_main)
1414
print("Selection Successful")
@@ -22,7 +22,7 @@ def select_roi (event,x,y,flags,param):
2222
cv2.namedWindow("frame")
2323
cv2.setMouseCallback("frame",select_roi)
2424

25-
i=1 # Numbering for saving images
25+
i = 1 # Numbering for saving images
2626

2727
while True:
2828
cv2.imshow("frame",img_main)
@@ -32,8 +32,8 @@ def select_roi (event,x,y,flags,param):
3232

3333
if var == ord('c'): # Crop selected images
3434

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]
3737
cv2.namedWindow("Crop")
3838
cv2.imshow("Crop",roi)
3939
print("Cropped")
@@ -42,7 +42,7 @@ def select_roi (event,x,y,flags,param):
4242

4343
if var2 == ord('s'): # Saving cropped image
4444
cv2.imwrite("Data/cropped image{}.png".format(i),roi)
45-
i=i+1
45+
i = i+1
4646
print("image saved\n")
4747
cv2.destroyWindow("Crop")
4848
img_main = clone.copy()

0 commit comments

Comments
 (0)