-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webcam.py
64 lines (56 loc) · 1.63 KB
/
webcam.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
import requests
from bs4 import BeautifulSoup
import time
# import the opencv library
import cv2
url = 'http://127.0.0.1:8000/up'
r = requests.get(url) #url is create form
soup = BeautifulSoup(r.text, 'html.parser')
links = soup.find_all('input')
token = links[0].get('value')
print(token)
# print(soup.find_all('input'))
# print()
jar = requests.cookies.RequestsCookieJar()
jar.set('XSRF-TOKEN', r.cookies['XSRF-TOKEN'])
jar.set('laravel_session', r.cookies['laravel_session'])
data = {
"_token": token
}
# files = {'img': open('test.png','rb')}
# upload = requests.post(url, files=files, data=data, cookies=jar, verify=False)
# print(upload.status_code)
# print(r.text)
# define a video capture object
vid = cv2.VideoCapture(0)
i = 1
previous = time.time()
delta = 0
framerate = 1
while(True):
# Get the current time, increase delta and update the previous variable
current = time.time()
delta += current - previous
previous = current
# Capture the video frame
# by frame
ret, frame = vid.read()
if delta > 2:
delta = 0
# Display the resulting frame
# cv2.imshow('frame', frame)
filename = f'cap_{i}.jpg'
cv2.imwrite(filename, frame)
img = open(f'cap_{i}.jpg', 'rb')
files = {'img': img}
upload = requests.post(url, files=files, data=data, cookies=jar, verify=False)
# the 'q' button is set as the
# quitting button you may use any
# desired button of your choice
# cv2.waitKey(1)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# After the loop release the cap object
vid.release()
# Destroy all the windows
cv2.destroyAllWindows()