示例#1
0
    def test_read_write_png_noc(self):
        input_filepath = "static/kitti_noc_000010_10.png"

        flow = flowpy.flow_read(input_filepath)

        _, output_filename = tempfile.mkstemp(suffix=".png")

        try:
            flowpy.flow_write(output_filename, flow)
            new_flow = flowpy.flow_read(output_filename)
            np.testing.assert_equal(new_flow, flow)
        finally:
            os.remove(output_filename)
示例#2
0
    def test_read_write_flo(self):
        input_filepath = "static/Dimetrodon.flo"
        flow = flowpy.flow_read(input_filepath)

        with tempfile.NamedTemporaryFile("wb", suffix=".flo") as f:
            flowpy.flow_write(f, flow)
            self.assertTrue(filecmp.cmp(f.name, input_filepath))
示例#3
0
    def test_flow_with_arrows(self):
        flow = flowpy.flow_read("static/kitti_occ_000010_10.png")

        fig, ax = plt.subplots()
        ax.imshow(flowpy.flow_to_rgb(flow))
        flowpy.attach_arrows(ax, flow, xy_steps=(20, 20), scale=1)

        plt.show()
示例#4
0
    def test_flow_arrows_and_coord(self):
        flow = flowpy.flow_read("static/Dimetrodon.flo")

        fig, ax = plt.subplots()
        ax.imshow(flowpy.flow_to_rgb(flow))
        flowpy.attach_arrows(ax, flow)
        flowpy.attach_coord(ax, flow)

        plt.show()
示例#5
0
    def test_forward_warp_rgb(self):
        flow = flowpy.flow_read("static/kitti_occ_000010_10.png")
        first_image = np.asarray(Image.open("static/kitti_000010_10.png"))
        second_image = np.asarray(Image.open("static/kitti_000010_11.png"))

        flow[np.isnan(flow)] = 0
        warped_second_image = flowpy.forward_warp(first_image, flow, k=1)

        fig, (ax_1, ax_2, ax_3) = plt.subplots(3, 1)
        ax_1.imshow(first_image)
        ax_2.imshow(flowpy.flow_to_rgb(flow))
        ax_3.imshow(warped_second_image)

        plt.show()
示例#6
0
    def test_backward_warp_greyscale(self):
        flow = flowpy.flow_read("static/kitti_occ_000010_10.png")
        first_image = np.asarray(
            Image.open("static/kitti_000010_10.png").convert("L"))
        second_image = np.asarray(
            Image.open("static/kitti_000010_11.png").convert("L"))

        flow[np.isnan(flow)] = 0
        warped_first_image = flowpy.backward_warp(second_image, flow)

        fig, (ax_1, ax_2, ax_3) = plt.subplots(3, 1)
        ax_1.imshow(first_image)
        ax_2.imshow(second_image)
        ax_3.imshow(warped_first_image)

        plt.show()
示例#7
0
    def test_flow_arrows_coord_and_calibration_pattern(self):
        flow = flowpy.flow_read("static/Dimetrodon.flo")
        height, width, _ = flow.shape
        image_ratio = height / width

        max_radius = flowpy.get_flow_max_radius(flow)

        fig, (ax_1, ax_2) = plt.subplots(
            1, 2, gridspec_kw={"width_ratios": [1, image_ratio]})

        ax_1.imshow(flowpy.flow_to_rgb(flow))
        flowpy.attach_arrows(ax_1, flow)
        flowpy.attach_coord(ax_1, flow)

        flowpy.attach_calibration_pattern(ax_2, flow_max_radius=max_radius)

        plt.show()
示例#8
0
 def test_flow_to_rgb(self):
     flow = flowpy.flow_read("static/Dimetrodon.flo")
     plt.imshow(flowpy.flow_to_rgb(flow))
     plt.show()
示例#9
0
        .png (as defined here)
    Visualizing optical flows with matplotlib
    Backward and forward warp
"""

# Examples a simple RGB plot
"""
This is the simplest example of how to use flowpy, it:
Reads a file using flowpy.flow_read.
Transforms the flow as an rgb image with flowpy.flow_to_rgb and shows it with matplotlib
"""

import flowpy
import matplotlib.pyplot as plt

flow = flowpy.flow_read("tests/data/kitti_occ_000010_10.flo")

fig, ax = plt.subplots()
ax.imshow(flowpy.flow_to_rgb(flow))
plt.show()

# Plotting arrows, showing flow values and a calibration pattern

# Flowpy comes with more than just RGB plots, the main features here are: - Arrows to quickly visualize the flow -
# The flow values below cursor showing in the tooltips - A calibration pattern side by side as a legend for your graph

flow = flowpy.flow_read("tests/data/Dimetrodon.flo")
height, width, _ = flow.shape

image_ratio = height / width
max_radius = flowpy.get_flow_max_radius(flow)
示例#10
0
import matplotlib.pyplot as plt
import numpy as np

from PIL import Image

import flowpy

flow = flowpy.flow_read("static/kitti_occ_000010_10.png")
first_image = np.asarray(Image.open("static/kitti_000010_10.png"))
second_image = np.asarray(Image.open("static/kitti_000010_11.png"))

flow[np.isnan(flow)] = 0
warped_first_image = flowpy.backward_warp(second_image, flow)

fig, axes = plt.subplots(3, 1)
for ax, image, title in zip(
        axes, (first_image, second_image, warped_first_image),
    ("First Image", "Second Image", "Second image warped to first image")):
    ax.imshow(image)
    ax.set_title(title)
    ax.set_axis_off()

plt.show()
import flowpy
import matplotlib.pyplot as plt

flow = flowpy.flow_read("static/Dimetrodon.flo")
height, width, _ = flow.shape

image_ratio = height / width
max_radius = flowpy.get_flow_max_radius(flow)

fig, (ax_1,
      ax_2) = plt.subplots(1,
                           2,
                           gridspec_kw={"width_ratios": [1, image_ratio]})

ax_1.imshow(flowpy.flow_to_rgb(flow))
flowpy.attach_arrows(ax_1, flow)
flowpy.attach_coord(ax_1, flow)

flowpy.attach_calibration_pattern(ax_2, flow_max_radius=max_radius)

plt.show()