def update3(self):
# keep looping infinitely until the thread is stopped
stream = io.BytesIO()
with picamera.PiCamera() as camera:
for f in camera.capture_continuous(stream, format='jpeg'): # 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
python类PiCamera()的实例源码
def __init__(self):
"""Constructor"""
self.folderCount = 0;
self.cam = picamera.PiCamera()
self.imageProUpperLevel = ImPro(self.cam, 256, 256)
self.imageProUpperLevel.camera._set_led(False)
self.imageProLowerLevel = ImPro(self.cam, 256, 256, True, 96, 96)
# This serial port is used to send 3D coordinates to the Arduino.
self.port = serial.Serial("/dev/ttyAMA0", baudrate=9600, timeout=3.0)
# This offset marks the pixelposition on the image which corresponds to the physical position when the
# DeltaPicker move down to 0.0, 0.0, -0.466. Only x and y components are used.
self.upperLevelOffset = Vector(0, 0, 0)
# This offset is the low level offset. It gets taken at a hight of -0.41
self.lowerLevelOffset = Vector(0, 0, 0)
# Crop Offset
self.cropOffset = Vector(80, 0, 0)
# - - - - - - - - - - - - - - - -
# - - - - GO TO STARTPOS - - - -
# - - - - - - - - - - - - - - - -
def takePhoto():
image = ImagePath + str(time.time()) + '.jpg'
print image
Camera = picamera.PiCamera()
Camera.resolution = (3280, 2464)
Camera.capture(image)
Camera.close()
return image
def is_plugged(function):
def plugged(*original_args, **original_kwargs):
return function(*original_args, **original_kwargs)
if not PiCamera:
logger = com_logger.Logger('CAMERA')
logger.warning('Camera not plugged')
return plugged
def __init__(self, mode, cameranumber):
if PiCamera is not None:
self.imgName = 'PIC_'
self.vidName = 'VID_'
self.cameranumber = cameranumber
conf = com_config.Config()
config = conf.getconfig()
logger = com_logger.Logger(self.cameranumber)
self.camera = PiCamera()
if mode == 'PICTURE':
self.camera.resolution = (int(config[self.cameranumber]['pic_resolution_x']), int(config[self.cameranumber]['pic_resolution_y']))
logger.info('Camera mode PICTURE: ' + config[self.cameranumber]['pic_resolution_x'] + ' ' + config[self.cameranumber]['pic_resolution_y'])
if mode == 'VIDEO':
self.camera.resolution = (int(config[self.cameranumber]['vid_resolution_x']), int(config[self.cameranumber]['vid_resolution_y']))
logger.debug('Camera mode VIDEO: ' + config[self.cameranumber]['vid_resolution_x'] + ' ' + config[self.cameranumber]['vid_resolution_y'])
self.camera.framerate = int(config[self.cameranumber]['framerate'])
self.camera.rotation = int(config[self.cameranumber]['rotation'])
# self.camera.brightness = int(config[self.cameranumber]['brightness'])
# self.camera.contrast = int(config[self.cameranumber]['contrast'])
if len(config[self.cameranumber]['image_effect']) > 0:
self.camera.image_effect = config[self.cameranumber]['image_effect']
self.camera.exposure_mode = config[self.cameranumber]['exposure_mode']
self.camera.meter_mode = config[self.cameranumber]['meter_mode']
self.camera.awb_mode = config[self.cameranumber]['awb']
if len(config[self.cameranumber]['raw']) > 0:
self.camera.raw_format = config[self.cameranumber]['raw']
self.path = config[self.cameranumber]['picture_path']
self.camera.iso = int(config[self.cameranumber]['ISO'])
self.quality = int(config[self.cameranumber]['jpegquality'])
self.format = config[self.cameranumber]['format']
def init_camera():
try:
camera = picamera.PiCamera()
# camera setup
camera.resolution = (cfg.width, cfg.height)
camera.hflip = cfg.pi_hflip
camera.vflip = cfg.pi_vflip
# let camera warm up
camera.start_preview()
time.sleep(2)
return True, camera
except:
return False, False
def init_camera():
try:
camera = picamera.PiCamera()
# camera setup
camera.resolution = (cfg.width, cfg.height)
camera.hflip = cfg.pi_hflip
camera.vflip = cfg.pi_vflip
# let camera warm up
camera.start_preview()
time.sleep(2)
return True, camera
except:
return False, False
def predict_from_cam(self, capfile='cap.jpg', reshape=(224, 224), N=5):
if self.camera is None:
self.camera = picamera.PiCamera()
# Show quick preview of what's being captured
self.camera.start_preview()
time.sleep(3)
self.camera.capture(capfile)
self.camera.stop_preview()
return self.predict_from_file(capfile)
def __init__(self, **kwargs):
""" Initialization of the camera """
self.camera = PiCamera()
version = kwargs.get('version', 0)
# Configuration
if version == 1:
self.camera.resolution = (1024, 768)
elif version == 2:
self.camera.resolution = (3280, 2464)
else:
raise ValueError('Unsupported raspberry pi camera version')
# Camera warm-up
self.camera.start_preview()
sleep(2)
def shutter():
photofile = open(photo_filename, 'wb')
print(photofile)
with picamera.PiCamera() as camera:
camera.resolution = (640,480)
camera.start_preview()
sleep(1.000)
camera.capture(photofile)
def shutter():
photofile = open(face_filename, 'wb')
print(photofile)
with picamera.PiCamera() as camera:
camera.resolution = (640,480)
camera.start_preview()
sleep(1.000)
camera.capture(photofile)
def __init__(self, config, path_maker):
self.camera = PiCamera()
self.camera.resolution = (int(config["width"]), int(config["height"]))
self.camera.meter_mode = "backlit"
self.config = config
self.path_maker = path_maker
def run(self):
with PiCamera() as camera:
camera.resolution = (2464,2464)
camera._set_rotation(180)
camera.capture("../_temp/snapshot.jpg")
def run(self):
with PiCamera() as camera:
camera._set_rotation(180)
camera.start_preview()
sleep(30)
def detect():
stream = io.BytesIO()
#Get the picture (low resolution, so it should be quite fast)
#Here you can also specify other parameters (e.g.:rotate the image)
with picamera.PiCamera() as camera:
camera.resolution = (700, 525)
camera.capture(stream, format='jpeg')
buff = np.fromstring(stream.getvalue(), dtype=np.uint8)
#Now creates an OpenCV image
img = cv2.imdecode(buff, 1)
#img = cv2.imread('coffee.jpg')
face_cascade = cv2.CascadeClassifier('/home/pi/Documents/OpenCV_Projects/XML_Files/coffeePot.xml')
eye_cascade = cv2.CascadeClassifier('/home/pi/Documents/OpenCV_Projects/XML_Files/liquid.xml')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, 1.2, 500, minSize=(80,100))
for (x,y,w,h) in faces:
img = cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
roi_gray = gray[y:y+h, x:x+w]
roi_color = img[y:y+h, x:x+w]
eyes = eye_cascade.detectMultiScale(roi_gray, 1.2, 10, minSize=(70,50))
return houghlines(roi_color,h)
def detect():
stream = io.BytesIO()
#Get the picture (low resolution, so it should be quite fast)
#Here you can also specify other parameters (e.g.:rotate the image)
with picamera.PiCamera() as camera:
camera.resolution = (700, 525)
camera.capture(stream, format='jpeg')
buff = np.fromstring(stream.getvalue(), dtype=np.uint8)
#Now creates an OpenCV image
img = cv2.imdecode(buff, 1)
#img = cv2.imread('coffee.jpg')
face_cascade = cv2.CascadeClassifier('/home/pi/Documents/OpenCV_Projects/XML_Files/coffeePot.xml')
eye_cascade = cv2.CascadeClassifier('/home/pi/Documents/OpenCV_Projects/XML_Files/liquid.xml')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, 1.2, 500, minSize=(80,100))
for (x,y,w,h) in faces:
img = cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
roi_gray = gray[y:y+h, x:x+w]
roi_color = img[y:y+h, x:x+w]
eyes = eye_cascade.detectMultiScale(roi_gray, 1.2, 10, minSize=(70,50))
return houghlines(roi_color,x,y,w,h)
def GetPhoto(f = None, quality = None):
"""
Photo aquisition
"""
global filename, FAILCOUNTER, error_tries
debug("GetPhoto: failcounter=%d" % FAILCOUNTER)
if FAILCOUNTER < 0:
print "Fail counter reached maximum attempts. Failed."
debug("Trying to return a failed img.")
filename = getfailedimg()
if not filename:
sys.exit(1)
debug("Using failed img: %s" % filename)
# it needs to be 0ed or it will fail
FAILCOUNTER = 0
return 0
filename = None
debug("Camera init")
camera = PiCamera()
debug("Camera start")
camera.start_preview()
time.sleep(10)
#if not os.path.exists(SAVEDIR):
# os.makedirs(SAVEDIR)
year = time.strftime("%Y", time.localtime())
month = time.strftime("%m", time.localtime())
if not os.path.exists("%s/%s/%s" % (SAVEDIR, year, month)):
os.makedirs("%s/%s/%s" % (SAVEDIR, year, month) )
if not f:
timestamp = time.strftime("%Y-%m-%d_%H%M%S", time.localtime())
filename = "%s/%s/%s/%s.jpg" % (SAVEDIR, year, month, timestamp)
else:
filename = f
debug("Saving file %s" % filename)
camera.capture(filename)
camera.stop_preview()
def testIt():
initGPIO()
lightTubes()
initTubes()
scrollList("The quick brown fox jumped over the lazy red hypercaterpillar".split())
print("************** running quick test ")
with picamera.PiCamera() as cam:
initcam(cam)
time.sleep(1.5)
cam.capture('tweet.jpg',resize=(800,480))
cam.close()
time.sleep(10)
return()
stream_images.py 文件源码
项目:continuous-online-video-classification-blog
作者: harvitronix
项目源码
文件源码
阅读 19
收藏 0
点赞 0
评论 0
def capture_images(save_folder):
"""Stream images off the camera and save them."""
camera = PiCamera()
camera.resolution = (320, 240)
camera.framerate = 5
# Warmup...
time.sleep(2)
# And capture continuously forever.
for _ in camera.capture_continuous(
save_folder + '{timestamp}.jpg',
'jpeg', use_video_port=True
):
pass
def __init__(self, config):
self.config = config
self.camera = picamera.PiCamera()
self.camera.annotate_text_size = 128
self.camera.led = False
self.camera.vflip = True
self.camera.resolution = (
self.config.getint("picture_width"),
self.config.getint("picture_height")
)