示例#1
0
def snapshot():
    global config
    img = camera_module.takePhoto()
    if config is not None:
        img = transform_perspective(img, int(config['x0']), int(config['y0']), int(config['x1']), int(config['y1']), int(config['x2']), int(config['y2']), int(config['x3']), int(config['y3']))
        img = img.rotate(int(config['rotation']))
    imageBuffer = StringIO.StringIO() 
    img.save(imageBuffer, format="JPEG")
    imageBuffer.seek(0)
    return send_file(imageBuffer, mimetype='image/jpeg')
 def test_correct_image_result(self):
     self.img = transform_perspective(self.img, self.x0, self.y0, self.x1, self.y1, self.x2, self.y2, self.x3, self.y3)
     self.img.save('tests/test_data/wb_test_temp.jpg') #Hack given that the histogram of an image changes when saved and opened as jpg probably due to compression
     self.img = Image.open('tests/test_data/wb_test_temp.jpg')
     os.remove('tests/test_data/wb_test_temp.jpg')
     img_comparison = Image.open('tests/test_data/wb_transformed_scaled.jpg')
     histogram1 = self.img.histogram()
     histogram2 = img_comparison.histogram()
     
     #from http://stackoverflow.com/questions/1927660/compare-two-images-the-python-linux-way
     root_mean_square = math.sqrt(reduce(operator.add,
         map(lambda a,b: (a-b)**2, histogram1, histogram2))/len(histogram1))     
     
     assert root_mean_square == 0
     
示例#3
0
def button_snapshot():
    global tp
    now = datetime.datetime.now()

    tp.print_text('Time submitted: ')
    tp.print_text(str(now))
    tp.linefeed(2)

    # send image to the server
    global server_config
    if server_config is None:
        return 'Server configuration file not found. Perhaps you have not registered this pi yet?', 400

    ip = server_config['server']
    server_location = 'http://' + server_config['server']

    # generate the access code
    r = requests.get(server_location + '/generate-access-code/')
    code = r.json()['code']

    tp.print_text('You have 2 days to process this snapshot before it is ')
    tp.print_text('automatically deleted.')
    tp.linefeed(2)

    tp.print_text('Access code: \n')
    tp.justify("C")
    tp.double_width(True)
    tp.double_height(True)
    tp.print_text(code)
    tp.double_width(False)
    tp.double_height(False)
    tp.justify("L")
    tp.linefeed(2)

    tp.print_text('Your photo will be available at: \n')
    tp.print_text('http://' + server_config['server'] + '/')
    tp.linefeed(5)

    global config
    img = camera_module.takePhoto()
    if config is not None:
        img = transform_perspective(img, int(config['x0']), int(config['y0']), int(config['x1']), int(config['y1']), int(config['x2']), int(config['y2']), int(config['x3']), int(config['y3']))
        img = img.rotate(int(config['rotation']))
    imageBuffer = StringIO.StringIO() 
    img.save(imageBuffer, format="JPEG")
    imageBuffer.seek(0)

    filename = 'button_%i%i%i_%i%i%i' % (now.year,
                                         now.month,
                                         now.day,
                                         now.hour,
                                         now.minute,
                                         now.second)
    filename = filename + ".jpg"
    files = {'file': (filename, imageBuffer.getvalue())}
    data = {'id': server_config['id'], 'code': code}
    r = requests.post(server_location + '/pi-upload/', files=files, data=data)
    if r.status_code != 200:
        tp.print_text('There was an error with the photo:\n')
        tp.print_text(str(r.status_code))
        tp.linefeed()
        tp.print_text(r.text)
    elif r.json()['code'] != code:
        tp.print_text('There was a code mismatch error.\n')
        tp.print_text(code + ' vs ' + r.json()['code'])

    return 'Success', 200
 def test_correct_dimensions(self):
     self.img = transform_perspective(self.img, self.x0, self.y0, self.x1, self.y1, self.x2, self.y2, self.x3, self.y3)
     (new_width, new_height) = self.img.size
     self.img.save('tests/test_data/wb_test_temp.jpg')
     assert self.img.size == self.size, "New image size is the same as computed whiteboard size in pixels"