python如何获取鼠标点击图片的像素点坐标
发布日期:2021-05-10 09:15:15 浏览次数:24 分类:精选文章

本文共 1671 字,大约阅读时间需要 5 分钟。

# -*- 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

在这里插入图片描述

在这里插入图片描述

上一篇:如何遍历numpy数组?
下一篇:python 如何通过time.time() time.localtime()获取结构化的年月日时分秒?

发表评论

最新留言

哈哈,博客排版真的漂亮呢~
[***.90.31.176]2025年04月15日 00时14分03秒