Reputation: 707
I have an api take img_path as input as it use cv2.imread()
to load image.
def detect(net, classes, img_path, CONF_THRESH = 0.8, NMS_THRESH = 0.3):
outputs = []
im = cv2.imread(img_path)
......
......
Now I want to create a small tool to directly load video and call the api function.However, while the cap.read() is done. I can't directly pass the image object into the api function.
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
What the best way to do so that I don't have to change the api function? My idea is to imwrite the video capture image and reload it again. but this seems stupid and slow.
Upvotes: 0
Views: 248
Reputation: 51
if you want to pass a frame as argument to your api detect function, save it first and then call the api function as usual
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)
Upvotes: 1