栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

鼠标回调测试

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

鼠标回调测试

import os
import cv2
import numpy as np


def getMousePos(leftimg,rightimg,disparity,cost):
    def onmouse(event, x, y, flags, param):
        cv2.imshow("img", left)
        # 双击左键,显示鼠标位置
        if event == cv2.EVENT_LBUTTONDBLCLK:
            cv2.circle(left, (x, y), 2, (0, 0, 255), -1)
            print(x,y) #x是列,y是行
            costimg = np.zeros([400, 64 * 5, 3], np.uint8)
            for i in range(64):
                cv2.circle(costimg,(i*5,(200-cost[y][x][i])),2,(0,0,255),-1)
            cv2.imshow("cost", costimg)
            if cv2.waitKey() & ord("d"):
                cv2.destroyWindow("cost")

    left = cv2.imread(leftimg)
    #right = cv2.imread(rightimg)
    #disp = cv2.imread(disparity)

    cv2.namedWindow('img')
    cost = np.zeros([240,320,64],np.uint16)
    with open("image/cost/1.txt") as file:
        content = file.read()
        temp = content.split(' ')
        for i in range(240):
            print(i)
            for j in range(320):
                for k in range(64):
                    cost[i][j][k] = int(temp[(i*240+j)*64+k])
    print("读取txt完毕")

    cv2.setMouseCallback("img", onmouse)

    if cv2.waitKey() & 0xFF == 27:  # 按下‘q'键,退出
        cv2.destroyAllWindows()

        return



if __name__ == '__main__':
    imgpath = "image"
    for f in os.listdir(imgpath+'/left'):
        leftimg = imgpath+"/left/"+f
        rightimg = imgpath+"/right/"+f
        disparity = imgpath+"/disp/"+f
        cost = imgpath+"/cost/"+ f.split(".")[0]+".txt"

        getMousePos(leftimg,rightimg,disparity,cost)
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/982052.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号