python类Image()的实例源码

asus.py 文件源码 项目:Face-Recognition-for-Mobile-Robot 作者: gagolucasm 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def __init__(self):

        global et
    global recognizer
    global dictid, labels
        self.engine1 = pyttsx.init()
    self.engine = pyttsx.init()
    self.engine1.say('Initializing components.         All systems ready.')
        self.engine1.runAndWait()
        self.bridge = CvBridge()
        self.image_sub = rospy.Subscriber("/camera/rgb/image_raw",Image,self.callback)
    recognizer = cv2.face.createLBPHFaceRecognizer()
    et = libs.EyeTracker("cascades/haarcascade_frontalface_alt2.xml")
    i=0
    path = 'faces'
    images,labels,dictid=libs.read_data(path)
    print labels
    recognizer.train(images, np.array(labels))
    print 'termine'
    self.num=0
vision1.py 文件源码 项目:racecar_7 作者: karennguyen 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def __init__(self):
        self.bridge = CvBridge() #allows us to convert our image to cv2

        self.zed_pub = rsp.Publisher("/image_echo", Image, queue_size = 1)
        self.imginfo_pub = rsp.Publisher("/exploring_challenge", img_info, queue_size = 1)

        self.zed_img = rsp.Subscriber("/camera/rgb/image_rect_color", Image, self.detect_img) #subscribes to the ZED camera image
        self.odom_sub = rsp.Subscriber("/vesc/odom", Odometry, self.odom_callback)

        self.last_arb_position = Point()
        self.gone_far_enough = True

        self.header = std_msgs.msg.Header()
        self.heightThresh = 75 #unit pixels MUST TWEAK
        self.odomThresh = 1 #unit meters
        self.blob_msg = img_info()

        rsp.init_node("vision_node")
cup_tracking.py 文件源码 项目:shell_game 作者: BlakeStrebel 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def __init__(self):
        self.bridge = CvBridge()
        # initializes subscriber for Baxter's left hand camera image topic
        self.image_sub = rospy.Subscriber("/cameras/left_hand_camera/image",Image,self.find_cups)
        # initializes subscriber for the location of the treasure (published by the find_treasure node)
        self.treasure_location_sub = rospy.Subscriber("/treasure_location",Treasure,self.find_treasure)
        # initializes publisher to publish the location of the cup containing the treasure
        self.treasure_cup_pub = rospy.Publisher("treasure_cup_location",Point,queue_size=10)
        # initializes publisher to publish the processed image to Baxter's display
        self.image_tracking_pub = rospy.Publisher("/robot/xdisplay",Image,queue_size=10)
        self.treasure_cup_location = Point()
        self.cups = []
        self.cupCenters = [[0,0],[0,0],[0,0]]
        self.wasPreviouslyTrue = False
        self.flag = False
        self.minRadius = 10
        for i in range(0,3):
            self.cups.append(cup())

    # determines the location of the 3 red cups (callback for the image topic subscriber)
image_buffer.py 文件源码 项目:perception 作者: BerkeleyAutomation 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def callback(data):
        """Callback function for subscribing to an Image topic and creating a buffer
        """
        global dtype
        global images_so_far

        # Get cv image (which is a numpy array) from data
        cv_image = bridge.imgmsg_to_cv2(data)
        # Save dtype before we float32-ify it
        dtype = str(cv_image.dtype)
        # Insert and roll buffer
        buffer.insert(0, (np.asarray(cv_image, dtype='float32'), rospy.get_time()))
        if(len(buffer) > bufsize):
            buffer.pop()

        # for showing framerate
        images_so_far += 1

    # Initialize subscriber with our callback
vis_tools.py 文件源码 项目:baxter 作者: destrygomorphous 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def make_mask(limb, filename):

    """
    Given a limb (right or left) and a name to save to
    (in the baxter_tools/share/images/ directory),
    create a mask of any dark objects in the image from the camera
    and save it.
    """

    image_sub = rospy.Subscriber(
        '/cameras/' + limb + '_hand_camera/image',Image,callback)


    try:
        bridge = CvBridge()
        cv_image = bridge.imgmsg_to_cv2(img, "bgr8")
    except CvBridgeError, e:
        print e

    msk = cv2.threshold(img, 250, 255, cv2.THRESH_BINARY_INV)
    return msk
bbox_node.py 文件源码 项目:objectattention 作者: cdevin 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def __init__(self, box_features, camera_channel='/camera_crop/image_rect_color',
                 bbox_channel='/objectattention/bbox', feat_channel='/objectattention/features',
                 similarity_channel='/objectattention/similarity'):
        """ weights should be a dictionary with variable names as keys and weights as values
        """
        print "start"
        self._camera_channel = camera_channel
        self.curr_img = None
        self.fps = None
        print "session"
        self.init_model(box_features)
        self.temp = 1
        self.bbox_publisher =rospy.Publisher(bbox_channel, Float64MultiArray, queue_size =1)
        self.feat_publisher =rospy.Publisher(feat_channel, Float64MultiArray, queue_size =1)
        self.similarity_publisher =rospy.Publisher(similarity_channel, Float64MultiArray, queue_size =1)
        self.image_subscriber = rospy.Subscriber(camera_channel, Image, self._process_image)
        self.msg = None

        rospy.init_node('image_proc',anonymous=True)
sitl_file.py 文件源码 项目:formulapi_ROS_simulator 作者: wilselby 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def __init__(self):
      self.imgprocess = ImageProcessor.ImageProcessor()
      self.bridge = CvBridge()
      self.latestimage = None
      self.process = False

      """ROS Subscriptions """
      self.image_pub = rospy.Publisher("/image_converter/output_video",Image, queue_size=10)
      self.image_sub = rospy.Subscriber("/cam/camera_/image_raw",Image,self.cvt_image)
      self.cmdVelocityPub = rospy.Publisher('/platform_control/cmd_vel', Twist, queue_size=10)

      self.targetlane = 0
      self.cmdvel = Twist()
      self.last_time = rospy.Time()
      self.sim_time = rospy.Time()
      self.dt = 0
      self.position_er = 0
      self.position_er_last = 0;
      self.cp = 0
      self.vel_er = 0
      self.cd = 0
      self.Kp = 3
      self.Kd = 3.5
sitl_file.py 文件源码 项目:formulapi_ROS_simulator 作者: wilselby 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def run(self):

      while True:

    # Only run loop if we have an image
    if self.process:

            self.imgprocess.ProcessingImage(self.latestimage)   # FormulaPi Image Processing Function

            self.AdjustMotorSpeed(self.imgprocess.trackoffset)  # Compute Motor Commands From Image Output

        # Publish Processed Image
        cvImage = self.imgprocess.outputImage
        try:
            imgmsg = self.bridge.cv2_to_imgmsg(cvImage, "bgr8")
            self.image_pub.publish(imgmsg)
        except CvBridgeError as e:
                print(e)

            #cv2.imshow("Image window", self.cvImage)
            #cv2.waitKey(3)
ros_node.py 文件源码 项目:tea 作者: antorsae 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def handle_image_msg(msg):
    assert msg._type == 'sensor_msgs/Image'

    with g_fusion_lock:
        g_fusion.filter(EmptyObservation(msg.header.stamp.to_sec()))

        if g_fusion.last_state_mean is not None:
            pose = g_fusion.lidar_observation_function(g_fusion.last_state_mean)

            yaw_q = ros_tf.transformations.quaternion_from_euler(0, 0, pose[3])
            br = ros_tf.TransformBroadcaster()
            br.sendTransform(tuple(pose[:3]), tuple(yaw_q), rospy.Time.now(), 'obj_fuse_centroid', 'velodyne')

            if last_known_box_size is not None:
                # bounding box
                marker = Marker()
                marker.header.frame_id = "obj_fuse_centroid"
                marker.header.stamp = rospy.Time.now()
                marker.type = Marker.CUBE
                marker.action = Marker.ADD
                marker.scale.x = last_known_box_size[2]
                marker.scale.y = last_known_box_size[1]
                marker.scale.z = last_known_box_size[0]
                marker.color = ColorRGBA(r=0., g=1., b=0., a=0.5)
                marker.lifetime = rospy.Duration()
                pub = rospy.Publisher("obj_fuse_bbox", Marker, queue_size=10)
                pub.publish(marker)
kalibr_camera_focus.py 文件源码 项目:camera_calibration_frontend 作者: groundmelon 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def __init__(self, topic):
        self.topic = topic
        self.windowNameOrig = "Camera: {0}".format(self.topic)
        cv2.namedWindow(self.windowNameOrig, 2)
        self.bridge = CvBridge()
        self.image_sub = rospy.Subscriber(self.topic, Image, self.callback)
store_data.py 文件源码 项目:geom_rcnn 作者: asbroad 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def __init__(self):
        self.data_dir = rospy.get_param('/store_data/data_dir')
        self.category = rospy.get_param('/store_data/category')
        self.pic_count = rospy.get_param('/store_data/init_idx')
        self.rate = 1/float(rospy.get_param('/store_data/rate'))

        self.bridge = CvBridge()
        self.image_sub = rospy.Subscriber('/camera/rgb/image_color', Image, self.img_cb)
        self.patches_sub = rospy.Subscriber('/candidate_regions_depth', PolygonStamped, self.patches_cb)
        self.capture_sub = rospy.Subscriber('/capture/keyboard', Bool, self.capture_cb)
        # you can read this value off of your sensor from the '/camera/depth_registered/camera_info' topic
        self.P = np.array([[525.0, 0.0, 319.5, 0.0], [0.0, 525.0, 239.5, 0.0], [0.0, 0.0, 1.0, 0.0]])

        self.capture = False
head_display.py 文件源码 项目:intera_sdk 作者: RethinkRobotics 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def __init__(self):
        """
        Constructor
        """
        self._image_pub = rospy.Publisher('/robot/head_display', Image, latch=True, queue_size=10)
head_display.py 文件源码 项目:intera_sdk 作者: RethinkRobotics 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def display_image(self, image_path, display_in_loop=False, display_rate=1.0):
        """
        Displays image(s) to robot's head

        @type image_path: list
        @param image_path: the relative or absolute file path to the image file(s)

        @type display_in_loop: bool
        @param display_in_loop: Set True to loop through all image files infinitely

        @type display_rate: float
        @param display_rate: the rate to publish image into head
        """
        rospy.logdebug("Display images in loop:'{0}', frequency: '{1}'".format(display_in_loop, display_rate))

        image_msg = []
        image_list = image_path if isinstance(image_path, list) else [image_path]
        for one_path in image_list:
            cv_img = self._setup_image(one_path)
            if cv_img:
                image_msg.append(cv_img)

        if not image_msg:
            rospy.logerr("Image message list is empty")
        else:
            r = rospy.Rate(display_rate)
            while not rospy.is_shutdown():
                for one_msg in image_msg:
                    self._image_pub.publish(one_msg)
                    r.sleep()
                if not display_in_loop:
                    break
camera.py 文件源码 项目:intera_sdk 作者: RethinkRobotics 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def set_callback(self, camera_name, callback, callback_args=None,
        queue_size=10, rectify_image=True):
        """
        Setup the callback function to show image.

        @type camera_name: str
        @param camera_name: camera name
        @type callback: fn(msg, cb_args)
        @param callback: function to call when data is received
        @type callback_args: any
        @param callback_args: additional arguments to pass to the callback
        @type queue_size: int
        @param queue_size: maximum number of messages to receive at a time
        @type rectify_image: bool
        @param rectify_image: specify whether subscribe to the rectified or
                              raw (unrectified) image topic
        """
        if self.verify_camera_exists(camera_name):
            if rectify_image == True:
                if self.cameras_io[camera_name]['is_color']:
                    image_string = "image_rect_color"
                else:
                    image_string = "image_rect"
            else:
                image_string = "image_raw"
            rospy.Subscriber('/'.join(["/io/internal_camera", camera_name,
                image_string]), Image, callback, callback_args=callback_args)
camdector.py 文件源码 项目:nimo 作者: wolfram2012 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def ImgCcallback(self, ros_img):
        global imgi
        imgi = mx.img.imdecode(ros_img.data)
        global img_rect
        global img_raw
        global Frame
        img_rect = CvBridge().compressed_imgmsg_to_cv2(ros_img)
        # img_raw = img_rect.copy()

        Frame = pv.Image(img_rect.copy())
        # cv2.imshow("tester", Frame.asOpenCV())

    # def Imgcallback(self, ros_img):
    #     global img_rect
    #     img_rect = CvBridge().imgmsg_to_cv2(ros_img)
folder_image_publisher.py 文件源码 项目:image_recognition 作者: tue-robotics 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def __init__(self, context):
        """
        :param context: QT context, aka parent
        """
        super(FolderImagePublisherPlugin, self).__init__(context)

        # Widget setup
        self.setObjectName('FolderImagePublisherPlugin')

        self._widget = QWidget()
        context.add_widget(self._widget)

        # Layout and attach to widget
        layout = QHBoxLayout()
        self._widget.setLayout(layout)

        self._info = QLineEdit()
        self._info.setDisabled(True)
        self._info.setText("Please choose a directory (top-right corner)")
        layout.addWidget(self._info)

        self._left_button = QPushButton('<')
        self._left_button.clicked.connect(partial(self._rotate_and_publish, -1))
        layout.addWidget(self._left_button)

        self._right_button = QPushButton('>')
        self._right_button.clicked.connect(partial(self._rotate_and_publish, 1))
        layout.addWidget(self._right_button)

        # Set subscriber and service to None
        self._pub = rospy.Publisher("folder_image", Image, queue_size=1)

        self._bridge = CvBridge()

        self._files = collections.deque([])
annotation.py 文件源码 项目:image_recognition 作者: tue-robotics 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def store_image(self, roi_image):
        """
        Store the image
        :param roi_image: Image we would like to store
        """
        if roi_image is not None and self.label is not None and self.output_directory is not None:
            image_writer.write_annotated(self.output_directory, roi_image, self.label, True)
annotation.py 文件源码 项目:image_recognition 作者: tue-robotics 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def _image_callback(self, msg):
        """
        Called when a new sensor_msgs/Image is coming in
        :param msg: The image messaeg
        """
        try:
            cv_image = self.bridge.imgmsg_to_cv2(msg, "bgr8")
        except CvBridgeError as e:
            rospy.logerr(e)

        self._image_widget.set_image(cv_image)
annotation.py 文件源码 项目:image_recognition 作者: tue-robotics 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def _create_subscriber(self, topic_name):
        """
        Method that creates a subscriber to a sensor_msgs/Image topic
        :param topic_name: The topic_name
        """
        if self._sub:
            self._sub.unregister()
        self._sub = rospy.Subscriber(topic_name, Image, self._image_callback)
        rospy.loginfo("Listening to %s -- spinning .." % self._sub.name)
        self._widget.setWindowTitle("Label plugin, listening to (%s)" % self._sub.name)
test.py 文件源码 项目:image_recognition 作者: tue-robotics 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def _create_subscriber(self, topic_name):
        """
        Method that creates a subscriber to a sensor_msgs/Image topic
        :param topic_name: The topic_name
        """
        if self._sub:
            self._sub.unregister()
        self._sub = rospy.Subscriber(topic_name, Image, self._image_callback)
        rospy.loginfo("Listening to %s -- spinning .." % self._sub.name)
        self._widget.setWindowTitle("Test plugin, listening to (%s)" % self._sub.name)


问题


面经


文章

微信
公众号

扫码关注公众号