Beispiel #1
0
    def create_lapse(self):
        """
        Create the timelapse frames, please
        """
        fails = 0
        # Assume 30fps

        while self.i < self.frames :
            logging.info("i = %s, fails = %s" % (self.i, fails) )
            if fails > 5:
                logging.info("failed too many times")
                sys.exit(0)

            # Set up buffer for image to go to
            buf = StringIO.StringIO()

            try:
                drct = self.camera.getDirection()
                buf.write( self.camera.getOneShot() )
                buf.seek(0)
                imgdata = Image.open( buf )
                draw = ImageDraw.Draw(imgdata)
                fails = 0
            except IOError, exp:
                logging.exception( exp )
                time.sleep(10)
                fails += 1
                continue
        
            now = datetime.datetime.now()
            
            if self.network != 'KELO':
                stamp = "%s   %s" % (vbcam.drct2dirTxt(drct), 
                                   now.strftime("%-I:%M %p") )
                (width, height) = self.font.getsize(stamp)
                if self.network == 'KCRG2':
                    draw.rectangle( [545-width-10, self.date_height, 545, 
                                     self.date_height+height], fill="#000000" )
                    draw.text((540-width, self.date_height), stamp, 
                              font=self.font)
                else:
                    draw.rectangle( [205-width-10, self.date_height, 205, 
                                     self.date_height+height], fill="#000000" )
                    draw.text((200-width, self.date_height), stamp, 
                              font=self.font)
        
                stamp = "%s" % (now.strftime("%d %b %Y"), )
            else:
                stamp = "%s  %s" % (now.strftime("%d %b %Y %-I:%M %p"), 
                                  vbcam.drct2dirTxt(drct))
            (width, height) = self.sfont.getsize(stamp)
            draw.rectangle( [0, 480-height, 0+width, 480], fill="#000000" )
            draw.text((0, 480-height), stamp, font=self.sfont)
            del draw
        
            imgdata.save('%05i.jpg' % ( self.i,))
            self.wait_for_next_frame(self.i)
            del imgdata
            del buf
            self.i += 1
Beispiel #2
0
    if buf.len == 0:
        return
    try:
        i0 = Image.open(buf)
        i320 = i0.resize((320, 240), Image.ANTIALIAS)
    except:
        slaughter()
        return

    # Get direction cam is looking
    if row['scrape_url'] is None:
        drct = cam.getDirection()
        drctTxt = cam.drct2txt(drct)
    else:
        drct = row['pan0']
        drctTxt = vbcam.drct2dirTxt(row['pan0'])

    # Place timestamp/direction on image
    font = ImageFont.truetype('../lib/veramono.ttf', 10)

    draw = ImageDraw.Draw(i0)
    text = "(%s) %s %s" % (drctTxt, row['name'],
                           now.strftime("%-2I:%M:%S %p - %d %b %Y"))
    (w, h) = font.getsize(text)
    # Our image may not be 640x480 at full res
    (_, imgheight) = i0.size
    draw.rectangle([5, imgheight - 5 - h, 5+w, imgheight - 5], fill="#000000")
    draw.text((5, imgheight - 5 - h), text, font=font)

    # Save 640x480
    i0.save("../tmp/%s-640x480.jpg" % (cid,))