|
import cv2 |
|
import numpy as np |
|
import socket |
|
import sys |
|
import pickle |
|
import struct |
|
import pygame |
|
|
|
|
|
pygame.mixer.init() |
|
|
|
|
|
label_sound_dict = { |
|
"person": "a.mp3", |
|
"cell_phone": "b.mp3", |
|
} |
|
|
|
cap = cv2.VideoCapture(0) |
|
clientsocket = socket.socket(socket.AF_INET,socket.SOCK_STREAM) |
|
clientsocket.connect(('localhost',8089)) |
|
|
|
|
|
label_count = 0 |
|
current_label = None |
|
|
|
while True: |
|
ret, frame = cap.read() |
|
|
|
data = pickle.dumps(frame) |
|
|
|
|
|
message_size = struct.pack("L", len(data)) |
|
|
|
|
|
clientsocket.sendall(message_size + data) |
|
|
|
|
|
response = clientsocket.recv(1024) |
|
decoded_response = response.decode() |
|
print(decoded_response) |
|
|
|
|
|
if "[Scarecrow]: " in decoded_response: |
|
label = decoded_response.split("[Scarecrow]: ")[1] |
|
if label in label_sound_dict: |
|
if label != current_label: |
|
|
|
current_label = label |
|
label_count = 1 |
|
else: |
|
|
|
label_count += 1 |
|
if label_count >= 5: |
|
sound_file = label_sound_dict[label] |
|
sound = pygame.mixer.Sound(sound_file) |
|
sound.play() |
|
label_count = 0 |
|
else: |
|
current_label = None |
|
label_count = 0 |
|
|