首页 > 解决方案 > 无法将从烧瓶上传的文件传递到 VideoCapture()

问题描述

这是使用烧瓶让用户上传视频文件的服务器脚本

        if file and allowed_file(file.filename):
            filename = secure_filename(file.filename)
            file_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
            file.save(file_path)
            abc.abc(file_path)

            flash('File successfully uploaded')
            return redirect('/')
        else:
            flash('Allowed file types are txt, pdf, png, jpg, jpeg, gif')
            return redirect(request.url)

abc.abc(file_path)使用上传的文件并将文件路径传递给cv2.videocapture(file_path)函数。但是,在文件上传后,实际上并没有发生任何事情,并且对的函数调用videocapture也没有被执行。这是视频捕获部分的代码,作为单独的 python 脚本

class abc:

    def __init__(self, video_url):
        self.video_url = video_url


    def abc(self):

        # Define the video stream
        print('here')
        cap = cv2.VideoCapture(self.video_url)  # Change only if you have more than one webcams

如何解决烧瓶没有将文件传递给 videocapture() 的问题?

标签: pythonopencvflaskfile-uploadvideo-processing

解决方案


它应该调用 init 并且不接受传递的参数,一种解决方法是删除类并直接从模块中导入函数并将文件路径作为参数传递并且它可以工作。谢谢凯文


推荐阅读