Last time, I wrote about the learning model of signboard detection. This time, I will write a program to actually detect and visualize it using the detected model.
・ Save the estimated video using the video with yolov5. -Visualize the detection on another system when it is detected. ・ Record the detected time and things. I would like to actually realize this area.
Actually, I have made a simple one using tensorflow, python, and processing before, so I would like to write it by diverting that program. The program is posted on github. * I forgot how to make a learning model and how to run that model with the label program. URL https://github.com/S-mishina/Personal-estimation The sketch_190628a / sketch_190628a.pde of this program is the visualization part. I will also post the entire system here. From here, we will actually modify yolov5.
This time I wanted to implement it easily, so when I found something I wanted to detect, I detected it. I made a program that issues a notification.
detect.py
label1 = str((names[int(c)])) # add to string
if label1=="chair":
print("Detected a chair.")
Well, it's a simple code, so anyone can understand it, but for the time being, when yolo detects an object, it seems that what is detected is probably recorded at names [int (c)]. So I converted it to a string. If it matches what you want to detect, it will be detected OK, and if it does not match, it will be detected NG.
As a prospect of this implemented function, I would like to connect it to a system that can visualize whether or not it is detected by socket communication instead of character-based.
This time the purpose is to detect the chair, so I would like to write a program that logs when the chair is detected. Import part
detect.py
import pathlib
File creation part
detect.py
#Initialization
set_logging()
device = select_device(opt.device)
if os.path.exists(out):
shutil.rmtree(out) #Delete the output folder
os.makedirs(out) #Create a new output folder
d_today = datetime.date.today()
f = pathlib.Path('daystext/'+ str(d_today) +'.txt')
f.touch()
Recording part
detect.py
label1 = str((names[int(c)])) # add to string
if label1=="chair":
print("Detected a chair.")
with open('daystext/'+str(d_today)+'.txt', 'a') as f:
dt_now = datetime.datetime.now()
f.write(str(dt_now)+"Detected a chair."+"\n")
What was recorded
2020-10-12 17:27:42.914446 Detected a chair.
2020-10-12 17:27:42.941445 Detected chair.
2020-10-12 17:27:42.968444 Detected chair.
2020-10-12 17:27:42.996444 Detected chair.
2020-10-12 17:27:43.024443 Detected chair.
2020-10-12 17:27:43.051442 Detected a chair.
2020-10-12 17:27:43.079441 A chair was detected.
2020-10-12 17:27:43.108440 Detected chair.
2020-10-12 17:27:43.135454 Detected chair.
2020-10-12 17:27:43.162439 Detected chair.
2020-10-12 17:27:43.190452 Detected chair.
2020-10-12 17:27:43.218437 Detected chair.
2020-10-12 17:27:43.245436 Chair detected.
2020-10-12 17:27:43.274445 Detected chair.
2020-10-12 17:27:43.301448 Detected chair.
2020-10-12 17:27:43.329434 Detected a chair.
2020-10-12 17:27:43.357433 Detected a chair.
2020-10-12 17:27:43.384432 Detected chair.
It will be recorded like this.
It seems to be quite difficult here, so I will turn it next time for the time being. sorry.
This time, I mainly wrote a program that improves the default program of yolov5 and records it after detecting an object. Next time, I would like to write the part to be visualized concretely, so thank you.
Recommended Posts