Camera frames and frame rate
English translation
Learning objectives
Choosing a resolution and capture interval requires understanding the trade-offs among storage, field of view, and frame rate.
Execution conditions
Inputs: a generated image and timestamps. The real capture example uses Picamera2 on Raspberry Pi OS. If it is not installed in the OS, run sudo apt install python3-picamera2 in a terminal.
Image size and memory
Starting conditions
Use the 120×160×3 uint8 RGB image generated by the provided NumPy code.
Procedure
- Record the dimensions, channels, data type, and nbytes.
- Display the image reduced with [::2,::2] alongside the original.
- Compare the spatial size ratio with the ratio of stored array bytes.
Results to retain
- Original and reduced images, and a statistics table.
import numpy as np
import matplotlib.pyplot as plt
x,y=np.meshgrid(np.linspace(0,255,160),np.linspace(0,255,120))
frame=np.stack([x,y,255-x],axis=-1).astype(np.uint8)
small=frame[::2,::2]
print(frame.shape,frame.nbytes,small.shape,small.nbytes)
# TODO: Record comparison plots and ratios.
Record results and self-check
Video:
shape:
dtype:
Array bytes:
Ratio to original:
Points to check
- Did you avoid calling the array byte count the JPEG file size?
- Did you check how halving both axes changes the pixel count?
Calculate frame rate from timestamps
Starting conditions
Use the acquisition timestamps s.
Procedure
- Use
np.diff(timestamp)to calculate the five frame intervals. Calculate observed FPS as the reciprocal of the mean of these five intervals. - List each interval alongside the reference s, and mark the start and end times of the longest interval. Plot interval number on the x-axis and frame interval [s] on the y-axis.
- Record the assumed requested rate of 30 FPS, the calculated observed FPS, and the number of frames in the timestamp record as separate items.
Results to retain
- A table for 5 intervals and an interval plot.
timestamp=np.array([0,.033,.067,.100,.150,.183])
intervals=np.diff(timestamp)
print('observed FPS',1/intervals.mean())
# TODO: Create tables and plots for each interval.
Record results and self-check
Interval:
Δt [s]:
1/Δt by interval [Hz]:
Observed delay:
Points to check
- Did you distinguish the total frame count divided by the last timestamp from the interval-based value?
- Did you check the timestamp units?
Region of interest and configuration choices
Starting conditions
Select row=20:80, col=40:120 of the original frame as the ROI, and compare it with the reduced full image.
Procedure
- Record the ROI coordinates and size, and the size of the reduced full image.
- Explain the differences in the field of view and detail preserved by the two.
- If actual camera frames and a frame rate are available, add one image captured using the same principles, and record the backend and resolution.
Results to retain
- ROI and reduced images, and 3 sentences explaining your configuration choices.
roi=frame[20:80,40:120]
# TODO: Compare the ROI, resized full image, and original in the same panel.
Record results and self-check
Method:
Region and resolution:
Preserved field of view:
Remaining detail:
Points to check
- Did you distinguish NumPy rows and columns from image x and y coordinates?
- Did you label results as hardware results only if you added real image capture?