-1
I wonder how to show the content captured via webcam (by videoCapture) in a window that only shows half of what the camera picks up, In opencv.
-1
I wonder how to show the content captured via webcam (by videoCapture) in a window that only shows half of what the camera picks up, In opencv.
1
Just get the image size using the attribute shape and then crop the image using slice (your image is an object of numpy.ndarray, which is a kind of list). See the example below:
import cv2
camera = cv2.VideoCapture(0)
r, frame = camera.read()
height, width = frame.shape[0:2]  # Obtém altura e largura da imagem
height //= 2                      # Corta a imagem no meio
# Obtém uma parte da imagem que vai de Y[0 - height] X[0 - width]
new_frame = frame[0:height, 0:width] 
cv2.imshow("Imagem Cortada", new_frame)
Browser other questions tagged python
You are not signed in. Login or sign up in order to post.
Try running this code and I got this error " new_frame = frame[0:height, 0:width] Typeerror: Slice indices must be integers or None or have an index method"
– junior54145
Oops, I made an error in the code and fixed the problem. The error was being caused because when splitting the
heightthe result was afloat, and cannot use float’s in the Slice. Try running this code again– JeanExtreme002
Actually this new code works, but for the sake of deepening if I wanted to take the other half the opposite side would be possible?
– junior54145
Of course, just do a simple calculation. To get the top half, you should start from ZERO point to half screen (
height / 2), soon, to get the other half just start from half the screen (height / 2) up to the size of the maximum screen that is theheight.– JeanExtreme002
And how I would do that in the code?
– junior54145
Replace row 8 with
new_frame = frame[height: height * 2, 0:width]– JeanExtreme002