I'm an absolute beginner in Python and I'm writing a program that uses my laptop's webcam.
I want to crop the output according to a crop factor and it seemed as easy as:
w = 1280
h = 720
crop_factor = 0.5
x_crop_start = int((w-w*crop_factor)/2)
x_crop_end = int(w-x_crop_start)
y_crop_start = int((h-h*crop_factor)/2)
y_crop_end = int(h-y_crop_start)
cropped_image = shifted_img[y_crop_start:y_crop_end, x_crop_start:x_crop_end]
Now the problem is my code doesn't work and I can't seem to understand the error shown on the console:
File "/Users/iacopo/Desktop/pyPong/faceStabilizer.py", line 74, in cv2.imshow("cropped", cropped_image) cv2.error: OpenCV(4.5.3) /private/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/pip-req-build-8g_88acj/opencv/modules/highgui/src/window.cpp:1006: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'imshow'
if I manually replace the variable names with integers everything works fine. Also if I leave y_crop_start and x_crop_start as variable names, but manually enter integers after the semicolon everything works just fine:
cropped_image = shifted_img[y_crop_start:500, x_crop_start:720]
I'm sure there's an easy fix and I feel very dumb for being stuck here.