您好我刚刚开始使用全息视图,我正在尝试使用全息视图(opencv)准备一个小型流媒体视频应用。我对龙卷风和异步编程的经验非常有限。
@Provides
我没有获得运行/流式更新。我只得到最后一帧的单个图像。有人可以帮我解决我的错误
答案 0 :(得分:1)
除了关于gen.sleep的评论花费时间(以秒为单位)之外,您还需要将回调写为生成器。这样的事情应该这样做:
from holoviews.streams import Pipe, Buffer
from tornado.ioloop import IOLoop
from tornado import gen
import cv2
@gen.coroutine
def f():
vd = cv2.VideoCapture("TestVideo.mp4")
width = int(vd.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(vd.get(cv2.CAP_PROP_FRAME_HEIGHT))
frames = int(vd.get(cv2.CAP_PROP_FRAME_COUNT))
while frames > 0:
ret, frame = vd.read()
rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
pipe.send(rgb)
frames -= 1
yield gen.sleep(1)
vd.release()
cv2.destroyAllWindows()
pipe = Pipe(data=[])
IOLoop.current().add_callback(f)
hv.DynamicMap(hv.RGB, streams=[pipe])
答案 1 :(得分:0)
谢谢@philippjfr
最后,我使用streamz python库得到了一些可行的东西。然而,这种方法有效。这是我基于上述方法的工作解决方案。
```
import numpy as np
import pandas as pd
import holoviews as hv
hv.extension('bokeh', 'matplotlib')
from holoviews.streams import Pipe, Buffer
from tornado.ioloop import IOLoop
from tornado import gen
import cv2
@gen.coroutine
def f():
width = int(vd.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(vd.get(cv2.CAP_PROP_FRAME_HEIGHT))
frames = int(vd.get(cv2.CAP_PROP_FRAME_COUNT))
while frames > 0:
ret, frame = vd.read()
rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
frames -= 1
yield pipe.send(rgb)
vd.release()
cv2.destroyAllWindows()
vd = cv2.VideoCapture("TestVideo.mp4")
ret, frame0 = vd.read()
rgb = cv2.cvtColor(frame0, cv2.COLOR_BGR2RGBA)
pipe = Pipe(data=rgb)
#pipe = Pipe(data=[])
IOLoop.current().add_callback(f)
hv.DynamicMap(hv.RGB, streams=[pipe])
```