I tried to create it by writing the command:
myRect = cv2.Rect(p1, p2)
but it does not find it. It writes:
Cannot find reference 'Rect' in 'imported module cv2'.
thanks for helping!
to make it clearer: I don't want to draw a rectangle on an image. I want to create a Rect object to apply methods on, such as area().
You can try something like this:
import cv2
import numpy as np
img = cv2.imread('input.jpg')
myRect = img[280:340, 330:390]
280:340
, 330:390
means: get a rectangle that begins at 280th row and 330th column and ends at 340th row and 390 column. So coordinates of the rectangle would be: (280,330), (280,390), (340,330), (340,390)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With