我是使用python进行图像处理的初学者。
我想将视频播放器制作在ubuntu enter link description here的SMplayer之类的嵌入式板(LattePanda)上
所以我写了这样的代码
#-*- coding:utf-8 -*-
__Version__ = '1.0V'
import os, sys, time
import cv2
from Queue import Queue
from threading import Thread
print cv2.useOptimized()
class FileVideoStream:
def __init__(self, path, queuesize=512):
self.stream = cv2.VideoCapture(path)
self.stopped = False
self.Q = Queue(maxsize=queuesize)
def start(self):
t = Thread(target=self.update, args=())
t.daemon = True
t.start()
return self
def update(self):
while True:
if self.stopped:
return
if not self.Q.full():
(ret, frame) = self.stream.read()
if not ret:
self.stop()
return
self.Q.put(frame)
def read(self):
return self.Q.get()
def more(self):
return self.Q.qsize() > 0
def stop(self):
self.stopped = True
def main():
window_name = 'window'
fvs = FileVideoStream('test.mp4').start()
cv2.namedWindow(window_name, cv2.WND_PROP_FULLSCREEN)
cv2.setWindowProperty(window_name, cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)
while True:
qsize = '%s' % str(fvs.Q.qsize())
qsize = int(qsize)
if qsize > 2:
break
else:
time.sleep(0.5)
while fvs.more():
frame = fvs.read()
cv2.imshow(window_name, frame)
cv2.waitKey(1)
if __name__ == '__main__':
main()
但是此代码的结果比SMplayer慢得多。不光滑。 请帮助我,像SMplayer这样的视频播放器如何流畅播放?