python-3.x - 无法使用 OpenCV 连接多个图像
问题描述
我有 408 张图像(256 x 256 像素)。我想将它们水平和垂直堆叠以创建一个大图像,但我在这样做时遇到了麻烦。文件被命名为 5-X-1.jpg 并且它们都在同一个目录中。
如果我能设法生成一行,我应该能够生成其余的。我已经设法用这些图像的路径制作了一个列表,但我无法cv2.imread
读取这个数组并用cv2.hconcat
or水平堆叠它cv2.hstack
。返回的错误是“无法将 'list' 类型的对象转换为 'filename' 的 'str'”。
这是我试图开始工作的代码:
PathList = [] # empty list
InitialTermCol = 0
for imgs in range(16):
ImgRowStack = r'C:\Users\total\Desktop\Angry\AUTOPY\JapanSteal' + '\\5-' + str(InitialTermCol) + '-1.jpg'
PathList.append(ImgRowStack)
InitialTermCol = InitialTermCol + 1
images = cv2.imread(PathList)
hor = np.hstack(PathList)
cv2.imshow('Horizontal', hor)
cv2.waitKey()
解决方案
您应该遍历 Pathlist,以访问图像的路径。不读清单。路径列表的格式为 :Pathlist=["pathto1","pathto2","pathto3"] 。因此,对其进行迭代将为您提供图像的路径。
for d in PathList: \\ images = cv2.imread(d) \\ Fullimage = np.hstack((Fullimage,images))
如果这个答案对你有帮助,请采纳!
推荐阅读
- python - 未提供身份验证凭据。部署到 AWS 时
- android - 如何使用 clickableAreaImages 库将图像视图显示为全屏
- ios - 未捕获的异常 'NSGenericException: 应用程序提供了一个 UIAlertController 样式的 UIAlertControllerStyleActionSheet
- postgresql - 出现错误“查询没有结果数据的目的地”
- json - 如何将此嵌套的 json 带入类
- php - json_encode() 问题和存储在 PHP 中的 cookie 问题
- sql - 使用带有左连接的合并来使用最新数据填充主表
- php - Magento 2 Checkout Billing Step Error 'Shipping Address is not set'
- javascript - 验证数据然后返回解析?
- numpy - numpy 掩码覆盖另一个掩码