开发者社区> 问答> 正文

我们可以在python flask上传一个视频吗?如果是,我如何使用opencv或其他库读取上传的视

我已经试过了

@app.route('/result', methods=["GET", "POST"])
def uploadfile():
   if request.method == "POST":
     #file = request.files['file']
     uploaded_files =  request.files['file']
     sfname = 'static/images/'+str(secure_filename(uploaded_files.filename))
     print("uploadfile",uploadfile,sfname)
     if uploaded_files:
        #url=test_model(sfname)
        ext=["jpg","png","tif"]
        if sfname[-3:].lower() in ext:
            return "predicted face exp is - "+str(test_model(uploaded_files))
        elif sfname[-3:].lower()=="mp4":
            return str(test_model_for_video(uploaded_files))
        else:
            return "file format is not supported"
     else:
        return "please ulpoad an image or video"
  def test_model_for_video(path_to_video):
      print(path_to_video.read())
      cap = cv2.VideoCapture(path_to_video)
      pred=[]
      while(cap.isOpened()):
        ret, frame = cap.read()
        gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
        cv2.imshow('frame',gray)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
   cap.release()
   cv2.destroyAllWindows()

问题来源StackOverflow 地址:/questions/59380148/can-we-upload-a-video-in-python-flask-if-yes-then-how-can-i-read-the-uploaded

展开
收起
kun坤 2019-12-28 14:32:00 2038 0
1 条回答
写回答
取消 提交回答
  • 成功了吗?这个思路不错

    2020-03-25 16:52:44
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
From Python Scikit-Learn to Sc 立即下载
Data Pre-Processing in Python: 立即下载
双剑合璧-Python和大数据计算平台的结合 立即下载