无法将从烧瓶上传的文件传递给VideoCapture()

时间:2020-04-27 17:49:11

标签: python opencv flask file-upload video-processing

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

        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()的问题?

1 个答案:

答案 0 :(得分:0)

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