示例#1
0
    def test_picture_exists_returns_true_when_picture_exists(self):
        pic_id = uuid.uuid4()
        doc_1 = {
            '_id': str(pic_id),
            'type': 'picture'
        }
        ps.save_picture_document(doc_1)

        assert True == ps.picture_exists(pic_id)
示例#2
0
def edge_detect(img_id_in,
                alternate_img_id_in,
                auto_id,
                wide_id=None,
                tight_id=None):
    if picture_exists(alternate_img_id_in):
        img_id_in = alternate_img_id_in
    pic_dict_in = find_picture(img_id_in)
    image_in = cv2.imread(pic_dict_in['uri'])
    gray = cv2.cvtColor(image_in, cv2.COLOR_BGR2GRAY)
    blurred = cv2.GaussianBlur(gray, (3, 3), 0)
    # apply Canny edge detection using a wide threshold, tight
    # threshold, and automatically determined threshold
    auto = auto_canny(blurred)
    auto = auto_canny(image_in)
    auto_filename = build_picture_name(auto_id)
    auto_path_out = build_picture_path(picture_name=auto_filename,
                                       snap_id=pic_dict_in['snap_id'])
    cv2.imwrite(auto_path_out, auto)
    auto_dict_out = make_edge_picture_dict(pic_id=auto_id,
                                           pic_filename=auto_filename,
                                           pic_path=auto_path_out,
                                           snap_id=pic_dict_in['snap_id'],
                                           group_id=pic_dict_in['group_id'],
                                           source_pic_id=img_id_in,
                                           edge_detect_type='auto')
    save_picture_document(auto_dict_out)
    if wide_id:
        wide = cv2.Canny(blurred, 10, 200)
        wide_filename = build_picture_name(wide_id)
        wide_path_out = build_picture_path(picture_name=wide_filename,
                                           snap_id=pic_dict_in['snap_id'])
        cv2.imwrite(wide_path_out, wide)
        wide_dict_out = make_edge_picture_dict(
            pic_id=wide_id,
            pic_filename=wide_filename,
            pic_path=wide_path_out,
            snap_id=pic_dict_in['snap_id'],
            group_id=pic_dict_in['group_id'],
            source_pic_id=img_id_in,
            edge_detect_type='wide')
        save_picture_document(wide_dict_out)
    if tight_id:
        tight = cv2.Canny(blurred, 225, 250)
        tight_filename = build_picture_name(tight_id)
        tight_path_out = build_picture_path(picture_name=tight_filename,
                                            snap_id=pic_dict_in['snap_id'])
        cv2.imwrite(tight_path_out, tight)
        tight_dict_out = make_edge_picture_dict(
            pic_id=tight_id,
            pic_filename=tight_filename,
            pic_path=tight_path_out,
            snap_id=pic_dict_in['snap_id'],
            group_id=pic_dict_in['group_id'],
            source_pic_id=img_id_in,
            edge_detect_type='tight')
        save_picture_document(tight_dict_out)
示例#3
0
def merge_images(img1_primary_id_in, img1_alternate_id_in, img2_id_in,
                 img_id_out, group_id):
    #deal with the fact that different merge methods require different parameters
    group_document = get_group_document(group_id)
    group_id = group_document['_id']

    img1_id_in = img1_primary_id_in
    if picture_exists(img1_alternate_id_in):
        img1_id_in = img1_alternate_id_in

    if 'merge_type' in group_document:
        merge_type = group_document['merge_type']

    if hasattr(ImageChops, merge_type):
        merge_method = getattr(ImageChops, merge_type)
    else:
        merge_method = getattr(ImageChops, 'screen')

    img1_dict_in = find_picture(str(img1_id_in))
    img1_filename_in = img1_dict_in['filename']
    img2_dict_in = find_picture(str(img2_id_in))
    img2_filename_in = img2_dict_in['filename']
    img_filename_out = build_picture_name(img_id_out)
    pic1_path_in = build_picture_path(picture_name=img1_filename_in,
                                      snap_id=img1_dict_in['snap_id'])
    pic2_path_in = build_picture_path(picture_name=img2_filename_in,
                                      snap_id=img1_dict_in['snap_id'])
    pic_path_out = build_picture_path(picture_name=img_filename_out,
                                      snap_id=img1_dict_in['snap_id'])
    image1_in = Image.open(pic1_path_in)
    image2_in = Image.open(pic2_path_in)
    image_out = merge_method(image1_in.convert('RGBA'),
                             image2_in.convert('RGBA'))
    image_out.save(pic_path_out)

    img_dict_out = {
        '_id': str(img_id_out),
        'type': 'picture',
        'source': 'merge',
        'source_image_id_1': str(img1_id_in),
        'source_image_id_2': str(img2_id_in),
        'merge_type': merge_type,
        'group_id': group_id,
        'snap_id': img1_dict_in['snap_id'],
        'filename': img_filename_out,
        'uri': pic_path_out,
        'created': str(datetime.datetime.now())
    }
    save_picture_document(img_dict_out)
示例#4
0
def merge_images(img1_primary_id_in, img1_alternate_id_in, img2_id_in, img_id_out, group_id):
    #deal with the fact that different merge methods require different parameters
    group_document = get_group_document(group_id)
    group_id = group_document['_id']

    img1_id_in = img1_primary_id_in
    if picture_exists(img1_alternate_id_in):
        img1_id_in = img1_alternate_id_in

    if 'merge_type' in group_document:
        merge_type = group_document['merge_type']

    if hasattr(ImageChops, merge_type):
        merge_method = getattr(ImageChops, merge_type)
    else:
        merge_method = getattr(ImageChops, 'screen')

    img1_dict_in = find_picture(str(img1_id_in))
    img1_filename_in = img1_dict_in['filename']
    img2_dict_in = find_picture(str(img2_id_in))
    img2_filename_in = img2_dict_in['filename']
    img_filename_out = build_picture_name(img_id_out)
    pic1_path_in = build_picture_path(picture_name=img1_filename_in, snap_id=img1_dict_in['snap_id'])
    pic2_path_in = build_picture_path(picture_name=img2_filename_in, snap_id=img1_dict_in['snap_id'])
    pic_path_out = build_picture_path(picture_name=img_filename_out, snap_id=img1_dict_in['snap_id'])
    image1_in = Image.open(pic1_path_in)
    image2_in = Image.open(pic2_path_in)
    image_out = merge_method(image1_in.convert('RGBA'), image2_in.convert('RGBA'))
    image_out.save(pic_path_out)

    img_dict_out = {
        '_id': str(img_id_out),
        'type': 'picture',
        'source': 'merge',
        'source_image_id_1': str(img1_id_in),
        'source_image_id_2': str(img2_id_in),
        'merge_type': merge_type,
        'group_id': group_id,
        'snap_id': img1_dict_in['snap_id'],
        'filename': img_filename_out,
        'uri': pic_path_out,
        'created': str(datetime.datetime.now())
    }
    save_picture_document(img_dict_out)
示例#5
0
def edge_detect(img_id_in, alternate_img_id_in, auto_id, wide_id=None, tight_id=None):
    if picture_exists(alternate_img_id_in):
        img_id_in = alternate_img_id_in
    pic_dict_in = find_picture(img_id_in)
    image_in = cv2.imread(pic_dict_in['uri'])
    gray = cv2.cvtColor(image_in, cv2.COLOR_BGR2GRAY)
    blurred = cv2.GaussianBlur(gray, (3, 3), 0)
    # apply Canny edge detection using a wide threshold, tight
    # threshold, and automatically determined threshold
    auto = auto_canny(blurred)
    auto = auto_canny(image_in)
    auto_filename = build_picture_name(auto_id)
    auto_path_out = build_picture_path(picture_name=auto_filename, snap_id=pic_dict_in['snap_id'])
    cv2.imwrite(auto_path_out, auto)
    auto_dict_out = make_edge_picture_dict(pic_id=auto_id, pic_filename=auto_filename, pic_path=auto_path_out,
                                           snap_id=pic_dict_in['snap_id'], group_id=pic_dict_in['group_id'],
                                           source_pic_id=img_id_in, edge_detect_type='auto')
    save_picture_document(auto_dict_out)
    if wide_id:
        wide = cv2.Canny(blurred, 10, 200)
        wide_filename = build_picture_name(wide_id)
        wide_path_out = build_picture_path(picture_name=wide_filename, snap_id=pic_dict_in['snap_id'])
        cv2.imwrite(wide_path_out, wide)
        wide_dict_out = make_edge_picture_dict(pic_id=wide_id, pic_filename=wide_filename, pic_path=wide_path_out,
                                               snap_id=pic_dict_in['snap_id'], group_id=pic_dict_in['group_id'],
                                               source_pic_id=img_id_in, edge_detect_type='wide')
        save_picture_document(wide_dict_out)
    if tight_id:
        tight = cv2.Canny(blurred, 225, 250)
        tight_filename = build_picture_name(tight_id)
        tight_path_out = build_picture_path(picture_name=tight_filename, snap_id=pic_dict_in['snap_id'])
        cv2.imwrite(tight_path_out, tight)
        tight_dict_out = make_edge_picture_dict(pic_id=tight_id, pic_filename=tight_filename, pic_path=tight_path_out,
                                               snap_id=pic_dict_in['snap_id'], group_id=pic_dict_in['group_id'],
                                               source_pic_id=img_id_in, edge_detect_type='tight')
        save_picture_document(tight_dict_out)
示例#6
0
    def test_picture_exists_returns_false_when_picture_does_not_exist(self):
        pic_id = uuid.uuid4()

        assert False == ps.picture_exists(pic_id)
示例#7
0
    def test_picture_exists_returns_true_when_picture_exists(self):
        pic_id = uuid.uuid4()
        doc_1 = {'_id': str(pic_id), 'type': 'picture'}
        ps.save_picture_document(doc_1)

        assert True == ps.picture_exists(pic_id)
示例#8
0
    def test_picture_exists_returns_false_when_picture_does_not_exist(self):
        pic_id = uuid.uuid4()

        assert False == ps.picture_exists(pic_id)