首页 > 编程知识 正文

python识别片坐标并点击,python获取指定区域的像素

时间:2023-05-03 13:23:55 阅读:228852 作者:1817

PYTHON CV2 图片中鼠标点击获取像素点坐标

# -*- coding: utf-8 -*-"""@File : get_actual_depth.py@Time : 2020/11/10 15:22@Author : Dontla@Email : sxana@qq.com@Software: PyCharm"""import cv2import numpy as npcount = 15path = './capture_depth_color_data/2020-11-6_14-56-19/'def get_actual_depth(count): depth_img = np.load('{}{}.npy'.format(path, count)) # 图片路径 img = cv2.imread('{}{}.jpg'.format(path, count)) flag = False a = [] b = [] def on_EVENT_LBUTTONDOWN(event, x, y, flags, param): if event == cv2.EVENT_LBUTTONDOWN: xy = "%d,%d" % (x, y) a.append(x) b.append(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, 0), thickness=1) cv2.imshow("{}.jpg".format(count), img) # print(x, y) print(a[0], b[0]) print(depth_img[b[0], a[0]]) while True: cv2.namedWindow("{}.jpg".format(count), cv2.WINDOW_NORMAL) cv2.setWindowProperty("{}.jpg".format(count), cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN) cv2.setMouseCallback("{}.jpg".format(count), on_EVENT_LBUTTONDOWN) cv2.imshow("{}.jpg".format(count), img) cv2.waitKey(0) if len(a) > 0: if depth_img[b[0], a[0]] > 0: actual_depth = depth_img[b[0], a[0]] # print(actual_depth) break else: a = [] b = [] np.save('{}{}_actual_depth.npy'.format(path, count), actual_depth) # a = np.load('{}{}_actual_depth.npy'.format(path, count))while True: get_actual_depth(count) count += 1

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。