Merge pull request #2311 from SvenWe:master

This commit is contained in:
Roman Donchenko 2014-02-11 17:11:06 +04:00 committed by OpenCV Buildbot
commit 511e79aef7

View File

@ -5,7 +5,7 @@ Interactive Image Segmentation using GrabCut algorithm.
This sample shows interactive image segmentation using grabcut algorithm. This sample shows interactive image segmentation using grabcut algorithm.
USAGE : USAGE:
python grabcut.py <filename> python grabcut.py <filename>
README FIRST: README FIRST:
@ -63,14 +63,14 @@ def onmouse(event,x,y,flags,param):
if rectangle == True: if rectangle == True:
img = img2.copy() img = img2.copy()
cv2.rectangle(img,(ix,iy),(x,y),BLUE,2) 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 rect_or_mask = 0
elif event == cv2.EVENT_RBUTTONUP: elif event == cv2.EVENT_RBUTTONUP:
rectangle = False rectangle = False
rect_over = True rect_over = True
cv2.rectangle(img,(ix,iy),(x,y),BLUE,2) 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 rect_or_mask = 0
print " Now press the key 'n' a few times until no further change \n" print " Now press the key 'n' a few times until no further change \n"
@ -103,7 +103,7 @@ if len(sys.argv) == 2:
filename = sys.argv[1] # for drawing purposes filename = sys.argv[1] # for drawing purposes
else: else:
print "No input image given, so loading default image, lena.jpg \n" print "No input image given, so loading default image, lena.jpg \n"
print "Correct Usage : python grabcut.py <filename> \n" print "Correct Usage: python grabcut.py <filename> \n"
filename = '../cpp/lena.jpg' filename = '../cpp/lena.jpg'
img = cv2.imread(filename) img = cv2.imread(filename)
@ -117,7 +117,7 @@ cv2.namedWindow('input')
cv2.setMouseCallback('input',onmouse) cv2.setMouseCallback('input',onmouse)
cv2.moveWindow('input',img.shape[1]+10,90) cv2.moveWindow('input',img.shape[1]+10,90)
print " Instructions : \n" print " Instructions: \n"
print " Draw a rectangle around the object using right mouse button \n" print " Draw a rectangle around the object using right mouse button \n"
while(1): while(1):