Python picamera.array.PiRGBArray() Examples
The following are 25
code examples of picamera.array.PiRGBArray().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
picamera.array
, or try the search function
.
Example #1
Source File: pi-timolo81.py From pi-timolo with MIT License | 7 votes |
def __init__(self, resolution=(CAMERA_WIDTH, CAMERA_HEIGHT), framerate=CAMERA_FRAMERATE, rotation=0, hflip=False, vflip=False): # initialize the camera and stream try: self.camera = PiCamera() except: print("ERROR - PiCamera Already in Use by Another Process") print("INFO - Exit %s" % progName) quit() self.camera.resolution = resolution self.camera.framerate = framerate self.camera.hflip = hflip self.camera.vflip = vflip self.camera.rotation = rotation self.rawCapture = PiRGBArray(self.camera, size=resolution) self.stream = self.camera.capture_continuous(self.rawCapture, format="bgr", use_video_port=True) # initialize the frame and the variable used to indicate # if the thread should be stopped self.frame = None self.stopped = False
Example #2
Source File: balloon_video.py From ardupilot-balloon-finder with GNU General Public License v3.0 | 6 votes |
def capture_image(self): # check camera is initialised self.init_camera() # use webcam if self.camera_type == 0: success_flag, image=self.camera.read() return image # use rpi camera if self.camera_type == 1: image_array = PiRGBArray(self.camera) self.camera.capture(image_array, format="bgr") image = image_array.array return image # open_video_writer - begin writing to video file
Example #3
Source File: pi-timolo.py From pi-timolo with MIT License | 6 votes |
def __init__(self, resolution=(CAMERA_WIDTH, CAMERA_HEIGHT), framerate=CAMERA_FRAMERATE, rotation=0, hflip=False, vflip=False): # initialize the camera and stream try: self.camera = PiCamera() except: logging.error("PiCamera Already in Use by Another Process") logging.error("Exiting %s Due to Error", progName) exit(1) self.camera.resolution = resolution self.camera.framerate = framerate self.camera.hflip = hflip self.camera.vflip = vflip self.camera.rotation = rotation self.rawCapture = PiRGBArray(self.camera, size=resolution) self.stream = self.camera.capture_continuous(self.rawCapture, format="bgr", use_video_port=True) # initialize the frame and the variable used to indicate # if the thread should be stopped self.thread = None # Initialize thread self.frame = None self.stopped = False
Example #4
Source File: pi-timolo81.py From pi-timolo with MIT License | 6 votes |
def getStreamImage(isDay): # Capture an image stream to memory based on daymode with picamera.PiCamera() as camera: camera.resolution = (testWidth, testHeight) with picamera.array.PiRGBArray(camera) as stream: if isDay: camera.exposure_mode = 'auto' camera.awb_mode = 'auto' time.sleep(motionCamSleep) # sleep so camera can get AWB else: # use variable framerate_range for Low Light motion image stream camera.framerate_range = (Fraction(1, 6), Fraction(30, 1)) time.sleep(2) # Give camera time to measure AWB camera.iso = nightMaxISO camera.capture(stream, format='rgb', use_video_port=useVideoPort) camera.close() return stream.array #-----------------------------------------------------------------------------------------------
Example #5
Source File: pi-timolo.py From pi-timolo with MIT License | 6 votes |
def getStreamImage(isDay): # Capture an image stream to memory based on daymode with picamera.PiCamera() as camera: camera.resolution = (testWidth, testHeight) with picamera.array.PiRGBArray(camera) as stream: if isDay: camera.exposure_mode = 'auto' camera.awb_mode = 'auto' time.sleep(motionCamSleep) # sleep so camera can get AWB else: # use variable framerate_range for Low Light motion image stream camera.framerate_range = (Fraction(1, 6), Fraction(30, 1)) time.sleep(2) # Give camera time to measure AWB camera.iso = nightMaxISO camera.capture(stream, format='rgb', use_video_port=useVideoPort) camera.close() return stream.array #-----------------------------------------------------------------------------------------------
Example #6
Source File: mypivideostream.py From hardware_demo with MIT License | 6 votes |
def __init__(self, resolution=(640, 480), framerate=32, save_image_interval=1): ''' @param save_image_interval, interval in sec to save imave ''' # initialize the camera and stream self.camera = PiCamera() self.camera.resolution = resolution self.camera.framerate = framerate self.rawCapture = PiRGBArray(self.camera, size=resolution) self.stream = self.camera.capture_continuous(self.rawCapture, format="bgr", use_video_port=True) # initialize the frame and the variable used to indicate # if the thread should be stopped self.frame = None self.rects = [] # list of matching faces self.stopped = False
Example #7
Source File: camera.py From pi-tracking-telescope with MIT License | 6 votes |
def __init__(self): # Using OpenCV to capture from device 0. If you have trouble capturing # from a webcam, comment the line below out and use a video file # instead. #self.video = cv2.VideoCapture(0) self.camera = PiCamera() #self.rawCapture = PiRGBArray(self.camera) self.camera.resolution = (640, 480) self.camera.framerate = 32 self.rawCapture = PiRGBArray(self.camera, size=(640, 480)) # allow the camera to warmup time.sleep(0.1) # If you decide to use video.mp4, you must have this file in the folder # as the main.py. # self.video = cv2.VideoCapture('video.mp4')
Example #8
Source File: camera.py From pi-tracking-telescope with MIT License | 6 votes |
def setupRpiCam(self): # import the necessary packages from picamera.array import PiRGBArray from picamera import PiCamera # initialize the camera and grab a reference to the raw camera capture camera = PiCamera() camera.resolution = (self.width, self.height) camera.framerate = self.fps camera.crop = (0.0, 0.0, 1.0, 1.0) self.camera = camera self.rawCapture = PiRGBArray(camera, size=(self.width, self.height)) self.rgb = bytearray(self.width * self.height * 3) self.yuv = bytearray(self.width * self.height * 3 / 2) # wait for camera to warm up time.sleep(0.1)
Example #9
Source File: capture.py From rpi-vision with MIT License | 6 votes |
def __init__(self, resolution=(320, 240), framerate=24, vflip=True, hflip=True): self.camera = PiCamera() self.camera.resolution = resolution self.camera.framerate = framerate self.camera.vflip = vflip self.camera.hflip = hflip self.camera.rotation = 270 self.data_container = PiRGBArray(self.camera, size=resolution) self.stream = self.camera.capture_continuous( self.data_container, format="bgr", use_video_port=True ) self.frame = None self.stopped = False print('starting camera preview') self.camera.start_preview()
Example #10
Source File: camera_pi.py From object-detection with MIT License | 5 votes |
def ObjectTracking(self): detector = Detector() myiter = glob.iglob(os.path.join(IMAGE_FOLDER, '**', '*.jpg'), recursive=True) newdict = reduce(lambda a, b: reduce_tracking(a,b), myiter, dict()) startID = max(map(int, newdict.keys()), default=0) + 1 ct = CentroidTracker(startID=startID) with PiCamera() as camera: camera.resolution = (1280, 960) # twice height and widht camera.rotation = int(str(os.environ['CAMERA_ROTATION'])) camera.framerate = 10 with PiRGBArray(camera, size=(WIDTH, HEIGHT)) as output: while True: camera.capture(output, 'bgr', resize=(WIDTH, HEIGHT)) img = output.array result = detector.prediction(img) df = detector.filter_prediction(result, img) img = detector.draw_boxes(img, df) boxes = df[['x1', 'y1', 'x2', 'y2']].values previous_object_ID = ct.nextObjectID objects = ct.update(boxes) if len(boxes) > 0 and (df['class_name'].str.contains('person').any()) and previous_object_ID in list(objects.keys()): for (objectID, centroid) in objects.items(): text = "ID {}".format(objectID) cv2.putText(img, text, (centroid[0] - 10, centroid[1] - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2) cv2.circle(img, (centroid[0], centroid[1]), 4, (0, 255, 0), -1) day = datetime.now().strftime("%Y%m%d") directory = os.path.join(IMAGE_FOLDER, 'pi', day) if not os.path.exists(directory): os.makedirs(directory) ids = "-".join(list([str(i) for i in objects.keys()])) hour = datetime.now().strftime("%H%M%S") filename_output = os.path.join( directory, "{}_person_{}_.jpg".format(hour, ids) ) cv2.imwrite(filename_output, img) time.sleep(0.300)
Example #11
Source File: CaptureDeviceRPiCamera.py From rpi-course with MIT License | 5 votes |
def __init__(self, frameSize, frameRate): camera = PiCamera() camera.resolution = frameSize camera.framerate = frameRate self.rawCapture = PiRGBArray(camera, size=frameSize) self.bufferIter = camera.capture_continuous(self.rawCapture, format="bgr", use_video_port=True)
Example #12
Source File: CaptureDeviceRPiCamera.py From rpi-course with MIT License | 5 votes |
def __init__(self, frameSize, frameRate): camera = PiCamera() camera.resolution = frameSize camera.framerate = frameRate self.rawCapture = PiRGBArray(camera, size=frameSize) self.bufferIter = camera.capture_continuous(self.rawCapture, format="bgr", use_video_port=True)
Example #13
Source File: camera.py From RaspberryCar with MIT License | 5 votes |
def CameraInit(self): # 初始化PiCamera self.camera = PiCamera() self.camera.resolution = (640, 480) self.camera.framerate = 32 rawCapture = PiRGBArray(self.camera, size=(640, 480)) rawCapture.truncate(0) time.sleep(2) # wait for camera starting 相机需要时间预热 return self.camera, rawCapture
Example #14
Source File: camera_old.py From RaspberryCar with MIT License | 5 votes |
def __init__(self): # initialize the camera and grab a reference to the raw camera capture HOST = '192.168.12.60' PORT = 8000 self.server = socket.socket(socket.AF_INET,socket.SOCK_DGRAM) self.server.connect((HOST,PORT)) self.camera = PiCamera() self.camera.resolution = (640, 480) self.camera.framerate = 32 self.rawCapture = PiRGBArray(self.camera, size=(640, 480)) time.sleep(0.1) # time for camera start
Example #15
Source File: camera.py From rpi-deep-pantilt with MIT License | 5 votes |
def __init__(self, resolution=(320, 240), framerate=24, vflip=False, hflip=False, rotation=0, max_workers=2 ): self.camera = PiCamera() self.camera.resolution = resolution self.camera.framerate = framerate self.camera.vflip = vflip self.camera.hflip = hflip self.camera.rotation = rotation self.overlay = None self.data_container = PiRGBArray(self.camera, size=resolution) self.stream = self.camera.capture_continuous( self.data_container, format="rgb", use_video_port=True ) self.overlay_buff = None self.frame = None self.stopped = False logging.info('starting camera preview') self.camera.start_preview()
Example #16
Source File: video_cam.py From ncappzoo with MIT License | 5 votes |
def frame(self): """ Get frame from camera """ if self.camera_type == "camerapi": self.rawCapture = PiRGBArray(self.camera, size=(self.cam_width, self.cam_height)) framesArray = self.camera.capture_continuous(self.rawCapture, format="bgr", use_video_port=True) return next(framesArray).array elif self.camera_type == "usb": assert self.camera.isOpened(), "Couldn't open Camera" success, orig_frame = self.camera.read() assert success, "Can't snap image" return orig_frame
Example #17
Source File: pivideostream.py From imutils with MIT License | 5 votes |
def __init__(self, resolution=(320, 240), framerate=32, **kwargs): # initialize the camera self.camera = PiCamera() # set camera parameters self.camera.resolution = resolution self.camera.framerate = framerate # set optional camera parameters (refer to PiCamera docs) for (arg, value) in kwargs.items(): setattr(self.camera, arg, value) # initialize the stream self.rawCapture = PiRGBArray(self.camera, size=resolution) self.stream = self.camera.capture_continuous(self.rawCapture, format="bgr", use_video_port=True) # initialize the frame and the variable used to indicate # if the thread should be stopped self.frame = None self.stopped = False
Example #18
Source File: picam.py From MMM-Face-Reco-DNN with MIT License | 5 votes |
def __init__(self, resolution=(320, 240), framerate=32, rotation=0): # initialize the camera and stream self.camera = PiCamera() self.camera.resolution = resolution self.camera.framerate = framerate self.camera.rotation = rotation self.rawCapture = PiRGBArray(self.camera, size=resolution) self.stream = self.camera.capture_continuous(self.rawCapture, format="bgr", use_video_port=True) # initialize the frame and the variable used to indicate # if the thread should be stopped self.frame = None self.stopped = False
Example #19
Source File: camera.py From SmartBin with MIT License | 5 votes |
def __init__(self, resolution=(320, 240), framerate=32): # initialize the camera and stream self.camera = PiCamera() self.camera.resolution = resolution self.camera.framerate = framerate self.camera.vflip = True self.camera.hflip = True self.rawCapture = PiRGBArray(self.camera, size=resolution) self.stream = self.camera.capture_continuous( self.rawCapture, format="bgr", use_video_port=True) # initialize the frame and the variable used to indicate # if the thread should be stopped self.frame = None self.stopped = False
Example #20
Source File: Camera.py From Facial-Recognition-Attendance-System with MIT License | 5 votes |
def capture_image(self, usingPiCamera=IS_RASPBERRY_PI): if usingPiCamera: from picamera.array import PiRGBArray from picamera import PiCamera with PiCamera() as camera: rawCapture = PiRGBArray(camera) # allow the camera to warmup time.sleep(0.1) # grab an image from the camera camera.capture(rawCapture, format="rgb") image = rawCapture.array image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) return image else: # Number of frames to throw away while the camera adjusts to light levels ramp_frames = 1 self.camera = cv2.VideoCapture(CAMERA_PORT) _, im = self.camera.read() [self.camera.read() for _ in range(ramp_frames)] # print("Taking image...") _, camera_capture = self.camera.read() del self.camera return camera_capture
Example #21
Source File: pi-timolo.py From pi-timolo with MIT License | 5 votes |
def __init__(self, resolution=(CAMERA_WIDTH, CAMERA_HEIGHT), framerate=CAMERA_FRAMERATE, rotation=0, hflip=False, vflip=False): # initialize the camera and stream self.camera = PiCamera() self.camera.resolution = resolution self.camera.framerate = framerate self.camera.hflip = hflip self.camera.vflip = vflip self.camera.rotation = rotation self.rawCapture = PiRGBArray(self.camera, size=resolution) self.stream = self.camera.capture_continuous(self.rawCapture, format="bgr", use_video_port=True) # initialize the frame and the variable used to indicate # if the thread should be stopped self.frame = None self.stopped = False
Example #22
Source File: camera_pi.py From object-detection with MIT License | 5 votes |
def CaptureContinous(self): detector = Detector() with PiCamera() as camera: camera.resolution = (1280, 960) # twice height and widht camera.rotation = int(str(os.environ['CAMERA_ROTATION'])) camera.framerate = 10 with PiRGBArray(camera, size=(WIDTH, HEIGHT)) as output: camera.capture(output, 'bgr', resize=(WIDTH, HEIGHT)) image = output.array result = detector.prediction(image) df = detector.filter_prediction(result, image) if len(df) > 0: if (df['class_name'] .str .contains('person|bird|cat|wine glass|cup|sandwich') .any()): day = datetime.now().strftime("%Y%m%d") directory = os.path.join(IMAGE_FOLDER, 'pi', day) if not os.path.exists(directory): os.makedirs(directory) image = detector.draw_boxes(image, df) classes = df['class_name'].unique().tolist() hour = datetime.now().strftime("%H%M%S") filename_output = os.path.join( directory, "{}_{}_.jpg".format(hour, "-".join(classes)) ) cv2.imwrite(filename_output, image)
Example #23
Source File: sub_process.py From ethoscope with GNU General Public License v3.0 | 4 votes |
def run(self): try: with PiCamera() as capture: capture.resolution = self._target_resolution capture.framerate = self._target_fps raw_capture = PiRGBArray(capture, size=self._target_resolution) for frame in capture.capture_continuous(raw_capture, format="bgr", use_video_port=True): if not self._stop_queue.empty(): logging.info("The stop queue is not empty. Stop acquiring frames") self._stop_queue.get() self._stop_queue.task_done() logging.info("Stop Task Done") break raw_capture.truncate(0) # out = np.copy(frame.array) out = cv2.cvtColor(frame.array,cv2.COLOR_BGR2GRAY) self._queue.put(out) finally: self._stop_queue.close() self._queue.close() logging.info("Camera Frame grabber stopped acquisition cleanly") # # try: # capture = cv2.VideoCapture("/lud/validation_2fps.mp4") # while True: # if not self._stop_queue.empty(): # logging.info("The stop queue is not empty. Stop acquiring frames") # self._stop_queue.get() # self._stop_queue.task_done() # logging.info("Stop Task Done") # break # # _, frame = capture.read() # out = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY) # self._queue.put(out) # finally: # capture.release() # # # self._stop_queue.close() # self._queue.close() # logging.info("Camera Frame grabber stopped acquisition cleanly")
Example #24
Source File: server.py From ethoscope with GNU General Public License v3.0 | 4 votes |
def __init__(self, target_fps=10, target_resolution=(960,720), *args, **kwargs): logging.info("Initialising camera") w,h = target_resolution self.capture = PiCamera() self.capture.resolution = target_resolution if not isinstance(target_fps, int): raise EthoscopeException("FPS must be an integer number") self.capture.framerate = target_fps self._raw_capture = PiRGBArray(self.capture, size=target_resolution) self._target_fps = float(target_fps) self._warm_up() self._cap_it = self._frame_iter() im = next(self._cap_it) if im is None: raise EthoscopeException("Error whist retrieving video frame. Got None instead. Camera not plugged?") self._frame = im if len(im.shape) < 2: raise EthoscopeException("The camera image is corrupted (less that 2 dimensions)") self._resolution = (im.shape[1], im.shape[0]) if self._resolution != target_resolution: if w > 0 and h > 0: logging.warning('Target resolution "%s" could NOT be achieved. Effective resolution is "%s"' % (target_resolution, self._resolution )) else: logging.info('Maximal effective resolution is "%s"' % str(self._resolution)) super(OurPiCamera, self).__init__(*args, **kwargs) self._start_time = time.time() logging.info("Camera initialised")
Example #25
Source File: online.py From continuous-online-video-classification-blog with MIT License | 4 votes |
def run_classification(labels): """Stream images off the camera and process them.""" camera = PiCamera() camera.resolution = (320, 240) camera.framerate = 2 raw_capture = PiRGBArray(camera, size=(320, 240)) # Warmup... time.sleep(2) # Unpersists graph from file with tf.gfile.FastGFile("../inception/retrained_graph.pb", 'rb') as fin: graph_def = tf.GraphDef() graph_def.ParseFromString(fin.read()) _ = tf.import_graph_def(graph_def, name='') with tf.Session() as sess: # And capture continuously forever. softmax_tensor = sess.graph.get_tensor_by_name('final_result:0') for _, image in enumerate( camera.capture_continuous( raw_capture, format='bgr', use_video_port=True ) ): # Get the numpy version of the image. decoded_image = image.array # Make the prediction. Big thanks to this SO answer: # http://stackoverflow.com/questions/34484148/feeding-image-data-in-tensorflow-for-transfer-learning predictions = sess.run(softmax_tensor, {'DecodeJpeg:0': decoded_image}) prediction = predictions[0] # Get the highest confidence category. prediction = prediction.tolist() max_value = max(prediction) max_index = prediction.index(max_value) predicted_label = labels[max_index] print("%s (%.2f%%)" % (predicted_label, max_value * 100)) # Reset the buffer so we're ready for the next one. raw_capture.truncate(0)