daily pastebin goal
33%
SHARE
TWEET

Untitled

a guest Jan 20th, 2018 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. CODE 3 Error Message:
  2.  
  3. Traceback (most recent call last):
  4.   File "Final.py", line 54, in <module>
  5.     (grabbed, frame) = frame.array
  6. ValueError: too many values to unpack
  7.    
  8. import argparse
  9. import datetime
  10. import imutils
  11. import math
  12.  
  13. import cv2
  14. import numpy as np
  15.  
  16. width = 800
  17.  
  18. textIn = 0
  19. textOut = 0
  20.  
  21. def testIntersectionIn(x, y):
  22.  
  23.     res = -450 * x + 400 * y + 157500  
  24.     if((res >= -550) and  (res < 550)):
  25.         print (str(res))
  26.         return True
  27.     return False
  28.  
  29.  
  30.  
  31. def testIntersectionOut(x, y):
  32.     res = -450 * x + 400 * y + 180000
  33.     if ((res >= -550) and (res <= 550)):
  34.         print (str(res))
  35.         return True
  36.     return False
  37.  
  38. camera = cv2.VideoCapture(0)
  39.  
  40. firstFrame = None
  41.  
  42.  
  43. while True:
  44.  
  45.     (grabbed, frame) = camera.read()
  46.     text = "Unoccupied"
  47.  
  48.  
  49.     if not grabbed:
  50.         break
  51.  
  52.     frame = imutils.resize(frame, width=width)
  53.     gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
  54.     gray = cv2.GaussianBlur(gray, (21, 21), 0)
  55.  
  56.  
  57.     if firstFrame is None:
  58.         firstFrame = gray
  59.         continue
  60.  
  61.  
  62.     frameDelta = cv2.absdiff(firstFrame, gray)
  63.     thresh = cv2.threshold(frameDelta, 25, 255, cv2.THRESH_BINARY)[1]
  64.  
  65.     thresh = cv2.dilate(thresh, None, iterations=2)
  66.     cnts, _ = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
  67.  
  68.     for c in cnts:
  69.         if cv2.contourArea(c) < 12000:
  70.             continue
  71.  
  72.         (x, y, w, h) = cv2.boundingRect(c)
  73.         cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
  74.  
  75.         cv2.line(frame, (width -15500, 0), (width , 300), (250, 0, 1), 2)  #blue line
  76.         cv2.line(frame, (width -15500, 0), (width , 400), (0, 0, 255), 2) #red line
  77.  
  78.  
  79.         rectagleCenterPont = ((x + x + w) /2, (y + y + h) /2)
  80.         cv2.circle(frame, rectagleCenterPont, 1, (0, 0, 255), 5)
  81.  
  82.         if(testIntersectionIn((x + x + w) / 2, (y + y + h) / 2)):
  83.             textIn += 1
  84.  
  85.         if(testIntersectionOut((x + x + w) / 2, (y + y + h) / 2)):
  86.             textOut += 1
  87.  
  88.     if cv2.waitKey(1) & 0xFF == ord('q'):
  89.         break
  90.  
  91.     cv2.putText(frame, "In Toilet: {}".format(str(textIn)), (10, 50),
  92.                 cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 2)
  93.     cv2.putText(frame, "Left Toilet: {}".format(str(textOut)), (10, 70),
  94.                 cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 2)
  95.     cv2.putText(frame, datetime.datetime.now().strftime("%A %d %B %Y %I:%M:%S%p"),
  96.                 (10, frame.shape[0] - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.35, (0, 0, 255), 1)
  97.     cv2.imshow("People Counter", frame)
  98.  
  99. camera.release()
  100. cv2.destroyAllWindows()
  101.    
  102. # import the necessary packages
  103. from picamera.array import PiRGBArray
  104. from picamera import PiCamera
  105. import time
  106. import cv2
  107.  
  108. # initialize the camera and grab a reference to the raw camera capture
  109. camera = PiCamera()
  110. camera.resolution = (640, 480)
  111. camera.framerate = 32
  112. rawCapture = PiRGBArray(camera, size=(640, 480))
  113.  
  114. # allow the camera to warmup
  115. time.sleep(0.1)
  116.  
  117. # capture frames from the camera
  118. for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):
  119.     # grab the raw NumPy array representing the image, then initialize the timestamp
  120.     # and occupied/unoccupied text
  121.     image = frame.array
  122.  
  123.     # show the frame
  124.     cv2.imshow("Frame", image)
  125.     key = cv2.waitKey(1) & 0xFF
  126.  
  127.     # clear the stream in preparation for the next frame
  128.     rawCapture.truncate(0)
  129.  
  130.     # if the `q` key was pressed, break from the loop
  131.     if key == ord("q"):
  132.         break
  133.    
  134. # import the necessary packages
  135. from picamera.array import PiRGBArray
  136. from picamera import PiCamera
  137. import time
  138. import cv2
  139. import numpy as np
  140.  
  141.  
  142. import argparse
  143. import datetime
  144. import imutils
  145. import math
  146.  
  147.  
  148. width = 800
  149.  
  150. textIn = 0
  151. textOut = 0
  152.  
  153. firstFrame = None
  154.  
  155.  
  156. def testIntersectionIn(x, y):
  157.  
  158.     res = -450 * x + 400 * y + 157500   #450 400 157500
  159.     if((res >= -550) and  (res < 550)):
  160.         print (str(res))
  161.         return True
  162.     return False
  163.  
  164.  
  165.  
  166. def testIntersectionOut(x, y):
  167.     res = -450 * x + 400 * y + 180000
  168.     if ((res >= -550) and (res <= 550)):
  169.         print (str(res))
  170.         return True
  171.     return False
  172.  
  173. # initialize the camera and grab a reference to the raw camera capture
  174. camera = PiCamera()
  175. camera.resolution = (640, 480)
  176. camera.framerate = 50
  177. camera.hflip = True
  178.  
  179. rawCapture = PiRGBArray(camera, size=(640, 480))
  180.  
  181. # allow the camera to warmup
  182. time.sleep(0.1)
  183.  
  184. # capture frames from the camera
  185. for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):
  186.  
  187.         (grabbed, frame) = frame.array       #This is the error msg line
  188.         text = "Unoccupied"
  189.  
  190.  
  191.         if not grabbed:
  192.             break
  193.  
  194.         frame = imutils.resize(frame, width=width)
  195.         gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
  196.         gray = cv2.GaussianBlur(gray, (21, 21), 0)
  197.  
  198.  
  199.         if firstFrame is None:
  200.             firstFrame = gray
  201.             continue
  202.  
  203.  
  204.         frameDelta = cv2.absdiff(firstFrame, gray)
  205.         thresh = cv2.threshold(frameDelta, 25, 255, cv2.THRESH_BINARY)[1]
  206.  
  207.         thresh = cv2.dilate(thresh, None, iterations=2)
  208.         cnts, _ = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
  209.  
  210.         for c in cnts:
  211.             if cv2.contourArea(c) < 12000:
  212.                 continue
  213.  
  214.             (x, y, w, h) = cv2.boundingRect(c)
  215.             cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
  216.  
  217.             cv2.line(frame, (width -15500, 0), (width , 300), (250, 0, 1), 2)  #blue line
  218.             cv2.line(frame, (width -15500, 0), (width , 400), (0, 0, 255), 2) #red line
  219.  
  220.  
  221.             rectagleCenterPont = ((x + x + w) /2, (y + y + h) /2)
  222.             cv2.circle(frame, rectagleCenterPont, 1, (0, 0, 255), 5)
  223.  
  224.             if(testIntersectionIn((x + x + w) / 2, (y + y + h) / 2)):
  225.                 textIn += 1
  226.  
  227.             if(testIntersectionOut((x + x + w) / 2, (y + y + h) / 2)):
  228.                 textOut += 1
  229.  
  230.         # clear the stream in preparation for the next frame
  231.         rawCapture.truncate(0)
  232.  
  233.         if cv2.waitKey(1) & 0xFF == ord('q'):
  234.             break
  235.  
  236.         cv2.putText(frame, "In: {}".format(str(textIn)), (10, 50),
  237.                 cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 2)
  238.         cv2.putText(frame, "Out: {}".format(str(textOut)), (10, 70),
  239.                 cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 2)
  240.         cv2.putText(frame, datetime.datetime.now().strftime("%A %d %B %Y %I:%M:%S%p"),
  241.                 (10, frame.shape[0] - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.35, (0, 0, 255), 1)
  242.         cv2.imshow("Counter", frame)
RAW Paste Data
Top