python opencv cv2 imshow threading 多线程
2024-09-07 20:52:36
除了线程同步,还需要注意的是「窗口处理」要放在主线程
#!/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!')
最新文章
- linux c 笔记-3 c语言基础知识
- Windows Server 2003 服务器备份和恢复技巧
- fabric批量操作远程操作主机的练习
- 【SDOI2010题集整合】BZOJ1922~1927&;1941&;1951&;1952&;1972&;1974&;1975
- ahjesus C# Flags 位域略说
- hdu-5586 Sum(dp)
- Fedora 20下安装官方JDK替换OpenJDK并配置环境变量
- ReactNative 踩坑小计
- cannot be resolved to a type in same package 问题解决
- 谈谈文件增量同步算法:RSYNC和CDC
- DLR、ASTER GDEM、SRTM3、GMTED2010等5种全球高程数据对比
- JS分两种数据类型,你都知道吗?
- Python-快速排序
- 基于Vue.js的大型报告页项目实现过程及问题总结(一)
- html5的八大特性
- ●BZOJ 3309 DZY Loves Math
- 不可错过的Node.js框架
- 简简单单的Vue3(插件开发,路由系统,状态管理)
- 【vue】vue +element 搭建项目,使用el-date-picker组件遇到的坑
- 1分钟看懂log4j 配置自己想要的日志信息
热门文章
- Clip Studio Paint EX 1.10.6安装破解教程
- (opencv09)cv2.getStructuringElement()构造卷积核
- 过渡——transition
- [源码解析] 机器学习参数服务器ps-lite 之(3) ----- 代理人Customer
- JavaEE在线就业班2.0-(1)-《博学谷》
- MarkDown语法(Typora软件为例)
- 什么是RSA
- Java集合框架和数组的排序(转载)
- Mybatis源码解析2—— 实例搭建
- Python 可变数据类型与不可变数据类型