为什么我不能从python3.7.2中的utils模块导入CFEVideoConf和image_resize

2024-06-28 20:19:14 发布

您现在位置:Python中文网/ 问答频道 /正文

我从互联网上了解到使用timelaspe捕捉图像。但是,我遇到了一些问题。我从GitHub上看到很多人可以使用: from utils import CFEVideoConf, image_resize但我不能。我是用Sublimitext 3.0做的。。。如果有人知道那个问题,请帮帮我。提前谢谢。在

这是我的代码:

from utils import CFEVideoConf, image_resize

ImportError: cannot import name 'CFEVideoConf' from 'utils' (C:\Users\NGHIA\AppData\Local\Programs\Python\Python37-32\lib\site-packages\utils__init__.py)


Tags: 代码from图像imageimportgithub互联网utils
1条回答
网友
1楼 · 发布于 2024-06-28 20:19:14

当你说“很多人”时,你可能指的是this存储库。在

我能找到的唯一一个定义CFEVideoConf的人。
这是the definition for that class

class CFEVideoConf(object):
    # Standard Video Dimensions Sizes
    STD_DIMENSIONS =  {
        "360p": (480, 360),
        "480p": (640, 480),
        "720p": (1280, 720),
        "1080p": (1920, 1080),
        "4k": (3840, 2160),
    }
    # Video Encoding, might require additional installs
    # Types of Codes: http://www.fourcc.org/codecs.php
    VIDEO_TYPE = {
        'avi': cv2.VideoWriter_fourcc(*'XVID'),
        #'mp4': cv2.VideoWriter_fourcc(*'H264'),
        'mp4': cv2.VideoWriter_fourcc(*'XVID'),
    }

    width           = 640
    height          = 480
    dims            = (640, 480)
    capture         = None
    video_type      = None
    def __init__(self, capture, filepath, res="480p", *args, **kwargs):
        self.capture = capture
        self.filepath = filepath
        self.width, self.height = self.get_dims(res=res)
        self.video_type = self.get_video_type()

    # Set resolution for the video capture
    # Function adapted from https://kirr.co/0l6qmh
    def change_res(self, width, height):
        self.capture.set(3, width)
        self.capture.set(4, height)

    def get_dims(self, res='480p'):
        width, height = self.STD_DIMENSIONS['480p']
        if res in self.STD_DIMENSIONS:
            width, height = self.STD_DIMENSIONS[res]
        self.change_res(width, height)
        self.dims = (width, height)
        return width, height

    def get_video_type(self):
        filename, ext = os.path.splitext(self.filepath)
        if ext in self.VIDEO_TYPE:
          return  self.VIDEO_TYPE[ext]
        return self.VIDEO_TYPE['avi']

事实上,他有多个文件导入了这个类。例如,here。在

为了使它在您的环境中工作,您需要:

  1. 在本地克隆存储库

    git clone https://github.com/codingforentrepreneurs/OpenCV-Python-Series
    
  2. 安装要求:

    cd OpenCV-Python-Series
    pip install -r requirements.txt
    
  3. 然后您就可以充分利用该项目

相关问题 更多 >