def main(): # initialize OpenCV windows cv.NamedWindow('frame', cv.CV_WINDOW_AUTOSIZE) cv.MoveWindow('frame', 10, 10) cv.NamedWindow('edges', cv.CV_WINDOW_AUTOSIZE) cv.MoveWindow('edges', 200, 10) # initialize Simulator window pf = ParticleFilter(numParticles=1000) sim = Simulator(pf) # sim.start() sim.refresh() time.sleep(1) frame = cv.LoadImage(sys.argv[1]) if frame is None: print 'Error loading image %s' % sys.argv[1] return find_corners(frame, pf) sim.refresh() # Pause for key press while True: k = cv.WaitKey(33) if k == 'q': break
def main(): pf = ParticleFilter(numParticles=500) sim = Simulator(pf) # For testing sim.canvas.bind("<Button-1>", lambda evt: click_callback(evt, sim)) cv.NamedWindow('frame', cv.CV_WINDOW_AUTOSIZE) cv.MoveWindow('frame', 10, 10) cv.NamedWindow('edges', cv.CV_WINDOW_AUTOSIZE) cv.MoveWindow('edges', 600, 10) capture = cv.CaptureFromFile(sys.argv[1]) if capture is None: print 'Error opening file' return # for i in range(2200): # cv.GrabFrame(capture) thread.start_new_thread(update_loop, (capture, pf, sim)) # Main Tk loop sim.root.mainloop()
def angle(self, img): # extract position of red blue yellow markers # find distance between pairs # return angle from inverse cosine imgHSV = cv.CreateImage(cv.GetSize(img), 8, 3) cv.CvtColor(img, imgHSV, cv.CV_BGR2HSV) cv.NamedWindow("red", cv.CV_WINDOW_AUTOSIZE) cv.MoveWindow("red", 800, 0) cv.NamedWindow("blue", cv.CV_WINDOW_AUTOSIZE) cv.MoveWindow("blue", 800, 100) cv.NamedWindow("yellow", cv.CV_WINDOW_AUTOSIZE) cv.MoveWindow("yellow", 800, 200) dot_coords = [] # use the corresponding thresholds for each color of marker # for h_low, h_high, col in [self.red_hues, self.yellow_hues, self.blue_hues]: imgThresh = cv.CreateImage(cv.GetSize(img), 8, 1) cv.InRangeS(imgHSV, cv.Scalar(h_low, 70, 70), cv.Scalar(h_high, 255, 255), imgThresh) moments = cv.Moments(cv.GetMat(imgThresh)) x_mov = cv.GetSpatialMoment(moments, 1, 0) y_mov = cv.GetSpatialMoment(moments, 0, 1) area = cv.GetCentralMoment(moments, 0, 0) small_thresh = cv.CreateImage((self.fit_camera_width, self.fit_camera_height), 8, 1) cv.Resize(imgThresh, small_thresh) if col == "r": cv.ShowImage("red", small_thresh) elif col == "b": cv.ShowImage("blue", small_thresh) elif col == "y": cv.ShowImage("yellow", small_thresh) if area > 0: posX = float(x_mov)/float(area) posY = float(y_mov)/float(area) else: posX = 0 posY = 0 dot_coords.append([posX, posY]) r = dot_coords[0] y = dot_coords[1] b = dot_coords[2] # get side lengths y_r = self.dist(r[0], r[1], y[0], y[1]) r_b = self.dist(b[0], b[1], r[0], r[1]) y_b = self.dist(b[0], b[1], y[0], y[1]) # apply law of cosines angle_in_rads = math.pow(y_r, 2) + math.pow(r_b, 2) - math.pow(y_b, 2) denom = 2.0 * y_r * r_b if denom > 0: angle_in_rads /= 2.0 * y_r * r_b else: angle_in_rads = 0 rads = math.acos(angle_in_rads) # convert to degrees degs = rads * float(180.0 / math.pi) if degs < 0 or degs > 360: degs = 0 return degs
def init_GUI(): """ initializes open cv windows and creates images to display """ global D print print "Press 'q' in Ranges window to quit" # create window and image to show range values cv.NamedWindow("Ranges") cv.MoveWindow("Ranges", WIN_WIDTH / 2, WIN_HEIGHT / 2) D.image = cv.CreateImage((WIN_WIDTH, WIN_HEIGHT), 8, 3) # 8 is pixel depth and 3 is # of channels # window for Hough transformation if SHOW_HOUGH: cv.NamedWindow("HoughLines") cv.MoveWindow("HoughLines", WIN_WIDTH / 2 + WIN_HEIGHT, WIN_HEIGHT / 2) # image for Hough transformation D.hough = cv.CreateImage((WIN_WIDTH, WIN_HEIGHT), 8, 3) # image used for Hough transformation # initialize ROS subscription rospy.init_node("range_listener", anonymous=True) rospy.Subscriber("laserRangeData", LaserRangeData, range_callback) # initialize ROS service rospy.wait_for_service('tank') # wait until the motors are available D.tank = rospy.ServiceProxy('tank', Tank) # give initial values to range data before first callback D.ranges = [0] * REV
def createWindows(self): cv.NamedWindow('canny') #cv.NamedWindow('harris') cv.NamedWindow('sobel') cv.NamedWindow('output') cv.MoveWindow('canny', 0, 0) #cv.MoveWindow('harris', 650,0) cv.MoveWindow('sobel', 1300, 0) cv.MoveWindow('output', 0, 420)
def init_globals(): """ sets up the data we need in the global dictionary D """ # get D so that we can change values in it global D # our publishers, D.K_PUB D.K_PUB = rospy.Publisher('key_press_data', String) #D.BALL_PUB = rospy.Publisher('ball_location_data', String) #D.GOAL_PUB = rospy.Publisher('goal_location_data', String) #D.PIKA_PUB = rospy.Publisher('pika_location_data', String) D.LOCATION_PUB = rospy.Publisher('location_data', String) # put threshold values into D D.thresholds = { 'low_red': 0, 'high_red': 255, 'low_green': 0, 'high_green': 255, 'low_blue': 0, 'high_blue': 255, 'low_hue': 0, 'high_hue': 255, 'low_sat': 0, 'high_sat': 255, 'low_val': 0, 'high_val': 255 } # Set up the windows containing the image from the camera, # the altered image, and the threshold sliders. cv.NamedWindow('image') cv.MoveWindow('image', 0, 0) cv.NamedWindow('threshold') THR_WIND_OFFSET = 640 if D.half_size: THR_WIND_OFFSET /= 2 cv.MoveWindow('threshold', THR_WIND_OFFSET, 0) # Set the method to handle mouse button presses cv.SetMouseCallback('image', onMouse, None) # We have not created our "scratchwork" images yet D.created_images = False # Variable for key presses D.last_key_pressed = 255 # Create a connection to the Kinect D.bridge = cv_bridge.CvBridge() # camera for missile launcher D.camera = cv.CaptureFromCAM(-1)
def _make_windows(self): if self.windows_made: return windows = ['video', 'right', 'thresholded', 'motion', 'intensity', 'patch', 'big_patch'] for n in windows: cv.NamedWindow(n, 1) cv.MoveWindow("video", 0, 0) cv.MoveWindow("right", 800, 0) cv.MoveWindow("thresholded", 800, 0) cv.MoveWindow("intensity", 0, 600) cv.MoveWindow("motion", 800, 600) self.windows_made = True
def create_windows(): """Set up the windows containing the image from the kinect camera, the thresholded image, the threshold sliders, and the kinect range image. """ #Create window to show image from Kinect camera cv.NamedWindow('Image') cv.MoveWindow('Image', 0, 0) #Create window to show thresholded image cv.NamedWindow('Threshold') cv.MoveWindow('Threshold', 640, 0)
def display_images(image_list, max_x = 1200, max_y = 1000, save_images_flag=False): if image_list == []: return loc_x, loc_y = 0, 0 wins = [] # if save_images_flag: # save_images(image_list) for i, im in enumerate(image_list): window_name = 'image %d' % i wins.append((window_name, im)) cv.NamedWindow(window_name, cv.CV_WINDOW_AUTOSIZE) cv.MoveWindow(window_name, loc_x, loc_y) loc_x = loc_x + im.width if loc_x > max_x: loc_x = 0 loc_y = loc_y + im.height if loc_y > max_y: loc_y = 0 while True: for name, im in wins: cv.ShowImage(name, im) keypress = cv.WaitKey(10) if keypress & 255 == 27: break
def __init__(self): cv2.namedWindow('CaptureMouse') cv.MoveWindow('CaptureMouse', 0, 0) cv2.setMouseCallback('CaptureMouse', self.onmouse) self.drag_start = False self.image = cv.LoadImageM("blank_800x800.jpg") self.pointlist = []
def main(): global startframe tree = utils.open_project(sys.argv) if tree == None: return os.chdir("shot_slitscans") '''cv.NamedWindow("win", cv.CV_WINDOW_AUTOSIZE) cv.MoveWindow("win", 500, 200) cv.SetMouseCallback("win", mouse_callback)''' bg_img = cv.CreateImage((576, 576), cv.IPL_DEPTH_8U, 1) #cv.Set(bg_img, (180)) files = sorted(glob.glob("*.png")) print(files) i = 0 while i < len(files): file = files[i] startframe = int(file.split("_")[3].split(".")[0]) print(startframe) cap = cv.CreateFileCapture(file) img = cv.QueryFrame(cap) win_name = "%d" % (int( float(i + 1) * 100.0 / len(files))) + "% - " + file cv.NamedWindow(win_name, cv.CV_WINDOW_AUTOSIZE) cv.MoveWindow(win_name, 500, 200) cv.SetMouseCallback(win_name, mouse_callback) cv.ShowImage(win_name, bg_img) cv.ShowImage(win_name, img) key = cv.WaitKey(0) print(key) if key in [2555904, 1113939]: # right arrow i += 1 elif key in [2424832, 1113937]: # left arrow i -= 1 if i < 0: i = 0 elif key in [27, 1048603]: # ESC break elif key in [1113941]: # page up i -= 100 if i < 0: i = 0 elif key in [1113942]: # page down i += 100 else: print("Unknown key code: {}".format(key)) cv.DestroyWindow(win_name) src_dir = os.path.dirname(sys.argv[0]) os.chdir(src_dir) os.system("python 02_2_save-shots.py \"" + sys.argv[1] + "\"")
def display_single_image(img, name="Image", x_pos=0, y_pos=0, delay=0): """ Displays an image on screen. Position can be chosen, and time on screen too. Delay corresponds to the display time, in milliseconds. If delay =0, the Image stays on screen until user interaction. ---- Ex: img = cv.LoadImage("../data/tippy.jpg", cv.CV_LOAD_IMAGE_GRAYSCALE) display_single_image(img, "My Tippy", 0, 0, 100) """ #TODO: Still not implemented! if not isinstance(name, str): raise TypeError("(%s) Name :String expected!" % (sys._getframe().f_code.co_name)) if (not isinstance(x_pos, int)) \ or (not isinstance(x_pos, int)) \ or (not isinstance(x_pos, int)) : raise TypeError("(%s) Int expected!" % (sys._getframe().f_code.co_name)) cv.StartWindowThread() cv.NamedWindow(name) cv.MoveWindow(name, x_pos, y_pos) cv.ShowImage(name, img) cv.WaitKey(delay) cv.DestroyWindow(name)
def __init__(self): rospy.init_node('cam_shift_node') self.ROI = rospy.Publisher("roi", RegionOfInterest, queue_size=1) """ Create the display window """ self.cv_window_name = "Camshift Tracker" cv.NamedWindow(self.cv_window_name, 0) """ Create the cv_bridge object """ self.bridge = CvBridge() """ Subscribe to the raw camera image topic """ self.image_sub = rospy.Subscriber("/camera/image_raw", Image, self.image_callback) """ Set up a smaller window to display the CamShift histogram. """ cv.NamedWindow("Histogram", 0) cv.MoveWindow("Histogram", 700, 10) cv.SetMouseCallback(self.cv_window_name, self.on_mouse) self.drag_start = None # Set to (x,y) when mouse starts dragtime self.track_window = None # Set to rect when the mouse drag finishes self.hist = cv.CreateHist([180], cv.CV_HIST_ARRAY, [(0,180)], 1 ) self.backproject_mode = False
def show(self, window="PyVisionImage", pos=None, delay=1, size=None): ''' Displays the annotated version of the image using OpenCV highgui @param window: the name of the highgui window to use, this should already have been created using cv.NamedWindow or set newWindow=True @param pos: If newWindow, then pos is the (x,y) coordinate for the new window @param delay: A delay in milliseconds to wait for keyboard input (passed to cv.WaitKey). 0 delays indefinitely, 1 is good for live updates and animations. The window will disappear after the program exits. @param size: Optional output size for image, None=native size. @returns: a key press event, ''' cv.NamedWindow(window) if pos != None: cv.MoveWindow(window, pos[0], pos[1]) if size != None: x = pyvision.Image(self.resize(size).asAnnotated()) else: x = pyvision.Image(self.asAnnotated()) cv.ShowImage(window, x.asOpenCV()) key = cv.WaitKey(delay=delay) del x return key
def create_mtf(name, width, height, screen, distance_user): out = cv.CreateImage((width, height), 8, 1) b = math.log(width / 2.0) / width a = 1.0 / (b * width) d = 0.01 c = math.log(d) / height x_vector = [ 0.5 + 0.5 * math.sin(2 * math.pi * a * math.e**(b * val)) for val in xrange(width) ] y_vector = [d * math.e**(-c * val) for val in xrange(height)] for i in xrange(width): for j in xrange(height): out[j, i] = 255.0 * (x_vector[i]) * y_vector[j] cv.ShowImage("mtf", out) cv.MoveWindow("mtf", 0, 0) cv.SetMouseCallback("mtf", user_x, [width, height, a, b, screen, distance_user]) cv.SaveImage("mtf.png", out) cv.WaitKey(0)
def initUI(): """ initializes the UI and ROS publishers/subscribers """ global D # initialize openCV window cv.NamedWindow("LibraComplex") cv.MoveWindow("Ranges", WIN_WIDTH / 2, WIN_HEIGHT / 2) D.image = cv.CreateImage((WIN_WIDTH, WIN_HEIGHT), 8, 3) # 8 is pixel depth and 3 is # of channels # initialize mouse click callback # see http://docs.opencv.org/modules/highgui/doc/user_interface.html#setmousecallback cv.SetMouseCallback("LibraComplex", onMouse, None) # initialize ROS publishers and subscribers rospy.init_node("node_nav", anonymous=True) rospy.Subscriber("hallwayType", HallwayType, command_callback) D.commandPub = rospy.Publisher("navCommand", NavCommand) # prepare map with TMap D.prev_type = None D.map = TMap() D.map.generateMap(LIBRA) D.start_node = 0 D.dst_node = 22 D.curr_node = D.start_node D.commands, D.cmd_path = D.map.generateCommands(D.start_node, D.dst_node) D.commands.append(["STOP", "STOP"]) D.cmd_path = D.cmd_path[1:-1]
def select_optimal_colors(self): # in case something else is still open cv.DestroyAllWindows() capture = cv.CaptureFromCAM(self.camera_index) if not capture: QMessageBox.information(self, "Camera Error", "Camera not found") return cv.NamedWindow("click & drag to select object", cv.CV_WINDOW_AUTOSIZE) cv.MoveWindow("click & drag to select object", 610, 0) cv.SetMouseCallback("click & drag to select object", self.mouseHandler, None) camera_on = True while camera_on: if (not self.busy_updating): frame = cv.QueryFrame(capture) if not frame: break cv.ShowImage("click & drag to select object", frame) self.frame = frame k = cv.WaitKey(1) # press q or escape to quit camera view if k == 27 or k == 113 or self.end_record: camera_on = False cv.DestroyAllWindows() self.end_record = False break
def dummy_window(): cv.NamedWindow('keyboard') cv.MoveWindow('keyboard', 0, 0) D.size = (100, 100) D.dummy = cv.CreateImage(D.size, 8, 1) D.created_images = True cv.ShowImage('keyboard', cv.Zero(D.dummy))
def main(): cv.NamedWindow('frame', cv.CV_WINDOW_AUTOSIZE) cv.MoveWindow('frame', 10, 10) cv.NamedWindow('edges', cv.CV_WINDOW_AUTOSIZE) cv.MoveWindow('edges', 600, 10) frame = cv.LoadImage(sys.argv[1]) if frame is None: print 'Error loading image %s' % sys.argv[1] return find_lines(frame) # Pause for key press while True: k = cv.WaitKey(33) if k == 'q': break
def initialize_gui(self): """Initializes GUI: - Windows for incoming images from left camera and right camera - Windows for thresholded image from left camera and right camera - Control window containing threshold sliders and threshold auto-select buttons. """ # Instantiate OpenCV windows for displaying incoming images cv.NamedWindow('Left Camera', 1) cv.MoveWindow('Left Camera', 0, 0) #cv.NamedWindow('Right Camera', 2) #cv.MoveWindow('Right Camera', 760, 0) # Set callback for mouse input to Left Camera window # Used to select regions of interest for target thresholding cv.SetMouseCallback('Left Camera', self.handle_mouse_left_camera, None) # Instantiate OpenCV windows for displaying thresholded image cv.NamedWindow('Left Threshold', 3) cv.MoveWindow('Left Threshold', 0, 480) #cv.NamedWindow('Right Threshold', 4) #cv.MoveWindow('Right Threshold', 760, 480) # Instantiate controls window cv.NamedWindow('Threshold Controls', 5) cv.MoveWindow('Threshold Controls', 760, 540) # Create sliders for tuning RGB thresholds cv.CreateTrackbar('low_hue', 'Threshold Controls', self.low_thresholds['hue'], 179, lambda x: self.change_slider('low', 'hue', x)) cv.CreateTrackbar('high_hue', 'Threshold Controls', self.high_thresholds['hue'], 179, lambda x: self.change_slider('high', 'hue', x)) cv.CreateTrackbar('low_sat', 'Threshold Controls', self.low_thresholds['sat'], 255, lambda x: self.change_slider('low', 'sat', x)) cv.CreateTrackbar('high_sat', 'Threshold Controls', self.high_thresholds['sat'], 255, lambda x: self.change_slider('high', 'sat', x)) cv.CreateTrackbar('low_val', 'Threshold Controls', self.low_thresholds['val'], 255, lambda x: self.change_slider('low', 'val', x)) cv.CreateTrackbar('high_val', 'Threshold Controls', self.high_thresholds['val'], 255, lambda x: self.change_slider('high', 'val', x))
def init_cam(self): try: cv.NamedWindow("drillEye", 1) cv.MoveWindow("drillEye", 288, 0) self.capture = cv.CreateCameraCapture(self.camera) except Exception, e: print("Error: %s" % e) exit(0)
def subsection_image(pil_img, sections, visual): sections = sections / 4 print "sections= ", sections fingerprint = [] # - -----accepts image and number of sections to divide the image into (resolution of fingerprint) # ---------- returns a subsectioned image classified by terrain type img_width, img_height = pil_img.size print "image size = img_wdith= ", img_width, " img_height=", img_height, " sections=", sections if visual == True: cv_original_img1 = PILtoCV(pil_img) cv.ShowImage("Original", cv_original_img1) cv.MoveWindow("Original", ((img_width) + 100), 50) pil_img = rgb2I3(pil_img) #cv.WaitKey() temp_img = pil_img.copy() xsegs = img_width / sections ysegs = img_height / sections print "xsegs, ysegs = ", xsegs, ysegs for yy in range(0, img_height - ysegs + 1, ysegs): for xx in range(0, img_width - xsegs + 1, xsegs): print "Processing section =", xx, yy, xx + xsegs, yy + ysegs box = (xx, yy, xx + xsegs, yy + ysegs) print "box = ", box cropped_img1 = pil_img.crop(box) I3_mean = ImageStat.Stat(cropped_img1).mean I3_mean_rgb = (int(I3_mean[0]), int(I3_mean[1]), int(I3_mean[2])) print "I3_mean: ", I3_mean sub_ID = classifiy_section(I3_mean_rgb) fingerprint.append(sub_ID) if visual == True: cv_cropped_img1 = PILtoCV(cropped_img1) cv.ShowImage("Fingerprint", cv_cropped_img1) cv.MoveWindow("Fingerprint", (img_width + 100), 50) if sub_ID == 1: I3_mean_rgb = (50, 150, 50) if sub_ID == 2: I3_mean_rgb = (150, 150, 150) if sub_ID == 3: I3_mean_rgb = (0, 0, 200) ImageDraw.Draw(pil_img).rectangle(box, (I3_mean_rgb)) cv_img = PILtoCV(pil_img) cv.ShowImage("Image", cv_img) cv.MoveWindow("Image", 50, 50) cv.WaitKey(50) #time.sleep(.05) #print "FINGERPRINT: ", fingerprint #cv.WaitKey() return fingerprint
def show(im, title="Image"): global size # I know, bad practice... cv.NamedWindow(title) im2 = max_size(im, (640, 480)) cv.ShowImage(title, im2) cv.MoveWindow(title, size[0], size[1]) size[0] += 20 size[1] += 20
def init_GUI(): """ initializes open cv windows and creates images to display """ global D print print "Press 'q' in Ranges window to quit" # initialize the font D.font = cv.InitFont(cv.CV_FONT_HERSHEY_SIMPLEX, 1, 1, 0, 2, 8) # create window and image to show range values cv.NamedWindow("Ranges") cv.MoveWindow("Ranges", WIN_WIDTH / 2, WIN_HEIGHT / 2) D.image = cv.CreateImage((WIN_WIDTH, WIN_HEIGHT), 8, 3) # 8 is pixel depth and 3 is # of channels # window for Hough transformation if SHOW_HOUGH: cv.NamedWindow("HoughLines") cv.MoveWindow("HoughLines", WIN_WIDTH / 2 + WIN_HEIGHT, WIN_HEIGHT / 2) # image for Hough transformation D.hough = cv.CreateImage((WIN_WIDTH, WIN_HEIGHT), 8, 3) # image used for Hough transformation # initialize ROS subscription rospy.init_node("range_listener", anonymous=True) rospy.Subscriber("scan", LaserScan, range_callback) rospy.Subscriber("navCommand", NavCommand, nav_callback) # initialize ROS publishers D.hallwayType = rospy.Publisher("hallwayType", HallwayType) D.motorPub = rospy.Publisher("couchMotors", MotorCommand) # initialize ROS service #rospy.wait_for_service('tank') # wait until the motors are available #D.tank = rospy.ServiceProxy('tank',Tank) # replaces the service above D.tank = _motor_broadcast # give initial values to range data before first callback D.ranges = [0] * REV
def __init__(self): #Dictionary containing the threshold values that the sliders correspond #to, each is initially set to 128, the mid value. self.thresholds = {'low_red': 128, 'high_red': 128,\ 'low_green': 128, 'high_green': 128,\ 'low_blue': 128, 'high_blue': 128,\ 'low_hue': 128, 'high_hue': 128,\ 'low_sat': 128, 'high_sat': 128,\ 'low_val': 128, 'high_val': 128} #Set up the windows containing the image from the kinect, the altered #image, and the threshold sliders. cv.NamedWindow('image') cv.MoveWindow('image', 320, 0) cv.NamedWindow('threshold') cv.MoveWindow('threshold', 960, 0) cv.NamedWindow('hsv') cv.MoveWindow('hsv', 320, 450) self.make_slider_window() #self.bridge = cv_bridge.CvBridge() #self.capture = cv.CaptureFromCAM(0) #self.image = cv.QueryFrame(self.capture) self.image_orig = cv.LoadImageM('room1.jpg') self.image_color = cv.LoadImageM('room1.jpg') self.image = cv.LoadImageM('room1.jpg') self.size = cv.GetSize(self.image) self.hsv = cv.CreateImage(self.size, 8, 3) cv.SetMouseCallback('image', self.mouse_callback, True) self.RGBavgs = () self.RGBvals = [] self.HSVavgs = () self.HSVvals = [] self.new_color = (128, 0, 0) self.new_hsv = (0, 255, 255) self.hue = 0
def test_thresholded_image(): capture = cv.CaptureFromCAM(MY_CAMERA) image = cv.QueryFrame(capture) image_threshed = thresholded_image(image) cv.NamedWindow('test', cv.CV_WINDOW_AUTOSIZE) cv.MoveWindow('test', 100, 100) cv.ShowImage('test', image_threshed) cv.WaitKey(1000) exit(0)
def update_high_color(self, pos): self.busy_updating = True self.high_color = pos cv.NamedWindow("End at color", cv.CV_WINDOW_AUTOSIZE) cv.MoveWindow("End at color", 750, 0) color_swatch = cv.CreateImage((200, 140), 8, 3) cv.Set(color_swatch, HSV_to_RGB(self.high_color)) cv.ShowImage("End at color", color_swatch) self.busy_updating = False
def main(): cv.NamedWindow("img", 0) cv.MoveWindow("img", 200, 200) cv.NamedWindow("out", 0) cv.MoveWindow("out", 200, 600) cam = cv.CreateCameraCapture(0); while True: frame = cv.QueryFrame(cam) cv.ShowImage("img", frame) out = process_frame(frame) cv.ShowImage("out", out) print get_pixel_center(out) if (cv.WaitKey(23) == 'q'): break
def show(self, window=None, pos=None, delay=0, size=None): ''' Displays the annotated version of the image using OpenCV highgui @param window: the name of the highgui window to use, if one already exists by this name, or it will create a new highgui window with this name. @param pos: if a new window is being created, the (x,y) coordinate for the new window @param delay: A delay in milliseconds to wait for keyboard input (passed to cv.WaitKey). 0 delays indefinitely, 30 is good for presenting a series of images like a video. For performance reasons, namely when using the same window to display successive frames of video, we don't want to tear-down and re-create the window each time. Thus the window frame will persist beyond the scope of the call to img.show(). The window will disappear after the program exits, or it can be destroyed with a call to cv.DestroyWindow. @param size: Optional output size for image, None=native size. @returns: the return value of the cv.WaitKey call. ''' if window == None and pv.runningInNotebook() and 'pylab' in globals( ).keys(): # If running in notebook, then try to display the image inline. if size == None: size = self.size # Constrain the size of the output max_dim = max(size[0], size[1]) if max_dim > 800: scale = 800.0 / max_dim size = (int(scale * size[0]), int(scale * size[1])) w, h = size # TODO: Cant quite figure out how figsize works and how to set it to native pixels #pylab.figure() IPython.core.pylabtools.figsize(1.25 * w / 72.0, 1.25 * h / 72.0) pylab.figure() pylab.imshow(self.asAnnotated(), origin='lower', aspect='auto') else: # Otherwise, use an opencv window if window == None: window = "PyVisionImage" cv.NamedWindow(window) if pos != None: cv.MoveWindow(window, pos[0], pos[1]) if size != None: x = pyvision.Image(self.resize(size).asAnnotated()) else: x = pyvision.Image(self.asAnnotated()) cv.ShowImage(window, x.asOpenCV()) key = cv.WaitKey(delay=delay) del x return key
def initialize_interface(): """Initializes all windows needed by our program.""" #Create window to monitor robot status cv.NamedWindow('Monitor') cv.MoveWindow('Monitor', 0, 0) D.size = (100, 100) D.dummy = cv.CreateImage(D.size, 8, 1) D.image = cv.Zero(D.dummy) cv.ShowImage('Monitor', D.image)