天天看點

matlab 求圖檔中心坐标點_OpenCV-python 4.2互動圖檔擷取滑鼠單擊坐标點

import cv2


def mouse(event, x, y, flags, param):
    if event == cv2.EVENT_LBUTTONDOWN:
        xy = "%d,%d" % (x, y)
        cv2.circle(img, (x, y), 1, (0, 0, 255), thickness = -1)
        cv2.putText(img, xy, (x, y), cv2.FONT_HERSHEY_PLAIN,
                    1.0, (0, 0, 255), thickness = 1)
        cv2.imshow("image", img)

img = cv2.imread("test_book.jpg")
cv2.namedWindow("image")
cv2.imshow("image", img)
row,col,chanel = img.shape

cv2.resizeWindow("image", 800, 600)
cv2.setMouseCallback("image", mouse)

k = cv2.waitKey(0)
if k == 27:
    cv2.destroyAllWindows()
           
matlab 求圖檔中心坐标點_OpenCV-python 4.2互動圖檔擷取滑鼠單擊坐标點