ruijiege

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
import cv2

dx0 = 0
dy0 = 0
isdown = False

def callback(event, x, y, flags, userdata):
    global dx0,dy0,isdown
    color = 0, 255, 0
    if flags & cv2.EVENT_FLAG_CTRLKEY:
        color = 255, 0, 0
    elif flags & cv2.EVENT_FLAG_SHIFTKEY:
        color = 0, 0, 255
    elif flags & cv2.EVENT_FLAG_ALTKEY:
        color = 128, 255, 50
    if event == cv2.EVENT_LBUTTONDOWN:
        dx0 = x
        dy0 = y
        isdown = True
    if event == cv2.EVENT_LBUTTONUP:
        isdown = False
        cv2.rectangle(userdata, (dx0, dy0), (x, y), (0, 255, 0), 2)
    if event == cv2.EVENT_MOUSEMOVE:
        if isdown:
            temp = userdata.copy()
            cv2.rectangle(temp,(dx0,dy0),(x,y),color,2)
            cv2.imshow("image",temp)

image = cv2.imread("x.jpg")
cv2.namedWindow("image", cv2.WINDOW_FREERATIO)
cv2.setMouseCallback("image", callback,image)
cv2.imshow("image", image)
while True:
    k = cv2.waitKey()
    if k == ord('q'):
        break
cv2.destroyAllWindows()
View Code

 

 这样的图片标注

posted on 2022-10-25 10:59  哦哟这个怎么搞  阅读(30)  评论(0编辑  收藏  举报