How to crop/zoom-on a video capture, by scaling the default capture resolution?

I store the camera resolution like this:

# Resolution of the camera capture & display.
res_w = 1440
res_h = 1080
resolution = (res_w, res_h)

How would I go about cropping the middle of the image (because my camera is a fix point, and I want my program to only detect what’s on the middle)?

take a look at numpy slicing.

x0 = res_w // 2 - 400 # 400px left of center
x1 = res_w // 2 + 400 # 400px right of center
y0...
cropped = img[y0:y1, x0:x1] # slicing
1 Like