代码如下 fire.py

import time
import multiprocessing as mp
import threading
import cv2
from PIL import Image
import base64
import json
from io import BytesIO
import numpy as np
import requests"""
Source: Yonv1943 2018-06-17
https://github.com/Yonv1943/Python
https://zhuanlan.zhihu.com/p/38136322
OpenCV official demo
https://docs.opencv.org/3.0-beta/doc/py_tutorials/py_gui/py_video_display/py_video_display.html
海康、大华IpCamera RTSP地址和格式(原创,旧版)- 2014年08月12日 23:01:18 xiejiashu
rtsp_path_hikvison = "rtsp://%s:%s@%s/h265/ch%s/main/av_stream" % (user, pwd, ip, channel)
rtsp_path_dahua = "rtsp://%s:%s@%s/cam/realmonitor?channel=%d&subtype=0" % (user, pwd, ip, channel)
https://blog.csdn.net/xiejiashu/article/details/38523437
最新(2017)海康摄像机、NVR、流媒体服务器、回放取流RTSP地址规则说明 - 2017年05月13日 10:51:46 xiejiashu
rtsp_path_hikvison = "rtsp://%s:%s@%s//Streaming/Channels/%d" % (user, pwd, ip, channel)
https://blog.csdn.net/xiejiashu/article/details/71786187
"""def image_put(q, rtsp):cap = cv2.VideoCapture(rtsp)while True:q.put(cap.read()[1])q.get() if q.qsize() > 1 else time.sleep(0.01)def image_get(q, window_name):cv2.namedWindow(window_name, flags=cv2.WINDOW_FREERATIO)while True:frame = q.get()frame = process(frame);# put_rtmp(frame, p)cv2.imshow(window_name, frame)cv2.waitKey(1)def process(frame):# frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)img = Image.fromarray(frame)output_buffer = BytesIO()  # 创建一个BytesIOimg.save(output_buffer, format='JPEG')  # 写入output_bufferbyte_data = output_buffer.getvalue()  # 在内存中读取image_base64 = base64.b64encode(byte_data).decode()  # 转为BASE64data = json.dumps({"image": image_base64, "visual_result": "True", "username": "xsrt", "password": "dGVzdC1wd2QxMjM="})headers = {"Content-Type": "application/json"}response = requests.post('http://192.168.20.99:8190/fire/json', data=data, headers=headers)# response = requests.post('http://192.168.20.99:8868/face_mask/json', data=data, headers=headers)result = response.textresult = json.loads(result)base64_img = Noneimg = Nonetry:base64_img = result["base64"]process_img = base64.b64decode(base64_img)img = cv2.imdecode(np.frombuffer(process_img, np.uint8), cv2.IMREAD_COLOR)img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)except:img = framereturn imgdef run_single_camera(rtsp):# user_name, user_pwd, camera_ip = "admin", "admin123456", "[fe80::3aaf:29ff:fed3:d260]"## mp.set_start_method(method='spawn')  # init# queue = mp.Queue(maxsize=2)# processes = [mp.Process(target=image_put, args=(queue, user_name, user_pwd, camera_ip)),#              mp.Process(target=image_get, args=(queue, camera_ip))]## [process.start() for process in processes]# [process.join() for process in processes]user_name, user_pwd, camera_ip = "admin", "admin123456", "[fe80::3aaf:29ff:fed3:d260]"mp.set_start_method(method='spawn')  # initqueue = mp.Queue(maxsize=2)threads = [threading.Thread(target=image_put, args=(queue, rtsp)),threading.Thread(target=image_get, args=(queue, 'fire'))][thread.start() for thread in threads]def run(rtsp):run_single_camera(rtsp)  # quick, with 2 threadspassif __name__ == '__main__':# rtsp = "rtsp://admin:a1234567@192.168.20.87:554/h264/ch1/main/av_stream"import sysrtsp = sys.argv[1]run(rtsp)

打包

打包后生成 fire.exe 文件
参考 python打包

打包成 exe 文件后运行

# 后面的是参数:视频流地址
fire.exe rtsp://admin:a1234567@192.168.20.87:554/h264/ch1/main/av_stream

python多线程调用视频流进行模型处理后播放相关推荐

  1. cv2 python 多线程调用摄像头_2种方法用python调用cv2模块给图片打马赛克

    1 说明: ===== 1.1 因各种需要,给图片打马赛克,当然本人着重介绍python用cv2的方法,主要讲解python和cv2的相关编程知识. 1.2 cv2模块:是OpenCV的python调 ...

  2. python多线程调用携程,Python 协程,Python携程

    Python 协程,Python携程 协程 进程:操作系统中存在 线程:操作系统中存在 协程:是微线程 模块(greenlet) 协程不是一个真实存在的东西,是由程序员创造出来的 协程,是对一个线程分 ...

  3. python多线程调用携程,进程、线程和携程的通俗解释【刘新宇Python】

    通过下面这张图你就能看清楚了,进程.线程和携程的关系 多个进程是可以运行在多个CPU当中的,比如你的电脑是4核,可以同时并行运行四个进程,这是真正物理上的并行运行. 每个进程又可以有多个线程,线程是轮 ...

  4. win10,win11后在cmd命令行输入python自动调用微软应用商店

    项目场景: 更新win11后命令行输入python无法调用 问题描述 升级win11后在cmd命令行输入python自动调用微软应用商店 解决方案: 一开始在网上查的方案,删除这个微软应用商店的方案无 ...

  5. python多线程执行_python多线程实现同时执行两个while循环

    如果想同时执行两个while True循环,可以使用多线程threading来实现. 完整代码 #coding=gbk from time import sleep, ctime import thr ...

  6. python caffe 训练自己的模型_python接口调用已训练好的caffe模型测试分类方法

    训练好了model后,可以通过python调用caffe的模型,然后进行模型测试的输出. 本次测试主要依靠的模型是在caffe模型里面自带训练好的结构参数:~/caffe/models/bvlc_re ...

  7. 线程中这么调用类_一文学会 Python 多线程编程

    Threading 模块从Python 1.5.2版开始出现,用于增强底层的多线程模块 thread .Threading 模块让操作多线程变得更简单,并且支持程序同时运行多个操作. 注意,Pytho ...

  8. python如何使用多线程_Python 类中的方法如何多线程调用?

    这么写直接弹框报python运行出错,/尴尬,那这个怎么多线程调用getA/getB/getC/getD/getE呢?每次传参还要循环个arg2list列表 class ThreadTest(): d ...

  9. python多线程没有java_Java 多线程启动为什么调用 start() 方法而不是 run() 方法?...

    多线程在工作中多多少少会用到,我们知道启动多线程调用的是 start() 方法,而不是 run() 方法,你知道原因吗? 在探讨这个问题之前,我们先来了解一些多线程的基础知识~ 线程的状态 Java ...

最新文章

  1. 损坏防浪涌电插排内部电路
  2. 没错,接单就是特简单!
  3. 走过13,展望14----希望是个好东西
  4. php udp 非阻塞,使用非阻塞udp读取时丢失消息
  5. 为何去银行存款的人越来越少,但是银行的存款却在增加?
  6. Java和JavaScript之间的区别
  7. css怎么把背景图片拉伸至100%
  8. js获得服务器时间并实时更新
  9. github 提速方法
  10. 3Dmax已渲染的图怎么加载VFB和LUT?
  11. 电路分析之正弦稳态电路的仿真与研究
  12. 花西子背后的那个男人和他的五篇笔记
  13. IP静态路由实验(基于华为eNSP模拟器)
  14. 如何判断本地(路由器)分配的IP是否是公网IP?
  15. zer0pts CTF 2022 VishwaCTF 2022
  16. GoldWave中文版如何将视频批量转换为音频?
  17. apche服务器网站访问503错误,apache部署python程序出现503错误的解决方法
  18. 记录安装tensorflow-gpu,版本选择问题,短平快解决战斗
  19. 英雄!「安可心」请你跳支舞
  20. deepin启动黑屏

热门文章

  1. 震动效果调研 - iOS
  2. 无源滤波器--低通滤波器(LPF)
  3. 电子学会2023年3月青少年软件编程(图形化)等级考试试卷(三级)真题,含答案解析
  4. Github 无法显示markdown图片
  5. 小程序页面传值传递对象[Object Object]
  6. python写篮球游戏_程序员们把“蔡徐坤打篮球”写成了一个游戏
  7. 程序员年薪30万到100万,汇报有啥差别?
  8. WindRiver.Tornado.v2.2.for.Mips-ISO 2CD
  9. Java物联网项目中,运行SPringBoot脚手架,运行失败问题
  10. 图神经网络基础--图结构数据