Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to perform intersection or union operations on a rect in Python?

I saw a question that is solved by using & (intersection) on rectangles http://answers.opencv.org/question/67091/how-to-find-if-2-rectangles-are-overlapping-each-other/

I am trying to do the same in python.

I draw the rectangles like this:

for rect in rects_new:
    #print (str(type(rect))) #<class 'numpy.ndarray'>
    #print (rect.area()) # gives error that 'numpy.ndarray' object has no attribute 'area'
    cv2.rectangle(vis, (rect[0],rect[1]), (rect[0]+rect[2],rect[1]+rect[3]), (0, 255, 255), 2)

but the rectangles are overlapping. I would only like to keep the outermost rectangle. However, I don't know how to perform & intersect operations. I can't even call area() on it.