Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CODE 3 Error Message:
- Traceback (most recent call last):
- File "Final.py", line 54, in <module>
- (grabbed, frame) = frame.array
- ValueError: too many values to unpack
- import argparse
- import datetime
- import imutils
- import math
- import cv2
- import numpy as np
- width = 800
- textIn = 0
- textOut = 0
- def testIntersectionIn(x, y):
- res = -450 * x + 400 * y + 157500
- if((res >= -550) and (res < 550)):
- print (str(res))
- return True
- return False
- def testIntersectionOut(x, y):
- res = -450 * x + 400 * y + 180000
- if ((res >= -550) and (res <= 550)):
- print (str(res))
- return True
- return False
- camera = cv2.VideoCapture(0)
- firstFrame = None
- while True:
- (grabbed, frame) = camera.read()
- text = "Unoccupied"
- if not grabbed:
- break
- frame = imutils.resize(frame, width=width)
- gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
- gray = cv2.GaussianBlur(gray, (21, 21), 0)
- if firstFrame is None:
- firstFrame = gray
- continue
- frameDelta = cv2.absdiff(firstFrame, gray)
- thresh = cv2.threshold(frameDelta, 25, 255, cv2.THRESH_BINARY)[1]
- thresh = cv2.dilate(thresh, None, iterations=2)
- cnts, _ = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
- for c in cnts:
- if cv2.contourArea(c) < 12000:
- continue
- (x, y, w, h) = cv2.boundingRect(c)
- cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
- cv2.line(frame, (width -15500, 0), (width , 300), (250, 0, 1), 2) #blue line
- cv2.line(frame, (width -15500, 0), (width , 400), (0, 0, 255), 2) #red line
- rectagleCenterPont = ((x + x + w) /2, (y + y + h) /2)
- cv2.circle(frame, rectagleCenterPont, 1, (0, 0, 255), 5)
- if(testIntersectionIn((x + x + w) / 2, (y + y + h) / 2)):
- textIn += 1
- if(testIntersectionOut((x + x + w) / 2, (y + y + h) / 2)):
- textOut += 1
- if cv2.waitKey(1) & 0xFF == ord('q'):
- break
- cv2.putText(frame, "In Toilet: {}".format(str(textIn)), (10, 50),
- cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 2)
- cv2.putText(frame, "Left Toilet: {}".format(str(textOut)), (10, 70),
- cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 2)
- cv2.putText(frame, datetime.datetime.now().strftime("%A %d %B %Y %I:%M:%S%p"),
- (10, frame.shape[0] - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.35, (0, 0, 255), 1)
- cv2.imshow("People Counter", frame)
- camera.release()
- cv2.destroyAllWindows()
- # import the necessary packages
- from picamera.array import PiRGBArray
- from picamera import PiCamera
- import time
- import cv2
- # initialize the camera and grab a reference to the raw camera capture
- camera = PiCamera()
- camera.resolution = (640, 480)
- camera.framerate = 32
- rawCapture = PiRGBArray(camera, size=(640, 480))
- # allow the camera to warmup
- time.sleep(0.1)
- # capture frames from the camera
- for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):
- # grab the raw NumPy array representing the image, then initialize the timestamp
- # and occupied/unoccupied text
- image = frame.array
- # show the frame
- cv2.imshow("Frame", image)
- key = cv2.waitKey(1) & 0xFF
- # clear the stream in preparation for the next frame
- rawCapture.truncate(0)
- # if the `q` key was pressed, break from the loop
- if key == ord("q"):
- break
- # import the necessary packages
- from picamera.array import PiRGBArray
- from picamera import PiCamera
- import time
- import cv2
- import numpy as np
- import argparse
- import datetime
- import imutils
- import math
- width = 800
- textIn = 0
- textOut = 0
- firstFrame = None
- def testIntersectionIn(x, y):
- res = -450 * x + 400 * y + 157500 #450 400 157500
- if((res >= -550) and (res < 550)):
- print (str(res))
- return True
- return False
- def testIntersectionOut(x, y):
- res = -450 * x + 400 * y + 180000
- if ((res >= -550) and (res <= 550)):
- print (str(res))
- return True
- return False
- # initialize the camera and grab a reference to the raw camera capture
- camera = PiCamera()
- camera.resolution = (640, 480)
- camera.framerate = 50
- camera.hflip = True
- rawCapture = PiRGBArray(camera, size=(640, 480))
- # allow the camera to warmup
- time.sleep(0.1)
- # capture frames from the camera
- for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):
- (grabbed, frame) = frame.array #This is the error msg line
- text = "Unoccupied"
- if not grabbed:
- break
- frame = imutils.resize(frame, width=width)
- gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
- gray = cv2.GaussianBlur(gray, (21, 21), 0)
- if firstFrame is None:
- firstFrame = gray
- continue
- frameDelta = cv2.absdiff(firstFrame, gray)
- thresh = cv2.threshold(frameDelta, 25, 255, cv2.THRESH_BINARY)[1]
- thresh = cv2.dilate(thresh, None, iterations=2)
- cnts, _ = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
- for c in cnts:
- if cv2.contourArea(c) < 12000:
- continue
- (x, y, w, h) = cv2.boundingRect(c)
- cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
- cv2.line(frame, (width -15500, 0), (width , 300), (250, 0, 1), 2) #blue line
- cv2.line(frame, (width -15500, 0), (width , 400), (0, 0, 255), 2) #red line
- rectagleCenterPont = ((x + x + w) /2, (y + y + h) /2)
- cv2.circle(frame, rectagleCenterPont, 1, (0, 0, 255), 5)
- if(testIntersectionIn((x + x + w) / 2, (y + y + h) / 2)):
- textIn += 1
- if(testIntersectionOut((x + x + w) / 2, (y + y + h) / 2)):
- textOut += 1
- # clear the stream in preparation for the next frame
- rawCapture.truncate(0)
- if cv2.waitKey(1) & 0xFF == ord('q'):
- break
- cv2.putText(frame, "In: {}".format(str(textIn)), (10, 50),
- cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 2)
- cv2.putText(frame, "Out: {}".format(str(textOut)), (10, 70),
- cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 2)
- cv2.putText(frame, datetime.datetime.now().strftime("%A %d %B %Y %I:%M:%S%p"),
- (10, frame.shape[0] - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.35, (0, 0, 255), 1)
- cv2.imshow("Counter", frame)
Add Comment
Please, Sign In to add comment