Пример #1
0
    def test_check_if_image_is_too_dark_returns_false_if_image_is_not_too_dark(
            self, as_get_image_mean_pixel_value):
        as_get_image_mean_pixel_value.return_value = 50.0

        ret_val = ans.check_if_image_is_too_dark('whatever', 49)

        assert not ret_val
        assert as_get_image_mean_pixel_value.called_once_with('whatever')
Пример #2
0
def take_picam_still(snap_id, group_id, normal_exposure_pic_id, long_exposure_pic_id):
    '''
    Top level method in the camera service for taking a still image via the picam (regular raspberry pi) camera.
    Also saves a picture record to the db
    Depending on settings and real time conditions, may cause a second, longer exposure to be taken
    '''
    group_document = get_group_document(str(group_id))
    retake_picam_pics_when_dark = get_retake_picam_pics_when_dark_setting(group_document)
    brightness_threshold = get_brightness_threshold(group_document)

    picture_name = build_picture_name(normal_exposure_pic_id)
    pic_path = build_picture_path(picture_name=picture_name, snap_id=snap_id)
    pic_dict = {
        '_id': str(normal_exposure_pic_id),
        'type': 'picture',
        'source': 'picam',
        'exposure_type': 'standard',
        'group_id': str(group_id),
        'snap_id': str(snap_id),
        'filename': picture_name,
        'uri': pic_path,
        'created': str(datetime.datetime.now())
    }
    take_standard_exposure_picam_still(pic_path)
    save_picture(pic_dict)
    image_is_too_dark = check_if_image_is_too_dark(pic_path, brightness_threshold)
    if image_is_too_dark and retake_picam_pics_when_dark:
        picture_name = build_picture_name(long_exposure_pic_id)
        pic_path = build_picture_path(picture_name=picture_name, snap_id=snap_id)
        pic_dict2 = copy.deepcopy(pic_dict)
        pic_dict2['exposure_type'] = 'long'
        pic_dict2['_id'] = str(long_exposure_pic_id)
        pic_dict2['filename'] = picture_name
        pic_dict2['uri'] = pic_path
        pic_dict2['created'] = str(datetime.datetime.now())
        take_long_exposure_picam_still(pic_path)
        save_picture(pic_dict2)