opencv-python,在线程里imshow图片QObject::killTimer: Timers cannot be stopped from another thread QObject::

硬件与环境

相机:realsense
系统:ubuntu 22.04
opencv版本:4.9.0.80

最小化代码示例:

class opencv_imshow_test(Node):
    def __init__(self):
        self.viz_thread = Thread(target=self.visulize)
        self.viz_thread.start()
        self.connect_camera()  
        self.camera_rgb = img # 这里是一张图片
        self.head_camera = Realsense_camera()
 	def visulize(self): 
        while True:
            self.camera_rgb,d,K = self.head_camera.get_one_frame()
            if self.camera_rgb is not None:
                cv2.imshow('rgb',self.camera_rgb)          
            cv2.waitKey(100)

报错

QObject::killTimer: Timers cannot be stopped from another thread
QObject::startTimer: Timers cannot be started from another thread

原因,目前查不到

解决办法

调整显示图片线程start的调用位置,如下,

class opencv_imshow_test(Node):
    def __init__(self):
        self.viz_thread = Thread(target=self.visulize)
        self.connect_camera()  
        self.camera_rgb = img # 这里是一张图片
        self.head_camera = Realsense_camera()             
# 把线程启动放在最后,就好了
        self.viz_thread.start()

奇怪的点

有的时候把线程启动放在最开始反而好使,有的时候是最后

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值