def mouseImage(event, x, y, flags, param): """Handles incoming mouse input to the Image window.""" if event==cv.CV_EVENT_LBUTTONDOWN: #Clicked the left button print "x, y are", x, y (b,g,r) = D.image[y,x] print "r,g,b is", int(r), int(g), int(b) (h,s,v) = D.hsv[y,x] print "h,s,v is", int(h), int(s), int(v) D.down_coord = (x,y) D.mouse_down = True elif event==cv.CV_EVENT_LBUTTONUP: #Let go of the left button print "x, y are", x, y (b,g,r) = D.image[y,x] print "r,g,b is", int(r), int(g), int(b) (h,s,v) = D.hsv[y,x] print "h,s,v is", int(h), int(s), int(v) D.up_coord = (x,y) D.mouse_down = False if D.mode == "clear": D.sections = [] else: #Start, add, or subtract -- put lower coordinates first x0, y0, x1, y1 = D.down_coord[0], D.down_coord[1], D.up_coord[0], D.up_coord[1] if x0 > x1: x0, x1 = x1, x0 if y0 > y1: y0, y1 = y1, y0 if D.mode == "start": D.sections = [] mode_dict = {"start":'a', "add":'a', "subtract":'s'} D.sections.append([mode_dict[D.mode], (x0, y0), (x1, y1)]) ImageProcessing.process_section(D) elif event == cv.CV_EVENT_RBUTTONDOWN: #Right click D.target_coord = (x, y) ImageProcessing.target_coord(D) elif D.mouse_down and event==cv.CV_EVENT_MOUSEMOVE: #Mouse just moved D.up_coord = (x,y)