Repository navigation
Expand file tree
/
Copy pathIPaddressClassification.py
More file actions
53 lines (39 loc) · 1.73 KB
/
Copy pathIPaddressClassification.py
File metadata and controls
53 lines (39 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import cv2 #opencv
import urllib.request #para abrir y leer URL
import numpy as np
#PROGRAMA DE CLASIFICACION DE OBJETOS PARA VIDEO EN DIRECCION IP
url = 'http://192.168.137.149/cam-hi.jpg'
#url = 'http://192.168.137.149/'
winName = 'ESP32 CAMERA'
cv2.namedWindow(winName,cv2.WINDOW_AUTOSIZE)
#scale_percent = 80 # percent of original size #para procesamiento de imagen
classNames = []
classFile = 'coco.names'
with open(classFile,'rt') as f:
classNames = f.read().rstrip('\n').split('\n')
configPath = 'ssd_mobilenet_v3_large_coco_2020_01_14.pbtxt'
weightsPath = 'frozen_inference_graph.pb'
net = cv2.dnn_DetectionModel(weightsPath,configPath)
net.setInputSize(320,320)
#net.setInputSize(480,480)
net.setInputScale(1.0/127.5)
net.setInputMean((127.5, 127.5, 127.5))
net.setInputSwapRB(True)
while(1):
imgResponse = urllib.request.urlopen (url) #abrimos el URL
imgNp = np.array(bytearray(imgResponse.read()),dtype=np.uint8)
img = cv2.imdecode (imgNp,-1) #decodificamos
#img = cv2.rotate(img, cv2.ROTATE_90_CLOCKWISE) # vertical
#img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) #black and white
classIds, confs, bbox = net.detect(img,confThreshold=0.5)
print(classIds,bbox)
if len(classIds) != 0:
for classId, confidence,box in zip(classIds.flatten(),confs.flatten(),bbox):
cv2.rectangle(img,box,color=(0,255,0),thickness = 3) #mostramos en rectangulo lo que se encuentra
cv2.putText(img, classNames[classId-1], (box[0]+10,box[1]+30), cv2.FONT_HERSHEY_COMPLEX, 1, (0,255,0),2)
cv2.imshow(winName,img) # mostramos la imagen
#esperamos a que se presione ESC para terminar el programa
tecla = cv2.waitKey(5) & 0xFF
if tecla == 27:
break
cv2.destroyAllWindows()