From 43c362b2f0d8a144a6126bebc988156c01285e6b Mon Sep 17 00:00:00 2001 From: ItsukiKigoshi Date: Thu, 15 Aug 2024 16:09:43 +0900 Subject: [PATCH] feat: add four point selector for image transformation --- src/four_points_selector.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/four_points_selector.py diff --git a/src/four_points_selector.py b/src/four_points_selector.py new file mode 100644 index 0000000..09aef6d --- /dev/null +++ b/src/four_points_selector.py @@ -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)) \ No newline at end of file