Advertisement
Guest User

lombakksi

a guest
Mar 30th, 2020
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.92 KB | None | 0 0
  1. import cv2
  2. import os
  3. import shutil
  4. import datetime
  5. import requests
  6.  
  7. key = cv2.waitKey(1)
  8. webcam = cv2.VideoCapture(0)
  9. name = datetime.datetime.now()
  10. filename = str(name)+'.jpg'
  11.  
  12. def record(nf):
  13.     while True:
  14.         check, frame = webcam.read()
  15.         print(check) #prints true as long as the webcam is running
  16.         print(frame) #prints matrix values of each framecd
  17.         cv2.imshow("Capturing", frame)
  18.         key = cv2.waitKey(1)
  19.         if key == ord('s'):
  20.             url = "http://localhost:8000/upload"
  21.             cv2.imwrite(nf, frame)
  22.             image = open(nf, 'rb')
  23.             files = {'file': image}
  24.             r = requests.post(url, files=files)
  25.             print(r)
  26.             os.remove(nf)
  27.             break
  28.         elif key == ord('q'):
  29.             print("Turning off camera.")
  30.             webcam.release()
  31.             print("Camera off.")
  32.             break
  33.  
  34. record(filename)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement