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, mode=1, name="w1", capture=1): if mode == 1: cv.StartWindowThread() cv.NamedWindow(name, cv.CV_WINDOW_AUTOSIZE) self.camera_index = 0 self.name = name if capture == 1: self.capture = cv.CaptureFromCAM(self.camera_index)
def __init__(self, stereo, image, blob): global font rospy.Subscriber(blob, Blobs, callbackBlobs) rospy.Subscriber(stereo + "/left/" + image, Image, callbackImage) print "Subscribing to:" print "\t* " + blob print "\t* " + stereo + "/left/" + image cv.StartWindowThread() cv.NamedWindow(windowName) font = cv.InitFont(cv.CV_FONT_HERSHEY_SIMPLEX, 0.20, 1, thickness=2)
def mouse_point(img, name="Mouse Points", mode="S"): """ Displays input image and waits for user click on a point of the image. For each click, the (x, y) coordinates are retrieved. Two modes are possible: -Single : The function exits automatically on first click. Returns a list containing 1 (x,y) tuple. -Multiple : All clicks are saved. The function exists when the user types on keyboard Returns containing (x,y) tuples. --- Ex: img = cv.LoadImage("../data/tippy.jpg", cv.CV_LOAD_IMAGE_GRAYSCALE) mouse_points(img, name="mouse points", mode="S") """ if not isinstance(name, str): raise TypeError("(%s) Name :String expected!" % (sys._getframe().f_code.co_name)) if not isinstance(mode, str): raise TypeError("(%s) Mode :String expected!" % (sys._getframe().f_code.co_name)) global _mouse_pos cv.StartWindowThread() cv.NamedWindow(name, cv.CV_WINDOW_AUTOSIZE) cv.SetMouseCallback(name, _on_mouse) try : cv.ShowImage(name, img) except TypeError: raise TypeError("(%s) img : IplImage expected!" % (sys._getframe().f_code.co_name)) if mode == "S": _single_point() elif mode == "M": _multiple_points() else: raise ValueError("(%s) Mode can be either S (single) or M (multiple)" % (sys._getframe().f_code.co_name)) cv.DestroyWindow(name) return _mouse_pos
def show_image(img, window_name='img', wait=False): roscv.StartWindowThread() roscv.NamedWindow(window_name) roscv.ShowImage(window_name, img) if wait: roscv.WaitKey()
#Note: data should be of type sensor_msgs.msg.Image #rospy.loginfo(rospy.get_name()+"I heard some data from camera") global global_ros_image global_ros_image = data def listener(): rospy.init_node('my_image_listener', anonymous=True) rospy.Subscriber("wide_stereo/right/image_rect_color", msgImage, imageCallback) rospy.spin() if __name__ == '__main__': cv.NamedWindow('view') cv.StartWindowThread() rospy.init_node('my_image_listener', anonymous=True) a = rospy.Subscriber("wide_stereo/right/image_rect_color", msgImage, imageCallback) print 'sleeping now' #spin cycle. Similar to "spin_once" ? while (not global_ros_image): rospy.sleep(.1) if rospy.is_shutdown(): print '\nforcing an exit' break print 'waking and exiting now' if not rospy.is_shutdown(): a.unregister()