grabcut.py sample: Allow drawing rect from bottom/right

The grabcut sample script isn't able to create rectangles correctly that are
drawn from e.g. bottom-right to top-left.
This small commit uses four min() calls to determine the correct
top-left point of the rectangle.
It also removes some unnecessary white spaces before colons.
This commit is contained in:
Sven Wehner 2014-02-10 16:45:28 +01:00
parent 86b6c48712
commit f7041bacc0

View File

@ -63,14 +63,14 @@ def onmouse(event,x,y,flags,param):
if rectangle == True:
img = img2.copy()
cv2.rectangle(img,(ix,iy),(x,y),BLUE,2)
rect = (ix,iy,abs(ix-x),abs(iy-y))
rect = (min(ix,x),min(iy,y),abs(ix-x),abs(iy-y))
rect_or_mask = 0
elif event == cv2.EVENT_RBUTTONUP:
rectangle = False
rect_over = True
cv2.rectangle(img,(ix,iy),(x,y),BLUE,2)
rect = (ix,iy,abs(ix-x),abs(iy-y))
rect = (min(ix,x),min(iy,y),abs(ix-x),abs(iy-y))
rect_or_mask = 0
print " Now press the key 'n' a few times until no further change \n"