Stop sign detection Development of visualization part part1 Detection and recording of objects * This time, the chair is detected (the model is not made by myself)

at first

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.

Functions you want to achieve

・ 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.

Realization of the function you want to realize

Preface

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. image.png From here, we will actually modify yolov5.

Take some action when something specific is detected.

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.

Outlook for this program

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.

Record the detected time and things.

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.

The part to record the video

It seems to be quite difficult here, so I will turn it next time for the time being. sorry.

To next time

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

Stop sign detection Development of visualization part part1 Detection and recording of objects * This time, the chair is detected (the model is not made by myself)
Stop sign detection Development of visualization part part3 Notify by voice using socket communication when an object is detected
Stop sign detection Development of visualization part part2 Notify another system by socket communication when an object is detected
Stop sign detection Development of visualization part part4 When an object is detected, it is notified by voice using socket communication (multiple volumes)
Stop sign detection Development of visualization part part5 Display what was detected when an object was detected