Last time, I wrote a program to notify by voice when a chair is detected by focusing on the smartphone. However, even if something other than a book is detected, it was not possible to notify it with the previous program. So this time, the smartphone It is a program that tries to notify you when something other than that is detected.
When an object is detected on Yolov5 ➡ Socket communication is performed. ➡ Sound is played when socket communication is received.
(The socket notification part is made into a function)
detect.py
def socket1():
host = "192.168.10.4" #IP address of the server launched by Processing
port = 10001 #Port number set in Processing
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s2:
s2.connect(('127.0.0.1', 50007))
BUFFER_SIZE=1024
data1='1'
s2.send(data1.encode())
print(s2.recv(BUFFER_SIZE).decode())
def socket2():
host = "192.168.10.4" #IP address of the server launched by Processing
port = 10001 #Port number set in Processing
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s2:
s2.connect(('127.0.0.1', 50007))
BUFFER_SIZE=1024
data1='2'
s2.send(data1.encode())
print(s2.recv(BUFFER_SIZE).decode())
(Recognition part)
detect.py
if label1=="cell phone":
print("I found a smartphone")
socket1()
with open('daystext/'+str(d_today)+'.txt', 'a') as f:
dt_now = datetime.datetime.now()
f.write(str(dt_now)+"I found a smartphone"+"\n")
if label1=="book":
print("I found a book")
socket2()
with open('daystext/'+str(d_today)+'.txt', 'a') as f:
dt_now = datetime.datetime.now()
f.write(str(dt_now)+"I found a book"+"\n")
Server part
server.py
#Create socket server
from playsound import playsound
import socket
cont=1
# AF =Means IPv4
# TCP/For IP, SOCK_Use STREAM
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
#Specify IP address and port
s.bind(('127.0.0.1', 50007))
#1 connection
s.listen(1)
#Wait until you connect
while True:
#When someone accesses it, enter the connection and address
conn, addr = s.accept()
with conn:
while True:
#Receive data
data = conn.recv(1024)
if not data:
break
else:
data2=str(data)
data3=(data2.replace('b', ''))
conn.sendall(b'Received: ' + data)
if data3 == "'1'":
playsound('2.wav')
if data3 == "'2'":
playsound('3.wav')
The specification is that when you send a socket, it will be sent twice, and you will talk twice. The challenge is to improve this in the future.
・ Since this program has some problems left, it is necessary to improve the program in order to solve the problems in the future. Therefore, write a program to improve this in the future. I'm going. ・ We are planning to cooperate with GPS in order to stop this system and adapt it to sign detection to develop a better system. Next time I will write about this area, but next time it will be a little heavy, so the update may be interrupted a little, but thank you.
Recommended Posts