image - RaspberryPi camera stream processing with Python 2.7 -


i found following code here catching video stream raspberrypi camera.

now want process video stream (e.g. finding blob or display video).

for purpose need catch content of video array, e.g. name frame in example:

cv2.imshow('stream', frame) 

i tried converting array like

frame = self.stream.array 

but not getting work.

the output tells me cannot create array stream:

file "raspberry.py", line 35, in run     frame = self.stream.array   #creating array stream attributeerror: '_io.bytesio' object has no attribute 'array' 

any ideas how solve it?

code:

import io import time import threading import picamera  # create pool of image processors done = false lock = threading.lock() pool = []  class imageprocessor(threading.thread):     def __init__(self):         super(imageprocessor, self).__init__()         self.stream = io.bytesio()         self.event = threading.event()         self.terminated = false         self.start()      def run(self):         # method runs in separate thread         global done         while not self.terminated:             # wait image written stream             if self.event.wait(1):                 try:                     self.stream.seek(0)                      frame = self.stream.array   #creating array stream                                         cv2.imshow('stream', frame) #should show livestream                        # read image , processing on                     #image.open(self.stream)                     #...                     #...                     # set done true if want script terminate                     # @ point                     #done=true                 finally:                     # reset stream , event                     self.stream.seek(0)                     self.stream.truncate()                     self.event.clear()                     # return ourselves pool                     lock:                         pool.append(self)  def streams():     while not done:         lock:             if pool:                 processor = pool.pop()             else:                 processor = none         if processor:             yield processor.stream             processor.event.set()         else:             # when pool starved, wait while refill             time.sleep(0.1)  picamera.picamera() camera:     pool = [imageprocessor() in range(4)]     camera.resolution = (640, 480)     camera.framerate = 30     camera.start_preview()     time.sleep(2)     camera.capture_sequence(streams(), use_video_port=true)  # shut down processors in orderly fashion while pool:     lock:         processor = pool.pop()     processor.terminated = true     processor.join() 

the base picamera package doesn't provide array capability prevent lengthy numpy compile on raspberry pi if don't need it.

to install numpy array support, try:

pip install --user "picamera[array]" 

Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -