Esempio n. 1
0
    def get_ball(self, camera):
       
        # Creating track bar
        if USE_TRACKBARS:
            callback = lambda x: 0
            cv.createTrackbar('hmin', 'result', 0, 179, callback)
            cv.createTrackbar('hmax', 'result',179,179, callback)
            cv.createTrackbar('smin', 'result',0,255, callback)
            cv.createTrackbar('smax', 'result',255,255, callback)
            cv.createTrackbar('vmin', 'result',0,255, callback)
            cv.createTrackbar('vmax', 'result',255,255, callback)
        rate = rospy.Rate(10)
        
        #_, self.frame = self.capture.read()
        frame = cv.blur(camera.get_frame(), (3,3))

        #converting to HSV
        hsv = cv.cvtColor(frame,cv.COLOR_BGR2HSV)

        # get info from track bar and appy to result
        if USE_TRACKBARS:
            hmin = cv.getTrackbarPos('hmin','result')
            hmax = cv.getTrackbarPos('hmax','result')
            smin = cv.getTrackbarPos('smin','result')
            smax = cv.getTrackbarPos('smax','result')
            vmin = cv.getTrackbarPos('vmin','result')
            vmax = cv.getTrackbarPos('vmax','result')
            lower_hsv = np.array([hmin, smin, vmin])
            upper_hsv = np.array([hmax, smax, vmax])
            mask_trackbar = cv.inRange(hsv,lower_hsv, upper_hsv)
            track_x, track_y, mask3, _ = vl.track_object(mask_trackbar)
            cv.imshow('Thresh trackbar',mask3)

        #orng_x, orng_y, mask1, current_area = vl.locate_orange_ball(frame)
        pink_x, pink_y, mask2, current_area = vl.locate_pink_ball(frame)

        display = frame.copy()
        cv.circle(display, (320, 70), 10, 255, -1) 
        #cv.circle(display, (orng_x, orng_y), 10, (0,0,255), -1) 
        cv.circle(display, (pink_x, pink_y), 10, (0,255,0), -1) 

        #cv.imshow('Thresh orange',mask1)
        #cv.imshow('Thresh pink',mask2)
        #cv.imshow('result', display)
        
        #ball_gripped = self.visual_servo(self.tl, camera, pink_x, pink_y, current_area)
        ball_gripped = self.attack_visual_servo()
        # rate.sleep()
        
        if ball_gripped:
            print 'THROW'
            return True
        else:
            return False
Esempio n. 2
0
def debug_with_trackbars():

    cv.namedWindow('result')
    callback = lambda x: 0
    cv.createTrackbar('hmin', 'result', 0, 179, callback)
    cv.createTrackbar('hmax', 'result',179,179, callback)
    cv.createTrackbar('smin', 'result',0,255, callback)
    cv.createTrackbar('smax', 'result',255,255, callback)
    cv.createTrackbar('vmin', 'result',0,255, callback)
    cv.createTrackbar('vmax', 'result',255,255, callback)
    rate = rospy.Rate(10)
    
    while not rospy.is_shutdown():
        #_, self.frame = self.capture.read()
        frame = cv.blur(camera.get_frame(), (3,3))

        #converting to HSV
        hsv = cv.cvtColor(frame,cv.COLOR_BGR2HSV)

        # get info from track bar and appy to result
        hmin = cv.getTrackbarPos('hmin','result')
        hmax = cv.getTrackbarPos('hmax','result')
        smin = cv.getTrackbarPos('smin','result')
        smax = cv.getTrackbarPos('smax','result')
        vmin = cv.getTrackbarPos('vmin','result')
        vmax = cv.getTrackbarPos('vmax','result')
        lower_hsv = np.array([hmin, smin, vmin])
        upper_hsv = np.array([hmax, smax, vmax])
        mask_trackbar = cv.inRange(hsv,lower_hsv, upper_hsv)
        track_x, track_y, mask3, area = vl.track_object(mask_trackbar)
        #print area
        cv.imshow('Thresh trackbar',mask3)

        display = frame.copy()
        cv.circle(display, (track_x, track_y), 10, (0,0,255), -1) 

        cv.imshow('result', display)

        rate.sleep()

        k = cv.waitKey(5) & 0xFF
        if k == 27:
            break
        
    cv.destroyAllWindows()