Skip to content

Commit

Permalink
feat: add four point selector for image transformation
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsukiKigoshi committed Aug 15, 2024
1 parent 557cce4 commit 43c362b
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/four_points_selector.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from transform import four_point_transform
import cv2
import numpy as np

# Output: coordinates of four points as np.array
def four_point_selector(img):
# four points in python array
pts=[]
def click_event(event, x, y, flags, params):
# checking for left mouse clicks
if event == cv2.EVENT_LBUTTONDOWN:
pts.append([x, y])
# displaying the coordinates
# on the image window
font = cv2.FONT_HERSHEY_SIMPLEX
cv2.putText(img, str(x) + ',' + str(y), (x,y), font, 1, (255, 0, 0), 2)
cv2.circle(img, (x,y), 6, (0, 0, 255), 2)
cv2.imshow('image', img)


# displaying the image
cv2.imshow('image', img)

# setting mouse handler for the image
# and calling the click_event() function
cv2.setMouseCallback('image', click_event)

# wait for a key to be pressed to exit
cv2.waitKey(0)

cv2.destroyAllWindows
return np.array(pts)

img = cv2.imread('public/sample-desktop-1.jpg', 1)
print(four_point_selector(img))

0 comments on commit 43c362b

Please sign in to comment.