python 视频处理1006python 视频处理_Python视频处理

此篇博客讲述了作者在使用Python OpenCV进行视频处理时,遇到视频线程中cv2.imshow方法无法正常显示的问题。通过创建并启动两个线程分别播放不同帧,分享了如何解决视频播放器打开即关闭的问题,适合对多线程和视频处理感兴趣的开发者参考。
摘要由CSDN通过智能技术生成

我写了一个代码,用两个不同的帧来播放一个视频线程。那个代码看起来不错,但是cv2.imshow方法不显示正在播放的视频。视频播放器立即打开和关闭。

解决问题所需的帮助。在import threading

import cv2

def print_cube(num):

"""

function to print cube of given num

"""

print("start")

print(num)

cv2.imshow("video1",num)

print("end")

cv2.destroyAllWindows()

def print_square(num):

"""

function to print square of given num

"""

print("start1")

print(num)

cv2.imshow("video2",num)

print("end2")

if __name__ == "__main__":

# creating thread

cap = cv2.VideoCapture("C:\\Users\shakarna\Desktop\video.mp4")

while(True):

# Capture frame-by-frame

ret, frame = cap.read()

# Our operations on the frame come here

gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

t1 = threading.Thread(target=print_square, args=(frame,))

t2 = threading.Thread(target=print_cube, args=(gray,))

# starting thread 1

t1.start()

# starting thread 2

t2.start()

# wait until thread 1 is completely executed

t1.join()

# wait until thread 2 is completely executed

t2.join()

if cv2.waitKey(1) & 0xFF == ord('q'):

break

cap.release()

cv2.destroyAllWindows()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值