python opencv 显示文件夹下的图像(文件夹下还有文件夹),并把鼠标点击的坐标,储存到txt

import cv2
import os

def on_EVENT_LBUTTONDOWN(event, x, y, flags, param):

if event == cv2.EVENT_LBUTTONDOWN:
    xy = "%d,%d" % (x, y)
    info = '{}, {}, {}'.format(path, x, y)
    with open('./data/loc.txt', 'a') as f:
        f.write(info + "\n")
    cv2.circle(img, (x, y), 1, (255, 0, 0), thickness=-1)
    cv2.putText(img, xy, (x, y), cv2.FONT_HERSHEY_PLAIN,
                1.0, (0, 0, 0), thickness=1)
    cv2.imshow("image", img)

data_path = ‘./data/hand_pose_test’
signal = os.listdir(data_path)
for fsingal in signal:
filepath = data_path + ‘/’ + fsingal
filename = os.listdir(filepath)
for fname in filename:
ffpath = filepath + “/” + fname
path = ffpath
print(path)
im_gray = cv2.imread(path, cv2.IMREAD_GRAYSCALE)
im_gray = im_gray * 16
im_color = cv2.applyColorMap(im_gray, cv2.COLORMAP_JET)
img = im_color

    cv2.namedWindow("image", 0)
    cv2.resizeWindow('image', 1024, 848)
    loc = cv2.setMouseCallback("image", on_EVENT_LBUTTONDOWN)
    cv2.imshow("image", img)
    cv2.waitKey(0)
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值