Exemple #1
0
def lambda_handler(event, context):
    try:
        body = json.loads(event['body'])
        url = body['url']
    except Exception as e:
        return {
            'statusCode': 400,
            'body': 'Cannot get url from request: %s' % e,
        }
    img_data = urllib.request.urlopen(url)

    img, bitmap = image.read_image(img_data)
    cells = grid.detect_filled_cells(bitmap)
    sudoku = [[0 for _ in range(9)] for _ in range(9)]
    for cell in cells:
        value = digit.predict(cell[0])
        pos = cell[2]
        sudoku[pos[0]][pos[1]] = int(value)
    result = copy.deepcopy(sudoku)
    if not solver.solve(result):
        result = None

    return {
        'statusCode': 200,
        'headers': {
            'Access-Control-Allow-Headers': 'Content-Type',
            'Access-Control-Allow-Origin': '*',
            'Access-Control-Allow-Methods': 'OPTIONS,POST',
        },
        'body': json.dumps({
            'input': sudoku,
            'solved': result,
        }),
    }
Exemple #2
0
def test_detection(example, ext):
    im, a = image.read_image(f'data/sudoku{example}.{ext}')
    expected_cells = eval(open(f'data/sudoku{example}.gold').read())
    cells = grid.detect_filled_cells(a)
    # Cell coordinates and positions should be as expected
    coords = [c[1] for c in cells]
    pos = [c[2] for c in cells]
    assert coords == expected_cells['coords']
    assert pos == expected_cells['pos']
Exemple #3
0
def upload():
    if request.files['image']:
        # 画像として読み込み
        img = read_image(request.files['image'])

        # 変換
        img, kanna_value, original_image = pred_kanna(img)

        # オリジナル画像を保存
        save_filename, save_path = save_image(kanna_value, original_image)

        return render_template('result.html', filename=save_filename, kanna_value=kanna_value)
Exemple #4
0
def load_images():
    images = []
    print('Loading Images')
    for breed in os.listdir('data/Annotation/'):
        for dog in os.listdir('data/Annotation/' + breed):
            tree = et.parse('data/Annotation/' + breed + '/' + dog)
            root = tree.getroot()
            objects = root.findall('object')
            for o in objects:
                box = o.find('bndbox')
                xmin = int(box.find('xmin').text)
                ymin = int(box.find('ymin').text)
                xmax = int(box.find('xmax').text)
                ymax = int(box.find('ymax').text)

            bounds = (xmin, ymin, xmax, ymax)
            try:
                image = read_image('data/all-dogs/' + dog + '.jpg', bounds)
                images.append(image)
            except:
                print('No image', dog)

    return np.array(images)
@simple_time_tracker()
def count_image_pixels_over_threshold(im, threshold=250):
    """计算大于某个色差值的所有像素比
    """
    pixels = im.width * im.height
    hit = 0

    ml = im.height
    part_list = [[0, ml // 4], [ml // 4, ml // 2], [ml // 2, ml - ml // 4],
                 [ml - ml // 4, ml]]

    with concurrent.futures.ProcessPoolExecutor() as executor:
        results = [
            executor.submit(count_hit_fast, im, (im.width, part[1]), threshold)
            for part in part_list
        ]

        for rc in concurrent.futures.as_completed(results):
            part_hits = rc.result()
            hit += part_hits

    ratio = hit / pixels
    return [hit, pixels, ratio]


if __name__ == '__main__':
    im = read_image("WechatIMG7.jpeg")
    hit, pixels, ratio = count_image_pixels_over_threshold(im)

    print(f"White pixels: hit = {hit}, pixels = {pixels}, ratio = {ratio}")
Exemple #6
0
        return image

    def profile_measurement(self, frame):
        points3d, profile = self.points_profile(frame)
        frame = self.draw_points(frame, profile,
                                 color=(0, 0, 255), thickness=2)
        if len(points3d) > 0:
            print points3d
            point3d = points3d[len(points3d)/5]
            cv2.putText(frame, '%s' % point3d, (11, 22),
                        cv2.FONT_HERSHEY_PLAIN, 1.0, (0, 255, 255),
                        thickness=1, lineType=cv2.CV_AA)
        return frame


if __name__ == '__main__':
    import image

    img = image.read_image('../data/utest9.png')
    profile0 = Profile(axis=1, thr=180, method='pcog')
    image.show_image(profile0.profile_measurement(img))
    #cv2.imwrite('peak.png', profile0.profile_measurement(img))
    #profile0.load_configuration('triangulation0.yml')

    # Camera test
    #from webcam import Webcam
    #camera = Webcam(device=1)
    #camera.set_size((800, 600))
    #camera.set_parameters(0.30, 0.20, 0.10)
    #camera.run(callback=lambda img: profile0.profile_measurement(img))
Exemple #7
0
def test_read_image():
    im, a = image.read_image('data/sudoku1.jpg')
    assert (im.width, im.height) == (298, 298)
    assert a.shape == (298, 298)
Exemple #8
0
from image import read_image, show_image, show_images


def transform(np_array, shape):
    return np_array.reshape(shape).astype('uint8')
  

if __name__ == '__main__':

    if len(sys.argv) > 1:
        image_file_name = sys.argv[1]
    else:
        raise Exception('Missing image file name')


    img, original_shape = read_image(image_file_name)
    hill = Hill(data=img, file_name=image_file_name)

    ### Testing zone
    print(img.shape)


    # -----------------------------------------------------------------
    # -------------------- Parte de codificación-----------------------
    # -----------------------------------------------------------------

    # Obtener la imagen vectorial codificada
    encoded_image_vector = hill.encode(img[0])

    # Cambiar la forma original de la imagen
    encoded_image = encoded_image_vector.reshape(original_shape)
Exemple #9
0
        return image

    def profile_measurement(self, frame):
        points3d, profile = self.points_profile(frame)
        frame = self.draw_points(frame, profile,
                                 color=(0, 0, 255), thickness=2)
        if len(points3d) > 0:
            print points3d
            point3d = points3d[len(points3d)/5]
            cv2.putText(frame, '%s' % point3d, (11, 22),
                        cv2.FONT_HERSHEY_PLAIN, 1.0, (0, 255, 255),
                        thickness=1, lineType=cv2.CV_AA)
        return frame


if __name__ == '__main__':
    import image

    img = image.read_image('../data/utest9.png')
    profile0 = Profile(axis=1, thr=180, method='pcog')
    image.show_image(profile0.profile_measurement(img))
    #cv2.imwrite('peak.png', profile0.profile_measurement(img))
    #profile0.load_configuration('triangulation0.yml')

    # Camera test
    #from webcam import Webcam
    #camera = Webcam(device=1)
    #camera.set_size((800, 600))
    #camera.set_parameters(0.30, 0.20, 0.10)
    #camera.run(callback=lambda img: profile0.profile_measurement(img))