一个快速的解决方案是修改image.c文件以打印出边界框信息:
...
if(bot > im.h-1) bot = im.h-1;
// Print bounding box values
printf("Bounding Box: Left=%d, Top=%d, Right=%d, Bottom=%d\n", left, top, right, bot);
draw_box_width(im, left, top, right, bot, width, red, green, blue);
...
有一个很好的小蟒蛇(2 - 但只有很少的修改3. [只是将打印和字符串更改为主要的二进制字符串])程序,你可以在主回购https://github.com/pjreddie/darknet/blob/master/python/darknet.py中使用
注意!给定的坐标是中点,宽度和高度。
如果你打算在python
中实现这个,那么我在python
创建了这个小的here包装器。按照ReadMe
文件进行安装。它很容易安装。
之后跟着这个example code知道如何检测物体。
如果您的检测是det
top_left_x = det.bbox.x
top_left_y = det.bbox.y
width = det.bbox.w
height = det.bbox.h
如果需要,您可以通过以下方式获得中点:
mid_x, mid_y = det.bbox.get_point(pyyolo.BBox.Location.MID)
希望这可以帮助..
对于Windows中的python用户:
首先......,做几个设置工作:
PYTHONPATH = 'YOUR DARKNET FOLDER'
%PYTHONPATH%
中编辑文件coco.data
,将cfg folder
文件夹变量更改为names
文件夹,在我的情况下:
coco.names
使用此设置,您可以从任何文件夹中调用darknet.py(来自names = D:/core/darknetAB/data/coco.names
存储库)作为您的python模块。
开始编写脚本:
alexeyAB\darknet
如何使用它:
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 - (weight_size/2))
y_start = round(y1 - (height_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
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
得到坐标:
如果只有1个结果:
table = 'D:/test/image/test1.jpg'
checking = detect(table)'
如果有很多结果:
x1, y1, x2, y2 = checking[2]