本文整理匯總了Python中picamera.array方法的典型用法代碼示例。如果您正苦於以下問題:Python picamera.array方法的具體用法?Python picamera.array怎麽用?Python picamera.array使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類picamera
的用法示例。
在下文中一共展示了picamera.array方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: getStreamImage
# 需要導入模塊: import picamera [as 別名]
# 或者: from picamera import array [as 別名]
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
#-----------------------------------------------------------------------------------------------
示例2: take_bracket_pictures
# 需要導入模塊: import picamera [as 別名]
# 或者: from picamera import array [as 別名]
def take_bracket_pictures(self):
"""
Returns two images in a list
One with normal exposure, and one with 2 stop longer exposure
The aim to to get detail out of shadows/underexposed film
Resulting images can be combined on a PC with Hugin's enfuse utility
"""
old_shutter = self.shutter_speed
imgs = []
with picamera.array.PiRGBArray(self) as output:
self.capture(output, format='bgr')
imgs.append( output.array )
self.shutter_speed = old_shutter*4
output.truncate(0)
self.capture(output, format='bgr')
imgs.append( output.array )
self.shutter_speed = old_shutter
return imgs
示例3: __init__
# 需要導入模塊: import picamera [as 別名]
# 或者: from picamera import array [as 別名]
def __init__(self, res_width=96, res_height=96):
self.camera = picamera.PiCamera(resolution=(res_width, res_height))
# TODO propagate configurable resolution through '96' logic below
self.camera.hflip = True
self.camera.vflip = True
self.res_width = res_width
self.res_height = res_height
self.stream = picamera.array.PiYUVArray(self.camera)
self.pixelObjList = []
self.object_id_center = 0
self.pixelObjList.append(PixelObject(self.next_obj_id()))
self.max_pixel_count = 0
self.largest_object_id = 0
self.largest_X = 0
self.largest_Y = 0
self.filename = ''
示例4: __iter__
# 需要導入模塊: import picamera [as 別名]
# 或者: from picamera import array [as 別名]
def __iter__(self):
"""
Iterate thought consecutive frames of this camera.
:return: the time (in ms) and a frame (numpy array).
:rtype: (int, :class:`~numpy.ndarray`)
"""
at_least_one_frame = False
while True:
if self.is_last_frame() or not self.is_opened():
if not at_least_one_frame:
raise EthoscopeException("Camera could not read the first frame")
break
t,out = self._next_time_image()
if out is None:
break
t_ms = int(1000*t)
at_least_one_frame = True
if (self._frame_idx % self._drop_each) == 0:
yield t_ms,out
if self._max_duration is not None and t > self._max_duration:
break
示例5: colorFindSet
# 需要導入模塊: import picamera [as 別名]
# 或者: from picamera import array [as 別名]
def colorFindSet(self,invarH, invarS, invarV):#1
global colorUpper, colorLower
HUE_1 = invarH+11
HUE_2 = invarH-11
if HUE_1>255:HUE_1=255
if HUE_2<0:HUE_2=0
SAT_1 = invarS+170
SAT_2 = invarS-20
if SAT_1>255:SAT_1=255
if SAT_2<0:SAT_2=0
VAL_1 = invarV+170
VAL_2 = invarV-20
if VAL_1>255:VAL_1=255
if VAL_2<0:VAL_2=0
colorUpper = np.array([HUE_1, SAT_1, VAL_1])
colorLower = np.array([HUE_2, SAT_2, VAL_2])
print('HSV_1:%d %d %d'%(HUE_1, SAT_1, VAL_1))
print('HSV_2:%d %d %d'%(HUE_2, SAT_2, VAL_2))
示例6: save_image
# 需要導入模塊: import picamera [as 別名]
# 或者: from picamera import array [as 別名]
def save_image(self, image, timestamp):
"""
Save image to disk
:param image: numpy array image
:param timestamp: formatted timestamp string
:return: filename
"""
if self.checkStorage() < 99:
filename = timestamp
filename = filename + ".jpg"
self.logger.debug('FileSaver: saving file')
try:
cv2.imwrite(os.path.join(self.config["photos_path"], filename), image)
self.logger.info("FileSaver: saved file to " + os.path.join(self.config["photos_path"], filename))
return filename
except Exception as e:
self.logger.error('FileSaver: save_photo() error: ')
self.logger.exception(e)
pass
else:
self.logger.error('FileSaver: not enough space to save image')
return None
示例7: __init__
# 需要導入模塊: import picamera [as 別名]
# 或者: from picamera import array [as 別名]
def __init__(self):
self.camera = picamera.PiCamera()
self.camera.vflip = True
self.camera.hflip = True
#self.camera.resolution = (320, 160)
self.camera.start_preview()
sleep(5)
self.stream = picamera.array.PiYUVArray(self.camera)
示例8: capture
# 需要導入模塊: import picamera [as 別名]
# 或者: from picamera import array [as 別名]
def capture(self):
self.camera.capture(self.stream, format='yuv')
img = self.stream.array[270:,:,0]
self.stream.seek(0)
self.stream.truncate()
return img
示例9: update
# 需要導入模塊: import picamera [as 別名]
# 或者: from picamera import array [as 別名]
def update(self):
# keep looping infinitely until the thread is stopped
for f in self.stream:
# grab the frame from the stream and clear the stream in
# preparation for the next frame
self.frame = f.array
self.rawCapture.truncate(0)
# if the thread indicator variable is set, stop the thread
# and resource camera resources
if self.stopped:
self.stream.close()
self.rawCapture.close()
self.camera.close()
return
示例10: read
# 需要導入模塊: import picamera [as 別名]
# 或者: from picamera import array [as 別名]
def read(self):
"""
Extracts frames synchronously from monitored deque, while maintaining a fixed-length frame buffer in the memory,
and blocks the thread if the deque is full.
**Returns:** A n-dimensional numpy array.
"""
# check if there are any thread exceptions
if not (self.__exceptions is None):
if isinstance(self.__exceptions, bool):
# clear frame
self.frame = None
# notify user about hardware failure
raise SystemError(
"[PiGear:ERROR] :: Hardware failure occurred, Kindly reconnect Camera Module and restart your Pi!"
)
else:
# clear frame
self.frame = None
# re-raise error for debugging
error_msg = "[PiGear:ERROR] :: Camera Module API failure occured: {}".format(
self.__exceptions[1]
)
raise RuntimeError(error_msg).with_traceback(self.__exceptions[2])
# return the frame
return self.frame
示例11: take_picture
# 需要導入模塊: import picamera [as 別名]
# 或者: from picamera import array [as 別名]
def take_picture(self):
"""
Returns an openCV compatible colour image
"""
with picamera.array.PiRGBArray(self) as output:
self.capture(output, format='bgr')
return output.array
示例12: capture_frame
# 需要導入模塊: import picamera [as 別名]
# 或者: from picamera import array [as 別名]
def capture_frame(self):
self.stream = picamera.array.PiYUVArray(self.camera)
self.camera.capture(self.stream, 'yuv')
self.camera._set_led(True)
self.pixelObjList = []
self.object_id_center = 0
self.pixelObjList.append(PixelObject(self.next_obj_id()))
rows = []
for _ in range(self.res_height):
rows.append(range(self.res_width))
# flip image horizontally
for j, j_ in enumerate(range(self.res_width-1, -1, -1)):
# now flip vertically
for i, i_ in enumerate(range(self.res_height-1, -1, -1)):
rows[j][i] = self.stream.array[j_][i_][0]
self.filename = self.save_PNG('raw.png', rows)
self.spread_white_pixels(
self.make_black_and_white(
self.fuse_horizontal_and_vertical(
self.get_horizontal_edges(rows),
self.get_vertical_edges(rows)))
)
示例13: flush
# 需要導入模塊: import picamera [as 別名]
# 或者: from picamera import array [as 別名]
def flush(self):
# looping until self.stopped flag is flipped
# for now, grab the first frame in buffer, then empty buffer
for f in self.stream:
self.frame = f.array
self.data_container.truncate(0)
if self.stopped:
self.stream.close()
self.data_container.close()
self.camera.close()
return
示例14: run
# 需要導入模塊: import picamera [as 別名]
# 或者: from picamera import array [as 別名]
def run(self):
while not self.is_stopped():
try:
if picamera_exists:
try:
# Get image from Pi camera
self.picamera_md_output.truncate(0)
self.picamera_md_output.seek(0)
self.picamera_md_stream.__next__()
self.image = self.picamera_md_output.array
if self.image is None:
self.logger.warning("CameraController: got empty image.")
time.sleep(0.01)
except Exception as e:
self.logger.error("CameraController: picamera update error.")
self.logger.exception(e)
self.initialise_picamera()
time.sleep(0.02)
else:
# Get image from webcam
if self.use_splitter_port:
ret, self.splitter_image = self.capture.read()
if self.splitter_image is not None:
self.image = imutils.resize(self.splitter_image, width=self.width, height=self.height)
else:
ret, self.image = self.capture.read()
if self.image is None:
self.logger.warning("CameraController: got empty image.")
except KeyboardInterrupt:
self.logger.info("CameraController: received KeyboardInterrupt, shutting down ...")
self.stop()
# Stop thread
示例15: decimate_to
# 需要導入模塊: import picamera [as 別名]
# 或者: from picamera import array [as 別名]
def decimate_to(shape, image):
"""Decimate an image to reduce its size if it's too big."""
decimation = np.max(np.ceil(np.array(image.shape, dtype=np.float)[:len(shape)]/np.array(shape)))
return image[::int(decimation), ::int(decimation), ...]