首页 > 解决方案 > 加载图像返回函数 cv::inRange 中的断言失败

问题描述

  1. 获取代码以读取图像文件夹路径时出现问题。看起来好像它正在创建一条不存在的路径。我运行了三个 .py 文件来运行主要的 img2bim.py。以下是错误行的内容(不是整个代码文件):

img2bim.py

    14# model = {
    15#    "beam": beam.find_steel_beams(image),

光束.py

    63# def find_steel_beams(img, debug=False):
    64#    image = wall.remove_walls(img)

墙.py

    7# def remove_walls(img):
    8#     rimg = cv2.bitwise_not(img)
    9#     kernel = np.ones((5,5),np.uint8)
    10#    lower = np.array([190, 190, 190])
    11#    upper = np.array([195, 195, 195])
    12#    initial_mask = cv2.inRange(img, lower, upper)

2. cmd.exe命令行回溯如下:

    > python VIF\img2bim.py

    Traceback (most recent call last):
       File "VIF\img2bim.py", line 15, in <module>
          "beam": beam.find_steel_beams(image),
       File "C:\Python\Python37-32\VIF\beam.py", line 64, in find_steel_beams
          image = wall.remove_walls(img)
       File "C:\Python\Python37-32\VIF\wall.py", line 12, in remove_walls
          initial_mask = cv2.inRange(img, lower, upper)
    cv2.error: OpenCV(3.4.4) C:\projects\opencv-python\opencv\modules\core\src\arithm.cpp:1766: error: (-215:Assertion failed) ! _src.empty() in function 'cv::inRange'

标签: pythonpython-3.xnumpyopencvcv2

解决方案


OpenCV 错误消息不清楚...此错误消息:

 (-215:Assertion failed) ! _src.empty() in function 'cv::inRange'

表示 inRange 函数(在您的情况下为 img)中的源参数为空。这可能是因为您在阅读图像时拼错了图像的文件名。


推荐阅读