py123d_detection.torch.data.images¶
How a camera image becomes network input: one affine map, applied once.
Every step between the sensor and the network is an axis-aligned affine map of pixel
coordinates: the rig’s fixed row crop and resize (rigs), the
scale that makes the image cover the network input, the crop window, the horizontal flip. So the
whole chain is one 3x3 matrix A, and it is used twice:
image_out = warpAffine(image, A) # one resampling of the source pixels
intrinsics = A @ intrinsics # the camera that would have taken image_out
Because both come from the same matrix, pixels and projection cannot disagree. The thesis
pipeline resized twice (to the rig’s size, then by the augmentation scale), which cost a second
interpolation and left the intrinsics and the pixels a fraction of a pixel apart, because
cv2.resize samples at pixel centres and the matrix scaled about the corner.
What is chosen per sample lives in ImageDraw, a zoom, a horizontal crop position and a
flip, shared by every camera of the frame. ImagePipeline.resolve() turns a draw into
the concrete transform for one camera’s size. The validation path is the default draw: no zoom,
centred, not flipped.
Functions
|
Resample |
Classes
|
The per-sample choices of the image transform, independent of any camera's size. |
|
The network input every camera is mapped to. |
|
The resize, crop and flip for one camera, resolved against its size. |
- class py123d_detection.torch.data.images.ImageDraw(zoom=1.0, crop_x=0.5, flip=False)[source]¶
Bases:
objectThe per-sample choices of the image transform, independent of any camera’s size.
- zoom: float = 1.0¶
Scale relative to the smallest one at which the image covers the network input. Above one the network sees a magnified part of the view; the validation path uses exactly one.
- class py123d_detection.torch.data.images.ImageTransform(resize, crop, flip)[source]¶
Bases:
objectThe resize, crop and flip for one camera, resolved against its size.
- resize: Tuple[float, float]¶
Scale applied to width and height. Equal in
cropmode, independent instretchmode.
- crop: Tuple[int, int, int, int]¶
(x0, y0, x1, y1)of the window taken out of the resized image. It may reach past the image’s edge; what lies outside is black.
- matrix()[source]¶
The 3x3 map from the input’s pixel coordinates to the output’s.
Pixel centres sit on integer coordinates, so a window
Wpixels wide mirrors asx -> W - 1 - x, which is also whatcv2.flipdoes. PETR mirrors asx -> W - xin the intrinsics while flipping the pixels withcv2.flip, which left every flipped camera’s projection one pixel off its image.- Return type:
- class py123d_detection.torch.data.images.ImagePipeline(size=(320, 800), mode='crop', pad_divisor=32)[source]¶
Bases:
objectThe network input every camera is mapped to.
- Parameters:
mode (
str) –"crop"scales by one factor until the image coverssize, then cutssizeout, bottom-aligned so the road is kept and the sky is lost. It keeps the pixel scale the same across cameras and is what PETR does."stretch"resizes straight tosize, distorting the aspect ratio but keeping the whole field of view; it ignores the zoom and the crop position of a draw.
- pad_divisor: int = 32¶
Pad up to a multiple of this, so a convolutional backbone’s strides divide it.
- resolve(draw, height, width)[source]¶
The transform
drawmeans for an image ofheightbywidthpixels.An
ImageTransformis already resolved and comes back unchanged, which is how a test or a debugging session replays one exact transform.- Return type: