diffdrive

Differential Drive Chapter

Our simulated differential drive robot has a camera, so a lot of the code here is support for some computer vision.

Pinhole Figures

Some plotting support code to illustrate the pinhole camera model.


source

show_3d

 show_3d (fig)

source

ray

 ray (point3, F, color='orange')

source

plane

 plane (Z:float)

source

axes

 axes (length=1.5)

Add axes to a plotly figure

feet = gtsam.Point3(-3,0,5) # point at the feet of the person, 5 meters in front of camera, 3 meters to the left
head = gtsam.Point3(-3,-2,5) # point at the top of the head (note, Y = *minus* 2 meters)
F = 1 # meter
show_3d(go.Figure(data = plane(-F) + [ray(feet, -F), ray(head, -F)] + axes()))

show_3d(go.Figure(data = plane(F) + [ray(feet, F), ray(head, F)] + axes()))

Reading Images


source

read_image

 read_image (image_name)

Read image from a the book repo

image_name = "LL_color_1201754063.387872.bmp"
image = read_image(image_name) # locally: PIL.Image.open(image_name)
print(f"resolution = {image.width}x{image.height}")
resolution = 512x384
import matplotlib.pyplot as plt
plt.imshow(image);

from PIL import ImageOps
grayscale_image = PIL.ImageOps.grayscale(image)
plt.imshow(grayscale_image, cmap="gray");

Easy Convolution


source

conv2

 conv2 (input, filter)

Convolve input image of shape (iW,iH) with filter of shape (kW,kH)

grayscale = torch.from_numpy(np.asarray(grayscale_image, dtype=float))
print(f"type={type(grayscale)}, dtype={grayscale.dtype}, shape={grayscale.shape}")
filter = torch.tensor([[-1.0, 0.0, 1.0]], dtype=float)
filter.shape
type=<class 'torch.Tensor'>, dtype=torch.float64, shape=torch.Size([384, 512])
torch.Size([1, 3])
vertical_edges = conv2(grayscale, filter)
plt.imshow(vertical_edges, cmap="RdYlGn");