Beispiel #1
0
def main(image_src="src.png", image_dst="dst.png"):
    image_src = PointExtractor(
        image_filename=image_src,
        name="src",
        indicator_radius=10
    )
    image_src.set_points(4)
    src_points = image_src.get_current_points()

    image_dst = PointExtractor(
        image_filename=image_dst,
        name="dst",
        indicator_radius=10
    )
    image_dst.set_points(4)
    dst_points = image_dst.get_current_points()

    transform = get_homography(src_points, dst_points)

    result_array = warp_image(image_src.image_array, image_dst.image_array, transform)

    image_result = ImageReader(
        image_array=result_array,
        name="result"
    )
    image_result.imshow()
Beispiel #2
0
def main(image_first="1st.jpg", image_second="2nd.jpg"):
    image_first = PointExtractor(image_filename=image_first, name="test1")

    image_first.set_points(4)

    image_second = PointExtractor(image_filename=image_second, name="test2")

    image_second.set_points(4)

    image_first_hists = []
    for i in range(len(image_first.points)):
        image_first_hists.append(
            get_grad_hist(image_first.image_array, image_first.points[i]))

    image_second_hists = []
    for i in range(len(image_second.points)):
        image_second_hists.append(
            get_grad_hist(image_second.image_array, image_second.points[i]))

    pairs = []
    for i in range(4):
        variances = []
        for j in range(4):
            variances.append(
                variance_check(image_first_hists[i], image_second_hists[j]))
        pairs.append((i, variances.index(min(variances))))

    image_first.save()
    image_second.save()
    result_image = ImageReader(image_array=np.concatenate(
        (image_first.image_array, image_second.image_array), axis=1),
                               name="concatenated")

    offset = image_first.image_array.shape[1]

    for pair in pairs:
        offset_point = image_second.points[pair[1]]
        print(offset_point)
        offset_point = offset_point[0] + offset, offset_point[1]
        result_image.draw_line(image_first.points[pair[0]], offset_point)
    result_image.imshow()
Beispiel #3
0
    low_left = (home_points[1][0], batter_keypoint_heights[0][1])
    new_points = [high_right, low_left]

    point_extraction.revert()
    point_extraction.destroy_window()

    display_image = ImageReader(image_array=point_extraction.image_array,
                                name="result")
    display_image.draw_line((high_right[0], high_right[1]),
                            (high_right[0], low_left[1]))
    display_image.draw_line((high_right[0], high_right[1]),
                            (low_left[0], high_right[1]))
    display_image.draw_line((low_left[0], low_left[1]),
                            (low_left[0], high_right[1]))
    display_image.draw_line((low_left[0], low_left[1]),
                            (high_right[0], low_left[1]))
    display_image.imshow()

    actual_strike_bot = abs(low_left[1] - home_points[1][1]) * (
        actual_distance / pixel_distance)
    actual_strike_height = abs(low_left[1] - high_right[1]) * (
        actual_distance / pixel_distance)
    actual_strike_width = abs(low_left[0] - high_right[0]) * (actual_distance /
                                                              pixel_distance)
    print("actual strike zone start bottom: {}cm".format(
        round(actual_strike_bot, 2)))
    print("strike zone height: {}cm".format(round(actual_strike_height, 2)))
    print("strike zone width: {}cm".format(round(actual_strike_width)))

    # cv2.imwrite("out_1.jpg", display_image.image_array)