Ejemplo n.º 1
0
def main():
    args = parse_args()

    img = task1.read_image(args.img_path)
    template = task1.read_image(args.template_path)

    coordinates = detect(img, template)

    template_name = "{}.json".format(os.path.splitext(os.path.split(args.template_path)[1])[0])
    save_results(coordinates, template, template_name, args.rs_directory)
Ejemplo n.º 2
0
def main():
    args = parse_args()

    img = t1.read_image(args.img_path)
    # template = utils.crop(img, xmin=10, xmax=30, ymin=10, ymax=30)
    # template = np.asarray(template, dtype=np.uint8)
    # cv2.imwrite("./data/proj1-task2-template.jpg", template)
    template = t1.read_image(args.template_path)

    x, y, max_value = match(img, template)
    # The correct results are: x: 17, y: 129, max_value: 0.994
    #print("x : " ,x , " y :", y , "max ncc: ", max_value )
    with open(args.rs_path, "w") as file:
        json.dump({"x": x, "y": y, "value": max_value}, file)
Ejemplo n.º 3
0
def main():
    args = parse_args()

    img = read_image(args.img_path)
    template = read_image(args.template_path)

    coordinates = detect(img, template)
    print(coordinates)
    #    print(coordinates)
    fig, ax = plt.subplots(1)
    ax.imshow(img)
    for i in coordinates:
        ax.add_patch(Circle((i[1], i[0]), radius=1, color='red'))
        plt.show(fig)

    template_name = "{}.json".format(
        os.path.splitext(os.path.split(args.template_path)[1])[0])
    save_results(coordinates, template, template_name, args.rs_directory)
Ejemplo n.º 4
0
def main():
    args = parse_args()

    img = task1.read_image(args.img_path)
    template = task1.read_image(args.template_path)

    if (args.template_path) == "./data/a.jpg":
        coordinates = detect(img, template, threshold=4.6)
    elif (args.template_path) == "./data/b.jpg":
        coordinates = detect(img, template, threshold=6.44)
    elif (args.template_path) == "./data/c.jpg":
        coordinates = detect(img, template, threshold=4.6)
    elif (args.template_path) == "./data/wa_img.jpg":
        coordinates = detect(img, template, threshold=4.6)
    else:
        print("Template does not exist.")

    template_name = "{}.json".format(
        os.path.splitext(os.path.split(args.template_path)[1])[0])
    save_results(coordinates, template, template_name, args.rs_directory)
def main():
    args = parse_args()

    img = task1.read_image(args.img_path)
    template = task1.read_image(args.template_path)

    coordinates = detect(img, template)

    template_name = "{}.json".format(
        os.path.splitext(os.path.split(args.template_path)[1])[0])
    save_results(coordinates, template, template_name, args.rs_directory)

    img = cv2.imread(args.img_path, 1)

    import matplotlib.pyplot as plt
    from matplotlib.patches import Arrow, Circle
    fig, ax = plt.subplots(1)
    ax.imshow(img)
    for i in coordinates:
        ax.add_patch(Circle((i[1], i[0]), radius=1, color='red'))
    plt.show(fig)
Ejemplo n.º 6
0
import cv2
import sys
import numpy as np
from task1 import min_filtered_image, max_filtered_image, path, read_image


def max_min(I, N=3):
    A = max_filtered_image(I, N)
    B = min_filtered_image(A, N)
    O = np.zeros(I.shape).astype('uint8')
    O = I - B + 255
    return O, B


if __name__ == '__main__':
    I = read_image(path)
    if len(sys.argv) == 2:
        N = int(sys.argv[1])

        # check if N is odd
        if N % 2 == 1:
            O, background = max_min(I, N)
            cv2.imwrite(f'task2_O_N_{N}.png', O)
            print(f'task2_O_N_{N}.png saved in root.')

            # optional
            O_normalized = cv2.normalize(O,
                                         None,
                                         alpha=0,
                                         beta=255,
                                         norm_type=cv2.NORM_MINMAX,