英文:
cv2.VideoCapture isn't read video coming from frontend
问题
@app.route('/process', methods=['POST'])
def process():
if request.method == 'POST':
vid = request.files['file']
cap = cv2.VideoCapture(vid)
while cap.isOpened():
ret, frame = cap.read()
if not ret:
break
do_something()
k = cv2.waitKey(1)
if k == 27:
break
英文:
@app.route('/process', methods=['POST'])
def process():
if request.method == 'POST':
vid = request.files['file']
cap = cv2.VideoCapture(vid)
while(cap.isOpened()):
ret,frame = cap.read()
if not ret:
break
do_something()
k = cv2.waitKey(1)
if k == 27:
break
I am sending a video from frontend to flask server to process it. But when I run this code, this error shows up on line cap = cv2.VideoCapture(vid)
:
TypeError: an integer is required (got type FileStorage)
The video coming is converted in class 'werkzeug.datastructures.FileStorage' and cv2.VideoCapture
isn't accepting input as this class. What should I do?
I tried to save the video on local system using vid.save('abc.webm')
and then read it using cv2.VideoCapture
and it works perfectly. But I don't want to save it on system.
Please help. Thank you in advance.
答案1
得分: 1
你需要使用.read()
方法来从FileStorage对象中获取字节。
vid = request.files['file'].read()
cap = cv2.VideoCapture(vid)
英文:
What you want is .read()
to get the bytes from the FileStorage object.
vid = request.files['file'].read()
cap = cv2.VideoCapture(vid)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论