Exemplo n.º 1
0
def demo():
    rm = HLRM()
    pygame.init()
    screen = pygame.display.set_mode((1280, 480))
    END = False
    dr = DragDraw_pgRect(screen)
    kk = KinectClientV2019()

    while not END:
        screen.blit(kk.get_color_as_pgsurface(), (0, 0))
        screen.blit(kk.get_depth_as_pgsurface(), (640, 0))
        events = pygame.event.get()
        flg, rec = dr.update(events)

        for ev in events:
            if ev.type == pygame.QUIT:
                END = True
            elif ev.type == pygame.KEYUP and ev.key == 13:  # enter key
                if flg:
                    c = locate_bottle(rec, kk.point_cloud)
                    print 'bottle location: ' + str(c)
                    rm.gripbottle(c)
                else:
                    print "you havn't selected any region"
        pygame.display.update()
    kk.release()
    pygame.quit()
Exemplo n.º 2
0
def demo():
    pygame.init()
    screen = pygame.display.set_mode((1280, 480))
    END = False
    dr = DragDraw_pgRect(screen)
    kk = KinectClientV2019()
    fps_clock = pygame.time.Clock()

    rm = RmCar_x64()
    track = TrackerPro()
    tc_pro = multiprocessing.Process(target=tracker_pro, args=(track.args, ))
    tc_pro.start()
    going = 0
    p = np.zeros(3)

    while not END:
        screen.blit(kk.get_color_as_pgsurface(), (0, 0))
        screen.blit(kk.get_depth_as_pgsurface(), (640, 0))
        events = pygame.event.get()
        flg, rec = dr.update(events)

        for ev in events:
            if ev.type == pygame.QUIT:
                END = True
            elif ev.type == pygame.KEYUP and ev.key == 13:  # enter key
                if flg:
                    name = raw_input(
                        'select succeed\nplease enter the target name: \n>>> ')
                    if name == 'bottle':
                        c = locate_bottle(rec, kk.point_cloud)
                    else:
                        c = locate_obj(rec, kk.point_cloud)

                    cmd = {'name': name, 'position': c}
                    rm.pushtask(cmd, 'auto')
                    (x, y), (w, h) = rec
                    going = 1
                    track.init_tracker((x, y, w, h))
                else:
                    print "select failure"
        if going:
            box, pos = track.update()
            if name == 'bottle':
                if pos['bottle'] is not None: p = pos['bottle']
            else:
                if pos['obj'] is not None: p = pos['obj']
            x, y, w, h = box
            print p
            pygame.draw.rect(screen, (0, 255, 0), ((x, y), (w, h)), 1)

            if rm.updatetask(p):
                going = 0
                print 'task completed'
            else:
                pass
        pygame.display.update()
        fps_clock.tick(10)
    kk.release()
    pygame.quit()
Exemplo n.º 3
0
 def parse_obj(self, obj):
     name, box = obj
     target_object_list = [
         'person', 'cup', 'bottle', 'diningtable', 'sofa', 'chair'
     ]
     if name in target_object_list:
         tar = {}
         x, y, w, h = box
         rect = ((x, y), (w, h))
         if name == 'diningtable': name = 'desk'
         tar['name'] = name
         tar['box'] = box
         tar['rect'] = rect
         if name == 'bottle':
             p = locate_bottle(rect, kk.point_cloud)
         else:
             p = locate_obj(rect, kk.point_cloud)
         tar['position'] = p
         return tar
     else:
         return None
Exemplo n.º 4
0
def tracker_pro(args):
    ev = args['ev']
    quin = args['quin']
    quout = args['quout']
    tracker = kcftracker.KCFTracker(True, True, True)
    kk = KinectClientV2019()
    
    while not ev.is_set():
        flg, box = quin.get()
        if flg == 1:  # 启动跟踪
            frame = kk.get_color_as_cvframe()
            tracker.init(box, frame)

        elif flg == 2:  # 请求结果
            frame = kk.get_color_as_cvframe()
            boundingbox = tracker.update(frame)
            x, y, w, h = boundingbox = map(int, boundingbox)
            pos = locate_obj(((x, y), (w, h)), kk.point_cloud)
            pos1 = locate_bottle(((x, y), (w, h)), kk.point_cloud)
            quout.put([boundingbox, {'obj': pos, 'bottle': pos1}])

        elif flg == 0:
            pass