we have code capture 1 image, , perform image processing techniques.
however, need capture image every 10 seconds. since noobs don't know how it. can pls us.
enclosed whole program inside while loop. program runs fine in first iteration. throws error next time.
getting following error
however, need capture image every 10 seconds. since noobs don't know how it. can pls us.
enclosed whole program inside while loop. program runs fine in first iteration. throws error next time.
code: select all
from picamera.array import pirgbarray picamera import picamera import time import cv2 import numpy np import rpi.gpio gpio while true: # initialize camera , grab reference raw camera capture camera = picamera() camera.resolution = (320, 240) rawcapture = pirgbarray(camera) # allow camera warmup time.sleep(0.1) # grab image camera camera.capture(rawcapture, format="bgr") image = rawcapture.array cv2.imshow("image",image) cv2.imwrite("captured.jpeg",image) image = cv2.imread('captured.jpeg',0) ret,thresh1 = cv2.threshold(image,127,255,cv2.thresh_binary) cv2.imwrite("captured_thresh.jpeg",thresh1) img = cv2.imread("captured_thresh.jpeg") blue_min = np.array([0, 0, 0], np.uint8) blue_max = np.array([50, 50, 50], np.uint8) dst = cv2.inrange(img, blue_min, blue_max) no_blue = cv2.countnonzero(dst) if no_blue>1000000: gpio.setmode(gpio.bcm) gpio.setup(14,gpio.out) gpio.output(14,gpio.high) print('the number of blue pixels is: ' + str(no_blue)) time.sleep(10)
code: select all
the number of blue pixels is: 66978 mmal: mmal_vc_component_enable: failed enable component: enospc traceback (most recent call last): file "count1.py", line 9, in <module> camera = picamera() file "/home/pi/.virtualenvs/cv/local/lib/python3.4/site-packages/picamera/camera.py", line 488, in __init__ self.stereo_modes[stereo_mode], stereo_decimate) file "/home/pi/.virtualenvs/cv/local/lib/python3.4/site-packages/picamera/camera.py", line 620, in _init_camera prefix="camera component couldn't enabled") file "/home/pi/.virtualenvs/cv/local/lib/python3.4/site-packages/picamera/exc.py", line 191, in mmal_check raise picamerammalerror(status, prefix) picamera.exc.picamerammalerror: camera component couldn't enabled: out of resources (other memory)
try moving code before while loop
suspect camera doesn't being initialized twice.
code: select all
camera = picamera() camera.resolution = (320, 240) rawcapture = pirgbarray(camera)
suspect camera doesn't being initialized twice.
raspberrypi
Comments
Post a Comment