Ejemplo n.º 1
0
    def init_camera(self):

        openni2.initialize()
        nite2.initialize()
        self.dev = openni2.Device.open_any()

        dev_name = self.dev.get_device_info().name.decode('UTF-8')
        print("Device Name: {}".format(dev_name))
        self.use_kinect = False
        if dev_name == 'Kinect':
            self.use_kinect = True
            print('using Kinect.')

        try:
            self.user_tracker = nite2.UserTracker(self.dev)
        except utils.NiteError:
            print("Unable to start the NiTE human tracker. Check "
                  "the error messages in the console. Model data "
                  "(s.dat, h.dat...) might be inaccessible.")
            sys.exit(-1)

        (self.img_w, self.img_h
         ) = CAPTURE_SIZE_KINECT if self.use_kinect else CAPTURE_SIZE_OTHERS
        self.win_w = 256
        self.win_h = int(self.img_h * self.win_w / self.img_w)
Ejemplo n.º 2
0
 def init_capture_device(self):
     openni2.initialize()
     nite2.initialize()
     return openni2.Device.open_any()
Ejemplo n.º 3
0
                }


if __name__ == "__main__":

    logging.basicConfig(level=logging.INFO)

    import argparse
    parser = argparse.ArgumentParser()
    parser.add_argument("world", help="Underworlds world to monitor")
    #parser.add_argument("-d", "--debug", help="run in interactive, debug mode", action="store_true")
    args = parser.parse_args()

    ### OpenNI/NiTE initialization
    openni2.initialize()
    nite2.initialize()

    logger.info("Opening a freenect device...")
    dev = openni2.Device.open_any()
    info = dev.get_device_info()
    logger.info("Device <%s %s> successfully opened." %
                (info.vendor, info.name))

    logger.info("Loading the NiTE user tracker...")
    try:
        userTracker = nite2.UserTracker(dev)
    except utils.NiteError as ne:
        logger.error("Unable to start the NiTE human tracker. Check "
                     "the error messages in the console. Model data "
                     "(s.dat, h.dat...) might be missing.")
        sys.exit(-1)
Ejemplo n.º 4
0

if __name__ == "__main__":

    logging.basicConfig(level=logging.INFO)

    import argparse
    parser = argparse.ArgumentParser()
    parser.add_argument("world", help="Underworlds world to monitor")
    #parser.add_argument("-d", "--debug", help="run in interactive, debug mode", action="store_true")
    args = parser.parse_args()
    

    ### OpenNI/NiTE initialization
    openni2.initialize()
    nite2.initialize()

    logger.info("Opening a freenect device...")
    dev = openni2.Device.open_any()
    info = dev.get_device_info()
    logger.info("Device <%s %s> successfully opened." % (info.vendor, info.name))

    logger.info("Loading the NiTE user tracker...")
    try:
        userTracker = nite2.UserTracker(dev)
    except utils.NiteError as ne:
        logger.error("Unable to start the NiTE human tracker. Check "
                    "the error messages in the console. Model data "
                    "(s.dat, h.dat...) might be missing.")
        sys.exit(-1)
    logger.info("User tracker loaded.")
def pegarMovimentos():
    global player1HandRightx
    global player1HandRighty
    global player1HandLeftx
    global player1HandLefty

    global player2HandRightx
    global player2HandRighty
    global player2HandLefty
    global player2HandLeftx

    global joints

    global leoteste

    #openni2.initialize("/home/leonardo/Downloads/OpenNI-Linux-x64-2.2/Redist")
    openni2.initialize("/home/leonardo/Tcc/OpenNI-Linux-x64-2.2/Redist")
    #nite2.initialize("/home/leonardo/Downloads/NiTE-Linux-x64-2.2/Redist")
    nite2.initialize("/home/leonardo/Tcc/NiTE-2.0.0/Redist")

    dev = openni2.Device.open_any()
    device_info = dev.get_device_info()
    try:
        userTracker = nite2.UserTracker(dev)
    except utils.NiteError as ne:
        print "entrou em exept"
        print(
            "Unable to start the NiTE human tracker. Check the error messages in the console. Model data (s.dat, h.dat...) might be inaccessible."
        )
        print(ne)
        sys.exit(-1)
        print "antes do while"

    while True:
        frame = userTracker.read_frame()
        depth_frame = frame.get_depth_frame()

        if frame.users:
            i = 1
            for user in frame.users:
                user.id = i
                i += 1
                if user.skeleton.state == nite2.SkeletonState.NITE_SKELETON_TRACKED:
                    print user.id
                else:
                    print user.id
                    print user.is_new()
                    print user.is_visible()
                    print("Skeleton state: " + str(user.skeleton.state))
                    #print 'leo' + str(user.id)
                    #if user.id == 0 and leoteste==0:
                    #	print 'e zero'
                    #	leoteste=+1
                    userTracker.start_skeleton_tracking(user.id)
                    print("Skeleton state: " + str(user.skeleton.state))
                    #	userTracker.start_skeleton_tracking(2)
                    #if user.is_new():
                    #	print("New human detected! ID: %d Calibrating...", user.id)
                    #	userTracker.start_skeleton_tracking(1)
                    #elif user.skeleton.state == nite2.SkeletonState.NITE_SKELETON_TRACKED:
                    #else:
                    #print user.skeleton.joints
                    #print user.id
                    #print str(user.is_visible())
                    preenchermovimento(user.id, user.skeleton.joints)
        else:
            print("No users")

    nite2.unload()
    openni2.unload()
Ejemplo n.º 6
0
def main(argv):
    """
        Main function that do the OpenNI and Nite loop

        parameters
        -------------------
        argv : should contains parameters to configure the broker
                -H : the hostname
    """
    robot = None

    #Read the parameters
    try:
        opts, args = getopt.getopt(argv, "H:", ["hostname="])
    except getopt.GetoptError:
        print('main.py -H <hostname>')
        sys.exit(2)

    for opt, arg in opts:

        if opt in ("-H", "--hostname"):
            robot = cr.CommandRobot(arg)

    if robot is None:
        robot = cr.CommandRobot()

    # Init OpenNi2 and Nite 2
    openni2.initialize(
    )  # can also accept the path of the OpenNI redistribution
    nite2.initialize()

    dev = openni2.Device.open_any()
    print "device: {}".format(dev.get_device_info())

    try:
        handTracker = nite2.HandTracker(dev)
        handTracker.start_gesture_detection(
            nite2.GestureType.NITE_GESTURE_WAVE)

    except utils.NiteError as ne:
        logging.error("Unable to start the NiTE human tracker. Check "
                      "the error messages in the console. Model data "
                      "(s.dat, h.dat...) might be inaccessible.")
        print(ne)
        sys.exit(-1)

    gestureStarted = False
    oldPosition = None
    newPosition = None
    handId = None

    tracker_hand = th.TrackerHand(handTracker, robot)
    depth_display = dp.DisplayDepth()

    cv2.namedWindow('Jarvis-View')

    while True:

        key = cv2.waitKey(10)

        if key == 27:
            break

        frame = handTracker.read_frame()
        #print "Resolution x:{}, y:{}".format(frame.depth_frame.width,frame.depth_frame.height)
        depth_display.build_img(frame.depth_frame)
        tracker_hand.track_hand(frame, depth_display)
        depth_display.show_frame()

    nite2.unload()
    openni2.unload()

    cv2.destroyAllWindows()
    def init_capture_device(self):

        openni2.initialize()
        nite2.initialize("/usr/lib/")
        # NiTE2 folder has to be in the same directory as this script!
        return openni2.Device.open_any()
Ejemplo n.º 8
0
    def __init__(self,
                 use_thread=False,
                 sleep_dt=0.,
                 verbose=False,
                 track_hand=False):
        """
        Initialize the Kinect input interface using the `openni` library.

        Args:
            use_thread (bool): If True, it will run the interface in a separate thread than the main one.
                The interface will update its data automatically.
            sleep_dt (float): If :attr:`use_thread` is True, it will sleep the specified amount before acquiring
                the next sample.
            verbose (bool): If True, it will print information about the state of the interface. This is let to the
                programmer what he / she wishes to print.
            track_hand (bool): If True, it will track the hands.
        """
        # initialize openni2 and nite2; you can give the path to the library as an argument.
        # Otherwise, it will look for OPENNI2_REDIST / OPENNI2_REDIST64 and NITE2_REDIST / NITE2_REDIST64 environment
        # variables.
        openni2.initialize()
        nite2.initialize()

        # open all the devices
        devices = openni2.Device.open_all()

        # get the correct device (Microsoft Kinect)
        self.device = None
        for device in devices:
            info = device.get_device_info()
            if info.vendor == 'Microsoft' and info.name == 'Kinect':  # Kinect Interface
                self.device = device
                break

        # If didn't find it, return an error
        if self.device is None:
            devices = [device.get_device_info() for device in devices]
            raise ValueError(
                "No Asus devices were detected; we found these devices instead: {}"
                .format(devices))

        if verbose:
            print(self.device.get_device_info())

        # create tracker for the hand or user depending on the given parameter
        if track_hand:
            self.tracker = nite2.HandTracker(self.device)
        else:
            self.tracker = nite2.UserTracker(self.device)

        # data
        self.joints = [
            'head', 'neck', 'torso', 'left_shoulder', 'left_elbow',
            'left_hand', 'left_hip', 'left_knee', 'left_foot',
            'right_shoulder', 'right_elbow', 'right_hand', 'right_hip',
            'right_knee', 'right_foot'
        ]
        joint = nite2.JointType
        self.nite_joints = [
            joint.NITE_JOINT_HEAD, joint.NITE_JOINT_NECK,
            joint.NITE_JOINT_TORSO, joint.NITE_JOINT_LEFT_SHOULDER,
            joint.NITE_JOINT_LEFT_ELBOW, joint.NITE_JOINT_LEFT_HAND,
            joint.NITE_JOINT_LEFT_HIP, joint.NITE_JOINT_LEFT_KNEE,
            joint.NITE_JOINT_LEFT_FOOT, joint.NITE_JOINT_RIGHT_SHOULDER,
            joint.NITE_JOINT_RIGHT_ELBOW, joint.NITE_JOINT_RIGHT_HAND,
            joint.NITE_JOINT_RIGHT_HIP, joint.NITE_JOINT_RIGHT_KNEE,
            joint.NITE_JOINT_RIGHT_FOOT
        ]

        self.data = {}

        super(KinectSkeletonTrackingInterface,
              self).__init__(use_thread=use_thread,
                             sleep_dt=sleep_dt,
                             verbose=verbose)