python - 如何获取多个图像的轮廓区域并在数据框中分离
问题描述
我正在尝试计算每个不同图像的轮廓区域(来自文件夹路径),然后转换为数据帧。有人可以给一些建议吗?
该脚本显示我可以计算所有图像的所有轮廓的面积,然后转换为所有轮廓的数据框,但我正在搜索为每个图像将它们分开。
第一个图像所有轮廓,第二个所有轮廓,第三个所有轮廓,等等。
有人可以指导我在循环中找到代码吗?
谢谢
import os
import cv2
import pandas as pd
import glob
#load images from specific path
##########################################################
try:
os.makedirs("D:\\NBC_new2020_\\data\\concat\\results")
#os.makedirs("D:\\NBC_new2020_\\images")
except FileExistsError:
# directory already exists
pass
try:
os.makedirs("D:\\NBC_new2020_\\images")
#os.makedirs("D:\\NBC_new2020_\\images")
except FileExistsError:
# directory already exists
pass
############################################################################
#calculate contour of all images from the path
#############################################################
img = []
contours = []
area = []
for fn in glob.glob("D:\\NBC_new2020_\\images\\*.png"):
img = cv2.imread(fn, 0)
ret, thresh = cv2.threshold(img, 39, 255, 0)
contours, hierarchy = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
for i in contours:
area.append(cv2.contourArea(i))
#print(contours)
dframe = pd.DataFrame(area)
print(dframe)
解决方案
推荐阅读
- reactjs - 在 React 中将对象数组设置为状态变量
- c++ - 为什么 CWE 认为 rand() 具有潜在危险
- apache-kafka - Kafka JMX 在一个代理中获取主题的分区
- bash - Returning from a second function in a sourced script
- mongodb - 如何从 pymongo 的数组中更新嵌入文档的字段?
- .net - 引用的 dll 在什么框架下运行?
- php - Laravel 启用将导出项目 Zip 文件下载到浏览器
- android - 带有分页库的存储库模式
- docker - 如何克服官方教程中 docker push 拒绝访问资源的问题
- c# - c# equivalent of c++ vector