加载图像 returns 断言函数失败 cv::inRange

loading images returns Assertion Failed in function cv::inRange

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

img2bim.py

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

beam.py

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

wall.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'

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

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

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