예제 #1
0
def TakePicture(img, cam):
    print(
        'Before saving picture, let me attempt to upload quite a few files in cache.'
    )
    for i in range(10):
        AttemptUpload()

    if len(globa.batch) == 0:
        print('not taking picture as batch is empty')
        return 0

    # audio_level = AudioLevelPi()

    print('Saving picture.')
    res = cam.resolution
    filename = 'cache/' + socket.gethostname(
    ) + '-' + globa.batch + '_' + time.strftime("%Y_%m_%d-%H_%M.jpg")
    print(filename)
    cv2.imwrite(filename, img,
                [int(cv2.IMWRITE_JPEG_QUALITY), 100])  # up to 100, default 95
    # cv2.imwrite(filename + '.png', img)
    ticks = time.time()
    globa.last_picture_filename = filename.replace('cache/', globa.group + '/')
    SaveLastPictureTicks(ticks, globa.last_picture_filename)
    # add EXIF keywords
    exif = ExifEditor(filename)
    keywords = [
        GitHash(), 'batch=' + globa.batch,
        'batch_start=' + str(int(globa.batch_start)), 'started=' +
        globa.time_process_started_string, 'shutter=' + str(cam.shutter_speed),
        'drc_str=' + str(cam.drc_strength), 'bright=' + str(cam.brightness),
        'iso=' + str(cam.iso), 'exp_comp=' + str(cam.exposure_compensation),
        'contrast=' + str(cam.contrast), 'meter=' + str(cam.meter_mode),
        'sharp=' + str(cam.sharpness), 'satur=' + str(cam.saturation),
        'exp_mode=' + str(cam.exposure_mode), 'awb_mode=' + str(cam.awb_mode),
        'awb_gains[r]=' + str(float(cam.awb_gains[0])), 'awb_gains[b]=' +
        str(float(cam.awb_gains[1])), 'exp=' + str(cam.exposure_speed),
        'analog_gain=' + str(float(cam.analog_gain)), 'digital_gain=' +
        str(float(cam.digital_gain)), 'zoom=' + str(cam.zoom[3])
    ]
    print(keywords)
    exif.addKeywords(keywords)
    # print('getKeywords', exif.getKeywords())
    print(('getTag Keywords', exif.getTag("Keywords")))
    AttemptUpload(
    )  # after taking the picture, immediately attempt to upload it
    # gc.collect()
    return ticks