-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcamTest.py
83 lines (64 loc) · 2.7 KB
/
camTest.py
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import cv2
import numpy as np
import requests
'''
INFO SECTION
- if you want to monitor raw parameters of ESP32CAM, open the browser and go to http://192.168.x.x/status
- command can be sent through an HTTP get composed in the following way http://192.168.x.x/control?var=VARIABLE_NAME&val=VALUE (check varname and value in status)
'''
# ESP32 URL
URL = "http://192.168.99.95/1024x768.mjpeg"
AWB = True
# Face recognition and opencv setup
cap = cv2.VideoCapture(URL + ":81/stream")
face_classifier = cv2.CascadeClassifier('haarcascade_frontalface_alt.xml') # insert the full path to haarcascade file if you encounter any problem
def set_resolution(url: str, index: int=1, verbose: bool=False):
try:
if verbose:
resolutions = "10: UXGA(1600x1200)\n9: SXGA(1280x1024)\n8: XGA(1024x768)\n7: SVGA(800x600)\n6: VGA(640x480)\n5: CIF(400x296)\n4: QVGA(320x240)\n3: HQVGA(240x176)\n0: QQVGA(160x120)"
print("available resolutions\n{}".format(resolutions))
if index in [10, 9, 8, 7, 6, 5, 4, 3, 0]:
requests.get(url + "/control?var=framesize&val={}".format(index))
else:
print("Wrong index")
except:
print("SET_RESOLUTION: something went wrong")
def set_quality(url: str, value: int=1, verbose: bool=False):
try:
if value >= 10 and value <=63:
requests.get(url + "/control?var=quality&val={}".format(value))
except:
print("SET_QUALITY: something went wrong")
def set_awb(url: str, awb: int=1):
try:
awb = not awb
requests.get(url + "/control?var=awb&val={}".format(1 if awb else 0))
except:
print("SET_QUALITY: something went wrong")
return awb
if __name__ == '__main__':
set_resolution(URL, index=8)
while True:
if cap.isOpened():
ret, frame = cap.read()
if ret:
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
gray = cv2.equalizeHist(gray)
faces = face_classifier.detectMultiScale(gray)
for (x, y, w, h) in faces:
center = (x + w//2, y + h//2)
frame = cv2.rectangle(frame, (x, y), (x + w, y + h), (255, 255, 0), 4)
cv2.imshow("frame", frame)
key = cv2.waitKey(1)
if key == ord('r'):
idx = int(input("Select resolution index: "))
set_resolution(URL, index=idx, verbose=True)
elif key == ord('q'):
val = int(input("Set quality (10 - 63): "))
set_quality(URL, value=val)
elif key == ord('a'):
AWB = set_awb(URL, AWB)
elif key == 27:
break
cv2.destroyAllWindows()
cap.release()