乒乓女孩 2021-07-22 15:25 采纳率: 100%
浏览 422
已采纳

python在多线程用cv2的imshow显示不出窗口的问题

代码如下,运行之后第一次可以显示图片,关闭之后再打开就显示不了了,但从打印信息来看是可以运行显示的线程的


import cv2
import numpy as np
import threading
from easygui import *
img1 = cv2.imread('01.png')
img2 = cv2.imread('02.png')
img_show=[True]
def img1_method():
    print('打开img1')
    while img_show[0]:
       cv2.imshow("img1",img1)
       cv2.waitKey(5)
    print('关闭img1')
def img2_method():
    print('打开img2')
    while img_show[0]:
       cv2.imshow("img2",img2)
       cv2.waitKey(5)
    print('关闭img2')
def open_close():
    while True:
        choices = ['[1]打开', '[2]关闭', '[3]退出']
        choice=buttonbox(msg='请选择', title='cv2测试', choices=choices,
                  default_choice=choices[2], cancel_choice=choices[2], callback=None, run=True)
        choose=choices.index(choice)+1
        if choose==1:
            img_show[0]=True
            threading.Thread(target=img1_method).start()
            threading.Thread(target=img2_method).start()
        elif choose==2:
            img_show[0]=False
        else:
            break

threading.Thread(target=img1_method).start()
threading.Thread(target=img2_method).start()
threading.Thread(target=open_close).start()
  • 写回答

1条回答 默认 最新

  • 乒乓女孩 2021-07-22 16:17
    关注

    已解决

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 已采纳回答 7月22日
  • 创建了问题 7月22日

悬赏问题

  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?