我需要使用 YOLO 对象检测获取上图中生成的边界框坐标。
原文由 Shriram 发布,翻译遵循 CC BY-SA 4.0 许可协议
我需要使用 YOLO 对象检测获取上图中生成的边界框坐标。
原文由 Shriram 发布,翻译遵循 CC BY-SA 4.0 许可协议
对于 Windows 中的 python 用户:
首先…,做几个设置工作:
PYTHONPATH = 'YOUR DARKNET FOLDER'
%PYTHONPATH%
coco.data
in cfg folder
, by change the names
folder variable to your coco.names
folder, in my case:names = D:/core/darknetAB/data/coco.names
使用此设置,您可以从任何文件夹调用 darknet.py(来自 alexeyAB\darknet 存储库)作为您的 python 模块。
开始编写脚本:
from darknet import performDetect as scan #calling 'performDetect' function from darknet.py
def detect(str):
''' this script if you want only want get the coord '''
picpath = str
cfg='D:/core/darknetAB/cfg/yolov3.cfg' #change this if you want use different config
coco='D:/core/darknetAB/cfg/coco.data' #you can change this too
data='D:/core/darknetAB/yolov3.weights' #and this, can be change by you
test = scan(imagePath=picpath, thresh=0.25, configPath=cfg, weightPath=data, metaPath=coco, showImage=False, makeImageOnly=False, initOnly=False) #default format, i prefer only call the result not to produce image to get more performance
#until here you will get some data in default mode from alexeyAB, as explain in module.
#try to: help(scan), explain about the result format of process is: [(item_name, convidence_rate (x_center_image, y_center_image, width_size_box, height_size_of_box))],
#to change it with generally used form, like PIL/opencv, do like this below (still in detect function that we create):
newdata = []
if len(test) >=2:
for x in test:
item, confidence_rate, imagedata = x
x1, y1, w_size, h_size = imagedata
x_start = round(x1 - (w_size/2))
y_start = round(y1 - (h_size/2))
x_end = round(x_start + w_size)
y_end = round(y_start + h_size)
data = (item, confidence_rate, (x_start, y_start, x_end, y_end), w_size, h_size)
newdata.append(data)
elif len(test) == 1:
item, confidence_rate, imagedata = test[0]
x1, y1, w_size, h_size = imagedata
x_start = round(x1 - (w_size/2))
y_start = round(y1 - (h_size/2))
x_end = round(x_start + w_size)
y_end = round(y_start + h_size)
data = (item, confidence_rate, (x_start, y_start, x_end, y_end), w_size, h_size)
newdata.append(data)
else:
newdata = False
return newdata
如何使用它:
table = 'D:/test/image/test1.jpg'
checking = detect(table)'
获取坐标:
如果只有 1 个结果:
x1, y1, x2, y2 = checking[2]
如果结果很多:
for x in checking:
item = x[0]
x1, y1, x2, y2 = x[2]
print(item)
print(x1, y1, x2, y2)
原文由 Wahyu Bram 发布,翻译遵循 CC BY-SA 4.0 许可协议
2 回答5.2k 阅读✓ 已解决
2 回答1.1k 阅读✓ 已解决
4 回答1.4k 阅读✓ 已解决
3 回答1.3k 阅读✓ 已解决
3 回答1.2k 阅读✓ 已解决
2 回答859 阅读✓ 已解决
1 回答1.7k 阅读✓ 已解决
一个快速的解决方案是修改 image.c 文件以打印出边界框信息: