Пример #1
0
def bhayankar_image_processing(file_path):
    norm2dp_image_path = 'norm2dp.jpg'
    final_image_path = 'final_image_processed.jpg'
    im = Image.open(file_path)
    l, w = im.size
    factor = fact(l)
    size = int(factor * l), int(factor * w)
    im_resized = im.resize(size, Image.ANTIALIAS)
    im_resized.save(norm2dp_image_path, dpi=(200, 200))
    im_new = smooth_image.smooth2(norm2dp_image_path)
    cv2.imwrite(final_image_path, im_new)
    return final_image_path
Пример #2
0
def extract_image(file_name):
    try:

        img = cv2.imread(file_name)
        img_final = cv2.imread(file_name)

        img2gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
        inv_img = (255 - img2gray)
        kernel = cv2.getStructuringElement(cv2.MORPH_CROSS, (5, 2))

        dilated = cv2.dilate(inv_img, kernel, iterations=7)  # dilate
        type_image = dilated
        contours, hierarchy = cv2.findContours(type_image, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)  # get contours

    except:
        print
        'Image_Processing Error in menu_json'
    ind = 0
    pix = {}
    value_at = {}
    index = 0
    P = {}

    image_2_text = smooth_image.smooth2(file_name)
    try:

        for contour in contours:
            # get rectangle bounding contour
            [x, y, w, h] = cv2.boundingRect(contour)
            # draw rectangle around contour on original image
            if w < 20 or h < 20:
                continue
            if w > 500 and h > 500:
                continue

            cv2.rectangle(img, (x, y), (x + w + 10, y + h + 10), (255, 0, 255), 2)

            s = 'meta/' + str(ind) + '.tif'

            box_read = image_process_extract_string(s, image_2_text, x, y, w, h)
            # print box_read
            D[(x, y)] = box_read
            ind += 1
            box_read_to_lines = box_read.split('\n')

            for lines in box_read_to_lines:
                P[(x, y)] = lines;
                value_at[index] = (x, y)
                index += 1
                x1 = x / 50
                x1 = x1 * 50

                tup = [[x, lines]]
                for key, val in tup:
                    pix.setdefault(key, []).append(val)
        cv2.imwrite('boxed_image.jpg', img)


    except:
        print
        'In menu_json'

    # print D
    final_list2 = []
    sorted_x = sorted(D.items(), key=operator.itemgetter(0))
    # print sorted_x
    for k, v in sorted(D.items()):
        # print v
        list_new = str(v).split('\n')
        for l in list_new:
            final_list2.append(l)

    '''final_list = []
    for val in pix:
        for dish in pix[val]:
            if len(dish) > 1:
                final_list.append(dish) 
    '''
    return final_list2