我有一个api把img_path作为输入,因为它使用cv2.imread()
加载图片。
def detect(net, classes, img_path, CONF_THRESH = 0.8, NMS_THRESH = 0.3):
outputs = []
im = cv2.imread(img_path)
......
......
现在我想创建一个小工具来直接加载视频并调用api函数。但是,当cap.read()完成时。我不能直接将图像对象传递给api函数。
def detect_video(net, classes, video, CONF_THRESH = 0.8, NMS_THRESH =0.3):
"""detect an input video"""
try:
cap = cv2.VideoCapture('video')
except Exception, e:
print e
return None
while(True):
ret, frame = cap.read()
# try to call the api function
最好的方法是什么,我不必更改api功能?我的想法是写入视频捕获图像并重新加载它。但这似乎很愚蠢。
答案 0 :(得分:1)
如果你想将一个帧作为参数传递给你的api检测函数,先保存它,然后像往常一样调用api函数
img_path = 'image.jpg'
...
ret, frame = cap.read()
cv2.imwrite(img_path, frame)
# and now try to call the api function
detect(net, classes, img_path, CONF_THRESH = 0.8, NMS_THRESH = 0.3)