opencv 人工标记图片像素点

在某些时候,对于图片像处理任务需要人工标记。通过该例子功能:鼠标点击后,生成坐标位置可打印到控制台供后续使用。比较方便。

import cv2
import numpy as np

# 全局变量
points = []
image = None

def click_event(event, x, y, flags, param):
    global points, image
    if event == cv2.EVENT_LBUTTONDOWN:
        points.append((x, y))
        cv2.circle(image, (x, y), 5, (0, 0, 255), -1)
        cv2.imshow('image', image)
        print(f"Point marked at: ({x}, {y})")

def main(image_path):
    global image
    image = cv2.imread(image_path)
    # 调整图像大小   (不经过此步骤都是原图)
    # width1, height1 = 2300, 1500
    # image = cv2.resize(image, (width1, height1))
    cv2.imshow('image', image)
    cv2.setMouseCallback('image', click_event)

    print("Click on the corners of the grid. Press 'q' to quit and save points.")
    while True:
        key = cv2.waitKey(1) & 0xFF
        if key == ord('q'):
            break

    cv2.destroyAllWindows()
    print("Marked points:", points)

    # Save points to file or use directly in your script
    with open("marked_points.txt", "w") as file:
        for point in points:
            file.write(f"{point[0]}, {point[1]}\n")

if __name__ == "__main__":
    main(r'F:\answerSheetJudging\anwser\de_343_erwei(1).png')
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值