python - 加载图像返回函数 cv::inRange 中的断言失败
问题描述
- 获取代码以读取图像文件夹路径时出现问题。看起来好像它正在创建一条不存在的路径。我运行了三个 .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'
解决方案
OpenCV 错误消息不清楚...此错误消息:
(-215:Assertion failed) ! _src.empty() in function 'cv::inRange'
表示 inRange 函数(在您的情况下为 img)中的源参数为空。这可能是因为您在阅读图像时拼错了图像的文件名。
推荐阅读
- javascript - 如何将两个函数添加在一起并存储在 JavaScript 中的另一个函数(第三个函数)中?
- html - 如何使用户的输入打开与 R 上的输入匹配的文件
- flutter - 如果父容器正在改变高度,颤振键盘不会聚焦
- ruby-on-rails - 命名空间的 Rails 路径助手
- c# - C# - """ 导致反序列化问题
- gradle - 我可以通过 gradle 中的任务将一个或多个文件上传到共享点吗?
- c# - C# 串行端口:从嵌入式 Linux 设备读取输出数据
- javascript - 如何在字符串中查找重复的单词?
- javascript - 我的课程作业的 Javascript 颜色猜谜游戏
- azure - Azure Sentinel 警报基于来自 KQL 的 5 分钟数据间隔