目录

安装报错

error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow'

error: (-2) could not find a writer for the specified extension in function cv::imwrite_

opencv-python用VideoWriter保存视频只有几KB

Unsupported depth of input image

opencv imshow函数显示图片,窗口在转圈并且一直是灰色图像


安装报错

报错信息:

# 这只是报错信息的片段
Building wheel for opencv-contrib-python (PEP 517) ... error
  ERROR: Complete output from command 'D:\anzhuanglujing\Anaconda\python.exe' 'D:\anzhuanglujing\Anaconda\lib\site
-packages\pip\_vendor\pep517\_in_process.py' build_wheel 'C:\Users\Administrator\AppData\Local\Temp\tmpjqvqd9_8':
  ERROR: Not searching for unused variables given on the command line.
  CMake Error at CMakeLists.txt:2 (PROJECT):
    Generator
  
      Ninja
  
    does not support platform specification, but platform
  
      x64
  
    was specified.
  
  
  -- Configuring incomplete, errors occurred!
  See also "C:/Users/Administrator/AppData/Local/Temp/pip-install-bc_r227f/opencv-contrib-python/_cmake_test_compi
le/build/CMakeFiles/CMakeOutput.log".
  Not searching for unused variables given on the command line.
  CMake Error at CMakeLists.txt:2 (PROJECT):
    Generator
  
      Visual Studio 17 2022
  
    could not find any instance of Visual Studio.

升级pip版本,命令如下:python -m pip install --upgrade pip

然后再安装

报错信息:

  Please check the install target is valid and see CMake's output for more information.
  ----------------------------------------
  ERROR: Failed building wheel for opencv-python
Failed to build opencv-python
ERROR: Could not build wheels for opencv-python, which is required to install pyproject.toml-based projects

我是python 3.6,不能装最新版本的opencv,可以装低版本,比如4.5.3.56

error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow'

查了网上原因有很多,我直接加了try except解决。

if frame is not None:
            try:
                cv2.imshow(window_name, frame)
                p.send(frame)
            except:
                pass

error: (-2) could not find a writer for the specified extension in function cv::imwrite_

我报错的原因是因为imwrite里,图片名字没有加扩展名

opencv-python用VideoWriter保存视频只有几KB

我遇到问题的原因是图片帧的尺寸与videowriter中参数size设定的大小不一致。

Unsupported depth of input image

opencv在读取或者存取图片时,数组的类型不是opencv支持的类型

OpenCV的原始数据类型包括unsigned char、bool、signed char、unsigned short、signed short、int、float、double以及由这些基础类型组成的元组,这些元组中的所有值都属于相同的类型。

opencv imshow函数显示图片,窗口在转圈并且一直是灰色图像

在imshow之后需要有cv2.waitKey(0)

06-11 11:54