I have a python script that uses a usb cam to detect fire with opencv, it worked well until changed to the picamera and now i get this error when i run the code:

File "seeFire.py", line 23, in (grabbed, frame) = video.read() ValueError: too many values to unpack (expected 2)

Here's my code:

import cv2
import numpy as np
from imutils.video import VideoStream
from imutils.video import FPS

#video_file = "video_1.mp4"
#video = cv2.VideoCapture(0)

# initialize the video stream, allow the camera sensor to warm up,
# and initialize the FPS counter
print("[INFO] starting video stream...")
#vs = VideoStream(src=0).start()
video = VideoStream(usePiCamera=True).start()
fps = FPS().start()

while True:
    (grabbed, frame) = video.read()
    frame = imutils.resize(frame, width=400)    
    if not grabbed:

    blur = cv2.GaussianBlur(frame, (21, 21), 0)
    hsv = cv2.cvtColor(blur, cv2.COLOR_BGR2HSV)

    lower = [18, 50, 50]
    upper = [35, 255, 255]
    lower = np.array(lower, dtype="uint8")
    upper = np.array(upper, dtype="uint8")
    mask = cv2.inRange(hsv, lower, upper)

    output = cv2.bitwise_and(frame, hsv, mask=mask)
    no_red = cv2.countNonZero(mask)
    cv2.imshow("output", output)
    #print("output:", frame)
    if int(no_red) > 20000:
        print ('Fire detected')
    if cv2.waitKey(1) & 0xFF == ord('q'):


How do i make it work with my pi cam?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.