For us to use YOLO for other applications in study, the ultimate goal is definitely not to look at the predictions BoundingBox OK.
Specifically for me, we need to get boundingbox and then find the local information of the target. Here's a brief description of how to do it.
1. Modify the source code
In the source code image.c find the Draw_detections () function, print out the position of the box, as follows:
2. Record terminal output to text file
The command I use here is | Tee Train_log.txt, refer to: Linux recording terminal (Terminal) output to text file
3.python further extract boundingbox and do simple processing
First look at the input data (that is, the data in the previous step output to the file):
You can see sometimes detection is sometimes not detected, here I do it for the convenience of the back (here I want to extract the category name tip of the box coordinates and processing), a simple process (known each frame has and only one tip, if not detected by the coordinates of adjacent frames), and save to the new file.
The code is as follows:
Read a row of ' tip ' data into dic
I=0
d={} with
open (' Output_coordinate.txt ') as F: For line in
F.readlines ():
if ' Objects: ' in line:
i=i+1
If ' tip: ' in line:
D[i]=line.strip ()
# Print (i)
# print (d)
If tip is not detected in a frame, the data detected by the previous frame defaults to
D[1]=d[2] for
K in range (1, i+1):
if not d.get (k):
d[k]=d[k-1]
# print (d)
Split tip data into List
Import re
for K, v. in D.items ():
d[k]=re.split (R ' \s+ ', v)
# print (d)
Array reassembly to DICT format
Frames=[]
probs=[]
lx=[]
rx=[]
ly=[]
ry=[]
for K, v. in D.items ():
frames.append (k)
probs.append (v[1])
lx.append (v[2])
rx.append (v[3)) Ly.append (
v[4])
ry.append (v[5))
data = {' Frames ': frames,
' probs ':p robs,
' lx ': lx,
' rx ': Rx,
' ly ': ly,
' ry ': ry,}
Data stored to Dataframe
From pandas import Series, dataframe
frames_num=1590
frame = dataframe (data, columns = [' probs ', ' lx ', ' rx ', ' ly ', ' ry '], index = list (range (1, frames_num+1)))
Frame.index.name = ' frames '
frame.columns.name = ' Coordiante '
Frame.head ()
Coordiante |
probs |
LX |
Rx |
ly |
ry |
Frames |
|
|
|
|
|
1 |
36% |
559 |
811 |
247 |
306 |
2 |
36% |
559 |
811 |
247 |
306 |
3 |
37% |
559 |
811 |
247 |
305 |
4 |
37% |
558 |
810 |
246 |
305 |
5 |
37% |
557 |
810 |
245 |
304 |
Coordinate data saved to text
With open (' Tip_coordinate.txt ', ' W ') as F: to
J in Range (Frames_num):
f.write (lx[j]+ ' +ly[j]+ ' +rx[j]+ ') +ry[ j]+ ' \ n ')
Results of the final processing: