Esempio n. 1
0
    def __init__(self, node_name):
        ROS2OpenCV2.__init__(self, node_name)

        self.node_name = node_name
        
        # The minimum saturation of the tracked color in HSV space,
        # as well as the min and max value (the V in HSV) and a 
        # threshold on the backprojection probability image.
        self.smin = rospy.get_param("~smin", 85)
        self.vmin = rospy.get_param("~vmin", 50)
        self.vmax = rospy.get_param("~vmax", 254)
        self.threshold = rospy.get_param("~threshold", 50)
                       
        # Create a number of windows for displaying the histogram,
        # parameters controls, and backprojection image
        #cv.NamedWindow("Histogram", cv.CV_WINDOW_NORMAL)
        #cv.MoveWindow("Histogram", 700, 50)
        #cv.NamedWindow("Parameters", 0)
        #cv.MoveWindow("Parameters", 700, 325)
        #cv.NamedWindow("Backproject", 0)
        #cv.MoveWindow("Backproject", 700, 600)
        
        # Create the slider controls for saturation, value and threshold
        #cv.CreateTrackbar("Saturation", "Parameters", self.smin, 255, self.set_smin)
        #cv.CreateTrackbar("Min Value", "Parameters", self.vmin, 255, self.set_vmin)
        #cv.CreateTrackbar("Max Value", "Parameters", self.vmax, 255, self.set_vmax)
        #cv.CreateTrackbar("Threshold", "Parameters", self.threshold, 255, self.set_threshold)
        
        # Initialize a number of variables
        self.hist = None
        self.track_window = None
        self.show_backproj = False
Esempio n. 2
0
    def __init__(self, node_name):
        ROS2OpenCV2.__init__(self, node_name)

        self.node_name = node_name
        
        # The minimum saturation of the tracked color in HSV space,
        # as well as the min and max value (the V in HSV) and a 
        # threshold on the backprojection probability image.
        self.smin = rospy.get_param("~smin", 85)
        self.vmin = rospy.get_param("~vmin", 50)
        self.vmax = rospy.get_param("~vmax", 254)
        self.threshold = rospy.get_param("~threshold", 50)
                       
        # Create a number of windows for displaying the histogram,
        # parameters controls, and backprojection image
        cv.NamedWindow("Histogram", cv.CV_WINDOW_NORMAL)
        cv.MoveWindow("Histogram", 700, 50)
        cv.NamedWindow("Parameters", 0)
        cv.MoveWindow("Parameters", 700, 325)
        cv.NamedWindow("Backproject", 0)
        cv.MoveWindow("Backproject", 700, 600)
        
        # Create the slider controls for saturation, value and threshold
        cv.CreateTrackbar("Saturation", "Parameters", self.smin, 255, self.set_smin)
        cv.CreateTrackbar("Min Value", "Parameters", self.vmin, 255, self.set_vmin)
        cv.CreateTrackbar("Max Value", "Parameters", self.vmax, 255, self.set_vmax)
        cv.CreateTrackbar("Threshold", "Parameters", self.threshold, 255, self.set_threshold)
        
        # Initialize a number of variables
        self.hist = None
        self.track_window = None
        self.show_backproj = False
    def __init__(self, node_name):
        ROS2OpenCV2.__init__(self, node_name)

        self.match_threshold = rospy.get_param("~match_threshold", 0.7)
        self.find_multiple_targets = rospy.get_param("~find_multiple_targets", False)
        self.n_pyr = rospy.get_param("~n_pyr", 2)
        self.min_template_size = rospy.get_param("~min_template_size", 25)

        self.scale_factor = rospy.get_param("~scale_factor", 1.2)
        self.scale_and_rotate = rospy.get_param("~scale_and_rotate", False)

        self.use_depth_for_detection = rospy.get_param("~use_depth_for_detection", False)
        self.fov_width = rospy.get_param("~fov_width", 1.094)
        self.fov_height = rospy.get_param("~fov_height", 1.094)
        self.max_object_size = rospy.get_param("~max_object_size", 0.28)

        # Intialize the detection box
        self.detect_box = None

        self.detector_loaded = False

        rospy.loginfo("Waiting for video topics to become available...")

        # Wait until the image topics are ready before starting
        rospy.wait_for_message("input_rgb_image", Image)

        if self.use_depth_for_detection:
            rospy.wait_for_message("input_depth_image", Image)

        rospy.loginfo("Ready.")
Esempio n. 4
0
    def __init__(self, node_name):
        ROS2OpenCV2.__init__(self, node_name)
        
        self.match_threshold = rospy.get_param("~match_threshold", 0.7)
        self.find_multiple_targets = rospy.get_param("~find_multiple_targets", False)
        self.n_pyr = rospy.get_param("~n_pyr", 2)
        self.min_template_size = rospy.get_param("~min_template_size", 25)

        self.scale_factor = rospy.get_param("~scale_factor", 1.2)
        self.scale_and_rotate = rospy.get_param("~scale_and_rotate", False)
        
        self.use_depth_for_detection = rospy.get_param("~use_depth_for_detection", False)
        self.fov_width = rospy.get_param("~fov_width", 1.094)
        self.fov_height = rospy.get_param("~fov_height", 1.094)
        self.max_object_size = rospy.get_param("~max_object_size", 0.28)

        # Intialize the detection box
        self.detect_box = None
        
        self.detector_loaded = False
        
        rospy.loginfo("Waiting for video topics to become available...")

        # Wait until the image topics are ready before starting
        rospy.wait_for_message("input_rgb_image", Image)
        
        if self.use_depth_for_detection:
            rospy.wait_for_message("input_depth_image", Image)
            
        rospy.loginfo("Ready.")
Esempio n. 5
0
    def __init__(self, node_name):
        ROS2OpenCV2.__init__(self, node_name)

        self.node_name = node_name

        # The minimum saturation of the tracked color in HSV space,
        # as well as the min and max value (the V in HSV) and a
        # threshold on the backprojection probability image.
        self.smin = rospy.get_param("~smin", 85)
        self.vmin = rospy.get_param("~vmin", 50)
        self.vmax = rospy.get_param("~vmax", 254)
        self.threshold = rospy.get_param("~threshold", 50)

        # Create a number of windows for displaying the histogram,
        # parameters controls, and backprojection image
        cv.NamedWindow("Histogram", cv.CV_WINDOW_NORMAL)
        cv.MoveWindow("Histogram", 700, 50)
        cv.NamedWindow("Parameters", 0)
        cv.MoveWindow("Parameters", 700, 325)
        cv.NamedWindow("Backproject", 0)
        cv.MoveWindow("Backproject", 700, 600)

        # Create the slider controls for saturation, value and threshold
        cv.CreateTrackbar("Saturation", "Parameters", self.smin, 255,
                          self.set_smin)
        cv.CreateTrackbar("Min Value", "Parameters", self.vmin, 255,
                          self.set_vmin)
        cv.CreateTrackbar("Max Value", "Parameters", self.vmax, 255,
                          self.set_vmax)
        cv.CreateTrackbar("Threshold", "Parameters", self.threshold, 255,
                          self.set_threshold)

        # Initialize a number of variables Customized to load pre-saved color
        self.home_folder = expanduser("~")
        self.hist_file = self.home_folder + '/.arlobot/self_hist.p'
        self.window_file = self.home_folder + '/.arlobot/track_window.p'
        print self.window_file, self.hist_file
        #self.hist = None
        self.hist = pickle.load(open(self.hist_file, "rb"))
        #self.track_window = None
        self.track_window = pickle.load(open(self.window_file, "rb"))
        self.show_backproj = False
    def __init__(self, node_name):

        ROS2OpenCV2.__init__(self, node_name)

        self.matchPercentage = rospy.get_param("~matchPercentage", 70)
        self.findMultipleTargets = rospy.get_param("~findMultipleTargets",
                                                   False)
        self.numMaxima = rospy.get_param("~numMaxima", 1)
        self.numDownPyrs = rospy.get_param("~numDownPyrs", 2)
        self.searchExpansion = rospy.get_param("~searchExpansion", 15)

        self.use_depth_for_detection = rospy.get_param(
            "~use_depth_for_detection", False)
        self.fov_width = rospy.get_param("~fov_width", 1.094)
        self.fov_height = rospy.get_param("~fov_height", 1.094)
        self.max_object_size = rospy.get_param("~max_object_size", 0.28)

        self.foundPointsList = list()
        self.confidencesList = list()

        # Intialize the detection box
        self.detect_box = None

        # Initialize a couple of intermediate image variables
        self.grey = None
        self.small_image = None

        # What kind of detector do we want to load
        self.detector_type = "template"
        self.detector_loaded = False

        rospy.loginfo("Waiting for video topics to become available...")

        # Wait until the image topics are ready before starting
        rospy.wait_for_message("input_rgb_image", Image)

        if self.use_depth_for_detection:
            rospy.wait_for_message("input_depth_image", Image)

        rospy.loginfo("Ready.")
Esempio n. 7
0
    def __init__(self, node_name):
        
        ROS2OpenCV2.__init__(self, node_name)
        
        self.matchPercentage = rospy.get_param("~matchPercentage", 70)
        self.findMultipleTargets = rospy.get_param("~findMultipleTargets", False)
        self.numMaxima = rospy.get_param("~numMaxima", 1)
        self.numDownPyrs = rospy.get_param("~numDownPyrs", 2)
        self.searchExpansion = rospy.get_param("~searchExpansion", 15)
        
        self.use_depth_for_detection = rospy.get_param("~use_depth_for_detection", False)
        self.fov_width = rospy.get_param("~fov_width", 1.094)
        self.fov_height = rospy.get_param("~fov_height", 1.094)
        self.max_object_size = rospy.get_param("~max_object_size", 0.28)

        self.foundPointsList = list()
        self.confidencesList = list()
        
        # Intialize the detection box
        self.detect_box = None
        
        # Initialize a couple of intermediate image variables
        self.grey = None
        self.small_image = None  
        
        # What kind of detector do we want to load
        self.detector_type = "template"
        self.detector_loaded = False
        
        rospy.loginfo("Waiting for video topics to become available...")

        # Wait until the image topics are ready before starting
        rospy.wait_for_message("input_rgb_image", Image)
        
        if self.use_depth_for_detection:
            rospy.wait_for_message("input_depth_image", Image)
            
        rospy.loginfo("Ready.")
Esempio n. 8
0
	def __init__(self,node_name):
		ROS2OpenCV2.__init__(self,node_name)
		self.node_name = node_name
		
		# The minimum saturation of the tracked color in HSV space
		# as well as the min and max value (the v in HSV) and a
		# threshold on the backprojection probability image.
		self.smin = rospy.get_param('~smin',85)
		self.vmin = rospy.get_param('~vmin',50)
		self.vmax = rospy.get_param('~vmax',254)
		self.threshold = rospy.get_param('~threshold',50)
	
		# Create a number of windows for displaying the histogram,
		# parameters controls, and backprojection image
		cv.NamedWindow('Histogram',cv.CV_WINDOW_NORMAL)
		cv.MoveWindow('Histogram',700,50)
		cv.NamedWindow('Parameters',0)
		cv.MoveWindow('Parameters',700,325)
		cv.NamedWindow('Backproject',0)
		cv.MoveWindow('Backproject',700,600)
		
		# Create the slider controls for saturation,value and threshold
		cv.CreateTracker('Saturation','Parameters',self.smin,255,self.set_smin)
		cv.CreateTracker('Min Value','Parameters',self.vmin,255,self.set_vmin)
		cv.CreateTracker('Max Value','Parameter',self.vmax,255,self.set_vmax)
		cv.CreateTracker('Threshold','Parameters',self.threshold,255,self.set_threshold)

		# Initialize a number of variables
		self.hist = None
		self.track_window = None
		self.show_backproj = False
		
		# These are the callbacks for the slider controls
		def set_smin(self,pos):
			self.smin = pos
		def set_vmin(self,pos):
			self.vmin=pos
		def set_vmax(self,pos):	
			self.vmax=pos
		def set_threshold(self,pos):
			self.threshold = pos
		# The main processing function computes the histogram and backprojection
		def process_image(self,cv_image):
			# First blur the image
			frame = cv2.blur(cv_image,(5,5))
			
			# Convert from RGB to HSV spare
			hsv = cv2.cvtColor(frame,cv2.COLOR_BGR2HSV)
			
			# Create a mask using the current saturation and value parameters
			mask = cv2.inRange(hsv,np.array((0.,self.smin,self.vmin)),np.array((180.,255.,self.vmax)))
			# If the user is making a selection with the mouse
			# calculate a new histogram to track
			if self.selection is not None:
				x0,y0,w,h = self.selection
				x1 = x0 + w
				y1 = x1 + h 
				self.track_window = (x0,y0,x1,y1)
				hsv_roi = hsv[y0:y1,x0:x1]
				mask_roi = mask[y0:y1,x0:x1]
				self.hist = cv2.calcHist([hsv_roi],[0],mask_roi,[16],[0,180])
				
				cv2.normalize(self.hist,self.hist,0,255,cv2.NORM_MINMAX)
				self.hist = self.hist.reshape(-1)
				self.show_hist()
			if self.detect_box is not None:
				self.selection = None
			
			# If we have a histogram, tracking it with Camshift
			if self.hist is not None:
				# compute the backprojection from the histogram
				backproject = cv2.calcBackProject([hsv],[0],self.hist,[0,180],1)	
				# Mask the backprojection with the mask created earlier
				backproject &= mask
				# Threshold the backproject
				ret,baackproject = cv2.threshold(backproject,self.threshold,255,cv.CV_THRESH_TOZERO)
				x,y,w,h = self.track_window
				if self.track_window is None or w<+0 or h<0:
					self.track_window =0,0,self.frame_width -1,self.frame_height -1
			# Set the criteria for the CamShift algorith,
			term_crit = (cv2.TERM_CRITERIA_EPS | cv2.TERM_CRITERIA_COUNT,10,1)
			# Run the CamShift algorithm
			self.track_box,self.track_window = cv2.CamShift(backproject,self.track_window,term_crit)
			# Display the resulting backprojection
			cv2.imshow('Backproject',backproject)		
			return cv_image