# get the value, and scale to the size of the hist image val = cv.cvRound( cv.cvGetReal1D(hist.bins, i) * histimg.height / 255) # compute the color color = hsv2rgb(i * 180. / hdims) # draw the rectangle in the wanted color cv.cvRectangle(histimg, cv.cvPoint(i * bin_w, histimg.height), cv.cvPoint((i + 1) * bin_w, histimg.height - val), color, -1, 8, 0) # Make the sweet negative selection box if mouse_select_object and mouse_selection.width > 0 and mouse_selection.height > 0: a = cv.cvGetSubRect(frame, mouse_selection) cv.cvXorS(a, cv.cvScalarAll(255), a) # Take the negative of the image.. del a # Carry out the histogram tracking... if track_object != 0: cv.cvInRangeS(hsv, cv.cvScalar(0, smin, min(vmin, vmax), 0), cv.cvScalar(180, 256, max(vmin, vmax), 0), mask) cv.cvSplit(hsv, hue, None, None, None) if track_object < 0: # Calculate the histogram for the mouse_selection box hue_roi_rect = cv.cvGetSubRect(hue, mouse_selection) mask_roi_rect = cv.cvGetSubRect(mask, mouse_selection) cv.cvCalcHist(hue_roi_rect, obj_hist, 0, mask_roi_rect) min_val, max_val, min_idx, max_idx = cv.cvGetMinMaxHistValue( obj_hist)
# get the value, and scale to the size of the hist image val = cv.cvRound (cv.cvGetReal1D (hist.bins, i) * histimg.height / 255) # compute the color color = hsv2rgb (i * 180. / hdims) # draw the rectangle in the wanted color cv.cvRectangle (histimg, cv.cvPoint (i * bin_w, histimg.height), cv.cvPoint ((i + 1) * bin_w, histimg.height - val), color, -1, 8, 0) # Make the sweet negative selection box if mouse_select_object and mouse_selection.width > 0 and mouse_selection.height > 0: a = cv.cvGetSubRect(frame,mouse_selection) cv.cvXorS(a,cv.cvScalarAll(255), a) # Take the negative of the image.. del a # Carry out the histogram tracking... if track_object != 0: cv.cvInRangeS( hsv, cv.cvScalar(0,smin ,min(vmin, vmax), 0), cv.cvScalar(180, 256, max(vmin,vmax), 0), mask ) cv.cvSplit(hsv, hue, None, None, None) if track_object < 0: # Calculate the histogram for the mouse_selection box hue_roi_rect = cv.cvGetSubRect( hue, mouse_selection ) mask_roi_rect = cv.cvGetSubRect( mask, mouse_selection ) cv.cvCalcHist (hue_roi_rect, obj_hist, 0, mask_roi_rect) min_val, max_val, min_idx, max_idx = cv.cvGetMinMaxHistValue (obj_hist) track_window = mouse_selection
cv.cvEllipseBox(image, track_box, cv.CV_RGB(255,0,0), 3, cv.CV_AA, 0) if (track_box.size.width > 10 or track_box.size.height > 10): rotate = ( (image.width/2.0) - track_box.center.x) / (image.width/2.0) translate = ((image.height/2.0) - track_box.center.y) / (image.height/2.0) #print "rotate =", rotate, "translate =", translate if go: move(translate, rotate) if select_object and selection.width > 0 and selection.height > 0: subimg = cv.cvGetSubRect(image, selection) cv.cvXorS( subimage, cv.cvScalarAll(255), subimage, 0 ) highgui.cvShowImage( "VisualJoystick", image ) c = highgui.cvWaitKey(10) if c == '\x1b': break elif c == 'b': backproject_mode ^= 1 elif c == 'c': track_object = 0 cv.cvZero( histimg ) if go: stop() if go:
if (track_box.size.width > 10 or track_box.size.height > 10): rotate = ((image.width / 2.0) - track_box.center.x) / (image.width / 2.0) translate = ((image.height / 2.0) - track_box.center.y) / (image.height / 2.0) #print "rotate =", rotate, "translate =", translate if go: move(translate, rotate) if select_object and selection.width > 0 and selection.height > 0: subimg = cv.cvGetSubRect(image, selection) cv.cvXorS(subimage, cv.cvScalarAll(255), subimage, 0) highgui.cvShowImage("VisualJoystick", image) c = highgui.cvWaitKey(10) if c == '\x1b': break elif c == 'b': backproject_mode ^= 1 elif c == 'c': track_object = 0 cv.cvZero(histimg) if go: stop() if go: