除了线程同步,还需要注意的是「窗口处理」要放在主线程

#!/usr/bin/env python3
# -*- coding: utf-8 -*- import sys
import threading
from time import sleep
from queue import Queue
import cv2
import numpy as np
from functools import reduce print(sys.version) q = Queue() def run(n):
thread = threading.current_thread()
thread.setName('thread-fuck')
print('tid is: {0}'.format(thread.ident))
print('thread name is: {0}'.format(thread.getName())) for i in range(100):
img = np.random.randint(0,255,(200,300)).astype(np.uint8)
q.put(img)
sleep(0.1) q.put(0) if __name__ == '__main__':
thread = threading.Thread(target=run, args=(6,))
thread.start() while True:
try:
item = q.get(block=False)
except Exception as e:
keycode = cv2.waitKey(20)
if keycode & 0xFF == ord('q'):
break
continue if type(item) == int:
break if type(item) == type(0):
break
cv2.imshow('fuck', item) thread.join() cv2.waitKey(0)
cv2.destroyAllWindows()
print('done!')

python opencv cv2 imshow threading 多线程的更多相关文章

  1. python学习笔记(threading多线程)

    博主昨天优化了接口框架想着再添加些功能 想到对接口的性能压力测试 在工作过程中之前都是使用的工具 如:loadrunner.jmeter 想着这次准备用python实现对接口的性能压力测试 首先要实现 ...

  2. conda opencv cv2.imshow无法使用

    error: -------src-dir-------/opencv-2.4.10/modules/highgui/src/window.cpp:501: error: (-2) The funct ...

  3. Python模块学习:threading 多线程控制和处理

    Reference:http://python.jobbole.com/81546/ threading.Thread Thread 是threading模块中最重要的类之一,可以使用它来创建线程.有 ...

  4. 【Python | opencv+PIL】常见操作(创建、添加帧、绘图、读取等)的效率对比及其优化

    一.背景 本人准备用python做图像和视频编辑的操作,却发现opencv和PIL的效率并不是很理想,并且同样的需求有多种不同的写法并有着不同的效率.见全网并无较完整的效率对比文档,遂决定自己丰衣足食 ...

  5. cv2.cornerHarris()详解 python+OpenCV 中的 Harris 角点检测

    参考文献----------OpenCV-Python-Toturial-中文版.pdf 参考博客----------http://www.bubuko.com/infodetail-2498014. ...

  6. linux/ubuntu下最简单好用的python opencv安装教程 ( 解决 imshow, SIFT, SURF, CSRT使用问题)

    希望这篇文章能彻底帮你解决python opencv安装和使用中的常见问题. 懒人请直奔这一节, 一条命令安装 opencv 使用python-opencv常用的问题 在linux中使用python版 ...

  7. python+opencv图像变换的两种方法cv2.warpAffine和cv2.warpPerspective

    本文链接:https://blog.csdn.net/qq_27261889/article/details/80720359 # usr/bin/env python # coding: utf- ...

  8. python中threading多线程

    python中有两个处理多线程的模块thread和threading.其中thread提供了多线程底层支持的模块,以低级原始的发那个是来处理和控制线程,使用起来较为复杂:而threading基于thr ...

  9. python——Tkinter图形化界面及threading多线程

    Tkinter模块("Tk 接口")是Python的标准Tk GUI工具包的接口.Tk和Tkinter可以在大多数的Unix平台下使用,同样可以应用在Windows和Macinto ...

随机推荐

  1. 【系统学习ES6】第一节:新的声明方式

    [系统学习ES6] 本专题旨在对ES6的常用技术点进行系统性梳理,帮助大家对其有更好的掌握.计划每周更新1-2篇,希望大家有所收获. 以前用ES5时,声明变量只能用var.ES6的出现,为我们带来了两 ...

  2. jvm源码解读--07 创建 fixup_mirrors

    通过前面的分析,创建的insttanceKlass 都没放入了java_lang_Class::fixup_mirror_list()这里类的数组里面了,所有的instance列举如下 ------- ...

  3. HashSet 和 HashMap 的比较

    HashMap 和 HashSet 都是 collection 框架的一部分,它们让我们能够使用对象的集合.collection 框架有自己的接口和实现,主要分为 Set 接口,List 接口和 Qu ...

  4. mongo-express 远程代码执行漏洞(CVE-2019-10758)

    影响版本 mongo-express 0.53.0 POST /checkValid HTTP/1.1 Host: 192.168.49.2:8081 Accept-Encoding: gzip, d ...

  5. (论文笔记Arxiv2021)Walk in the Cloud: Learning Curves for Point Clouds Shape Analysis

    目录 摘要 1.引言 2.相关工作 3.方法 3.1局部特征聚合的再思考 3.2 曲线分组 3.3 曲线聚合和CurveNet 4.实验 4.1 应用细节 4.2 基准 4.3 消融研究 5.总结 W ...

  6. 01_安装电脑软件的步骤批处理脚本.bat

    REM 01_安装电脑软件的步骤批处理脚本.bat MD 01_安装电脑软件的步骤 REM ZIP解压密码空格MD 02_制作杏雨梨云USB维护系统2019中秋版之国庆更新固态U盘MD 03_复制安装 ...

  7. OpenGL学习笔记(二)画三角形

    目录 渲染管线(Graphics Pipeline) 编码实现 顶点数据 顶点缓冲对象(VBO) 顶点着色器 编译着色器 片段着色器 着色器程序 链接顶点属性 顶点数组对象 最终绘制三角形 索引缓冲对 ...

  8. Java数组02——三种初始化及内存分析

    内存分析 三种初始化 例子  package array; ​ public class ArrayDemon02 {     public static void main(String[] arg ...

  9. springboot的单元测试(总结两种)

    .personSunflowerP { background: rgba(51, 153, 0, 0.66); border-bottom: 1px solid rgba(0, 102, 0, 1); ...

  10. mybatis源码核心代码

    /** * mybatis源码测试类 * @param args * @throws IOException * @see org.apache.ibatis.session.Configuratio ...