查看图片中某点的坐标,代码如下:
def on_mouse(event, x, y, flags, param):
if event == cv.EVENT_LBUTTONDOWN:
print(f'x: {x}, y: {y}')
cv.setMouseCallback("img", on_mouse)
根据坐标点在图片上画矩形
import cv2 as cv
img = cv.imread("D:\\practice\\wuliumen\\datasets\\images\\1.jpg")
cv.namedWindow("img",cv.WINDOW_NORMAL)
width = img.shape[1]
print(width)
height = img.shape[0]
print(height)
cv.resizeWindow("img",(int(width/2),int(height/2)))
cv.rectangle(img,(438,354),(920,446),(0,0,255),3)
#cv.rectangle(img,(436,354),(478,424),(0,0,255),3)
cv.imshow("img",img)
cv.imwrite("new_2.jpg",img)
cv.waitKey(0)
cv.destroyAllWindows()
备注:如果要查看图片中某个点的坐标,可以再cv2.imshow之前添加代码