Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to construct a Rect object in opencv 3 in python?

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().

like image 374
Amit Keinan Avatar asked Oct 13 '25 11:10

Amit Keinan


1 Answers

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)

like image 61
Ishara Madhawa Avatar answered Oct 15 '25 01:10

Ishara Madhawa