opencv 如何解决我的视频灰度转换器中的递归错误

6za6bjd0  于 2023-04-21  发布在  其他
关注(0)|答案(1)|浏览(125)

我正在开发一个桌面应用程序,可以使用Kivy和OpenCV将视频转换为灰度视频。
但是在使用pyinstaller和下面的命令之后

pyinstaller --name VideoCartoonizer --windowed --onefile main.py

我得到一个错误显示
由于出现未处理的异常,无法执行脚本“main”:超过最大递归深度
下面是我的代码:

import cv2

import numpy as np

from moviepy.editor import VideoFileClip

from moviepy.editor import VideoFileClip, concatenate_videoclips, VideoClip

from kivy.app import App

from kivy.uix.boxlayout import BoxLayout

from kivy.uix.label import Label

from kivy.uix.textinput import TextInput

from kivy.uix.button import Button

from kivy.uix.filechooser import FileChooserListView

from kivy.uix.popup import Popup

class VideoCartoonizer(App):

    def build(self):

        # create the GUI

        self.layout = BoxLayout(orientation='vertical')

        # select input file button

        self.select_input_button = Button(text='Select Input File', size_hint_y=0.1)

        self.select_input_button.bind(on_press=self.select_input_file)

        self.layout.add_widget(self.select_input_button)

        # input file path label

        self.layout.add_widget(Label(text='Or enter the input video file path:', size_hint_y=0.1))

        # input file path text input

        self.input_file = TextInput(size_hint_y=0.1)

        self.layout.add_widget(self.input_file)

        # convert button

        self.convert_button = Button(text='Convert to cartoon', size_hint_y=0.1)

        self.convert_button.bind(on_press=self.convert_video)

        self.layout.add_widget(self.convert_button)

        # output file path label

        self.layout.add_widget(Label(text='Output file path:', size_hint_y=0.1))

        # output file path text input

        self.output_file = TextInput(size_hint_y=0.1, readonly=True)

        self.layout.add_widget(self.output_file)

        return self.layout

    def select_input_file(self, *args):

        # create the file chooser

        file_chooser = FileChooserListView(filters=['*.mp4'])

        # create the popup

        popup = Popup(title='Select Input File', content=file_chooser, size_hint=(0.9, 0.9))



# set the callback for when a file is selected

        def on_selection(instance,selected_file):

            self.input_file.text = selected_file[0]

            popup.dismiss()

        file_chooser.bind(selection=on_selection)

        # open the popup

        popup.open()

    def convert_video(self, *args):

    # get the input file path

        input_file = self.input_file.text

    # define the video processing function

        def process_image(image):

        # resize the image while maintaining aspect ratio

            aspect_ratio = image.shape[1] / image.shape[0]

            target_width = 640

            target_height = int(target_width / aspect_ratio)

            image = cv2.resize(image, (target_width, target_height)) 

        # convert to grayscale

            gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

            return gray

    # process the input video and save the output

        output_file = input_file.replace(".mp4", "_cartoon.mp4")

        input_video = VideoFileClip(input_file)

    # create a queue to keep track of the frames that need to be processed

        frame_queue = list(input_video.iter_frames())

    # create an output video clip with the same parameters as the input video

        output_video = None

        for i, frame in enumerate(input_video.iter_frames()):

            if output_video is None:

                output_video = VideoClip(

                    lambda t: process_image(frame_queue.pop(0)),

                    duration=input_video.duration

            )

            else:

                output_video = concatenate_videoclips([

                    output_video,

                    VideoClip(

                        lambda t: process_image(frame_queue.pop(0)),

                        duration=input_video.duration

                    )

                ])

    # write the output video

        output_video.write_videofile(output_file, codec='mpeg4')

错误:

File "logging\__init__.py", line 1084, in emit

AttributeError: 'NoneType' object has no attribute 'write'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

  File "logging\__init__.py", line 1084, in emit

AttributeError: 'NoneType' object has no attribute 'write'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

  File "logging\__init__.py", line 1084, in emit

AttributeError: 'NoneType' object has no attribute 'write'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

  File "logging\__init__.py", line 1084, in emit

AttributeError: 'NoneType' object has no attribute 'write'

File "logging\__init__.py", line 1657, in callHandlers

  File "logging\__init__.py", line 950, in handle

  File "logging\__init__.py", line 1089, in emit

  File "logging\__init__.py", line 1002, in handleError

  File "kivy\logger.py", line 338, in write

  File "logging\__init__.py", line 1454, in warning

  File "logging\__init__.py", line 1585, in _log

  File "logging\__init__.py", line 1595, in handle

  File "logging\__init__.py", line 1657, in callHandlers

  File "logging\__init__.py", line 950, in handle

  File "logging\__init__.py", line 1089, in emit

  File "logging\__init__.py", line 1002, in handleError

  File "kivy\logger.py", line 338, in write

  File "logging\__init__.py", line 1454, in warning

  File "logging\__init__.py", line 1585, in _log

  File "logging\__init__.py", line 1595, in handle

  File "logging\__init__.py", line 1657, in callHandlers

  File "logging\__init__.py", line 950, in handle

  File "logging\__init__.py", line 1081, in emit

  File "logging\__init__.py", line 925, in format

  File "kivy\logger.py", line 291, in format

  File "copy.py", line 172, in deepcopy

  File "copy.py", line 270, in _reconstruct

  File "copy.py", line 146, in deepcopy

  File "copy.py", line 230, in _deepcopy_dict

  File "copy.py", line 146, in deepcopy

  File "copy.py", line 210, in _deepcopy_tuple

RecursionError: maximum recursion depth exceeded

想让我的视频灰度工作作为一个exe文件,因为它是工作在任何文本编辑器罚款

irlmq6kh

irlmq6kh1#

从错误追溯中可以看出问题的原因:File "kivy\logger.py", line 338, in write。看起来递归错误是由Kivy引起的,所以在谷歌上快速搜索kivy logging recursion depth error python,就会发现kivy github上的一个开放问题的答案。这似乎描述了你的问题,所以我建议你尝试解决这个问题的方法,如果不适合你,请在下面评论。

相关问题