Пример #1
0
def testWriteBinJpeg():
    if m_tornado.WSHandler.wsClients() > 0:
        img = picam.takePhotoWithDetails(width, height, 85)
        img.save(stream, 'JPEG', quality=70)
        m_tornado.WSHandler.wsSend('[5]')
        m_tornado.WSHandler.wsSend(stream.getvalue(), binary=True)
        stream.seek(0)
Пример #2
0
def alfred_pic(channel):
    sendUserAndConsole(channel, usr_resp_pic)

    picture = picam.takePhotoWithDetails(640, 480, 85)
    picture.save(PATH_2_IMG)

    channel.send_pic(PATH_2_IMG)
Пример #3
0
def testWriteBinJpeg():
    if m_tornado.WSHandler.wsClients() > 0:
        img = picam.takePhotoWithDetails(width,height, 85)
        img.save(stream,'JPEG', quality=70)
        m_tornado.WSHandler.wsSend('[5]')
        m_tornado.WSHandler.wsSend(stream.getvalue(),binary=True)
        stream.seek(0)
Пример #4
0
    def get_image(self):
        frame = None
        rval = False
        if WEBCAMPI:
            frametemp = picam.takePhotoWithDetails(640, 480, 100)   # width, height, quality
            frame = np.array(frametemp)
            rval = frame != None # check frame.size ??
        else:
            rval, frame = self.cap.read()

        return rval, frame
Пример #5
0
def TakePhoto(dirname,name,ext,w,h,s,loopi):
    setwh=(not w==0) and (not h==0)
    for i in range(loopi):   
      time.sleep(s)
      filename=name+"%02d" % i+ext
      filen=dirname+"/"+filename
      if(setwh):
        pic=cam.takePhotoWithDetails(w,h,100)
      else:
        pic=cam.takePhoto()
      pic.save(filen)
Пример #6
0
    def get_image(self):
        frame = None
        rval = False
        if WEBCAMPI:
            frametemp = picam.takePhotoWithDetails(
                640, 480, 100)  # width, height, quality
            frame = np.array(frametemp)
            rval = frame != None  # check frame.size ??
        else:
            rval, frame = self.cap.read()

        return rval, frame
def logMedian():
	# set the current directory for the data to todays date
	day = str(time.strftime("%m-%d-%Y"))
	directory = '/media/pi/SANDISK/' + day
	photodir = directory + "/photos"
	filename = str(directory + "/" + day +'.csv')
	print directory
	
	# check if directories exist
	# create them if they do not
	if os.path.exists(directory) == False:
	    os.makedirs(directory)
	    print "created directory"
	if os.path.exists(photodir) == False:
	    os.makedirs(photodir)
	    print "created directory"

	# create an empty array to store the measurements
	data = []
	loop = 0
	print 'beginning measurements'

	# measure water level X amount of times 
	while loop <= 8 :
		m = distance()
		data.append(m)
		print "measured {0} times".format(loop)
		loop = loop + 1

	# sort the data by distance and grab the media value to help ensure accuracy
	print data
	data.sort()
	median = str(data[4])

	# log the current time and measurment to a spreadsheet
	with open(filename, 'a') as fp:
	    writer = csv.writer(fp, dialect='excel', delimiter=',')
	    timestamp = str(time.strftime("%m/%d, %H:%M"))
	    writer.writerow([timestamp, median])
	    print 'water logged'

	# take a photo of the drain. Label it the row number of the corresponding measurement
	row_count = 0
	with open(filename, 'r') as f:
		reader = csv.DictReader(f)
		for row in reader:
			row_count += 1
		row_count = str(row_count)
		photo = picam.takePhotoWithDetails(640,480, 85)
		photo.save(photodir+"/"+row_count+".jpg")
Пример #8
0
    def takePhoto(self, parameters):
        while self.shooting:
            print 'sleeping'
            self._sleep(1)
        try:
            self.shooting = True
            request = parameters
            #print vars(request)
            imageType = request.encoding if request.encoding else 'jpg'
            imageFilename = 'IMG-' + datetime.now().isoformat().replace(':','_') + '.' + imageType
            imageType = request.encoding if request.encoding != 'jpg' else 'JPEG'
            replyType = request.replyMessageType
            #print imageType, imageFilename

            picam.config.imageFX = IMXFX_OPTIONS.index(request.imxfx) if request.imxfx else 0
            picam.config.exposure = SCENE_OPTIONS.index(request.scene) if request.scene else 0
            picam.config.meterMode = METERING_OPTIONS.index(request.metering)
            picam.config.awbMode = AWB_OPTIONS.index(request.awb)
            picam.config.ISO = int(request.iso) if ISO_OPTIONS.index(request.iso) != 0 else 0
            
            picam.config.sharpness = int(request.sharpness) if request.sharpness else 0            # -100 to 100
            picam.config.contrast = int(request.contrast)  if request.contrast else 0               # -100 to 100
            picam.config.brightness = int(request.brightness)   if request.brightness else 0           #  0 to 100
            picam.config.saturation = int(request.saturation)  if request.saturation else 0             #  -100 to 100
            #picam.config.videoStabilisation = 0      # 0 or 1 (false or true)
            # EV seems to be mis-stated - adjust
            picam.config.exposureCompensation  = int(request.ev * 8)  if request.ev else 0  # -10 to +10 ?
            #print picam.config.exposureCompensation
            #picam.config.rotation = 90               # 0-359
            picam.config.hflip = int(request.hflip)  if request.hflip else 0                  # 0 or 1
            picam.config.vflip = int(request.vflip) if request.vflip else 0                   # 0 or 1
            #picam.config.shutterSpeed = 20000         # 0 = auto, otherwise the shutter speed in ms
            width = request.width if request.width else self.MAX_WIDTH
            height = request.height if request.height else self.MAX_HEIGHT
            quality = int(request.quality) if request.quality else self.DEFAULT_QUALITY
            
            if request.zoomTimes > 1.0:
                sz = 1.0/request.zoomTimes
                picam.config.roi = [ .5 - sz/2.0, .5 - sz/2.0, sz, sz ] 
                #print picam.config.roi
            
            image = picam.takePhotoWithDetails(width,height,quality) 
            
            #print imageFilename, str(len(imageBinary))
            return imageFilename, image, imageType, replyType
        finally:
            self.shooting = False
Пример #9
0
def takePhoto(config,now=datetime.datetime.today()):
  #Take a photo with the given config and save to file with the given name pattern
  #Preference is given to a webcam because opencv provides better error checking.
  CFN=config.campath+'current.jpg'
  FN=config.campath+'images/'+now.strftime(config.values['FNpattern'][0])
  import cv2
  cam = cv2.VideoCapture(0)
  #CV_CAP_PROP_FRAME_WIDTH
  cam.set(3,config.values['FrameWidth'][0])
  #CV_CAP_PROP_FRAME_HEIGHT
  cam.set(4,config.values['FrameHeight'][0])
  retval, image = cam.read()
  if retval:
    cam.release()
    cv2.imwrite(CFN,image)
  else:
    import picam
    image=picam.takePhotoWithDetails(config.values['FrameWidth'][0],config.values['FrameHeight'][0], 100)
    image.save(CFN)
  import shutil
  shutil.copyfile(CFN,FN)
  return FN
Пример #10
0
import picam
import time

ii = picam.takePhotoWithDetails(640,480, 85) 

filename = "/home/pi/picam/picam-%s.jpg" % time.strftime("%Y_%m_%d-%H:%M:%S")

ii.save(filename)
Пример #11
0
picam.config.sharpness = 0               # -100 to 100
picam.config.contrast = 0                # -100 to 100
picam.config.brightness = 50             #  0 to 100
picam.config.saturation = 0              #  -100 to 100
picam.config.videoStabilisation = 0      # 0 or 1 (false or true)
picam.config.exposureCompensation  = 0   # -10 to +10 ?
picam.config.rotation = 0               # 0-359
picam.config.hflip = 0                   # 0 or 1
picam.config.vflip = 0                   # 0 or 1
picam.config.shutterSpeed = 100         # 0 = auto, otherwise the shutter speed in ms

i = picam.takePhoto()
i.save('./after.jpg')

# (width, height, jpg quality)
ii = picam.takePhotoWithDetails(640,480, 85) 

#RGB pixel info
frame1 = picam.takeRGBPhotoWithDetails(width,height)
frame2 = picam.takeRGBPhotoWithDetails(width,height)

#returns RGB pixel list with modified pixels, and the quantity of changed pixels
THRESHOLD=15
(modified,q) = picam.difference(frame1,frame2,THRESHOLD)




#filename = "/tmp/picam-%s.h264" % time.strftime("%Y%m%d-%H%M%S")

# (width, height, duration = 5s)