Exemple #1
0
def CaptureFeaturesxxx():
    rospy.init_node('capture_node')

    models = [\
       'beer',
       'bowl',
       'create',
       'disk_part',
       'hammer',
       'plastic_cup',
       'soda_can']

    # Disable gravity and delete the ground plane
    initial_setup()
    labeled_features = []

    numCapturesPerModel = 4
    numRetriesPerCapture = 3
    for model_name in models:
        print("Feature capture on model '{}' ({}) target numAttempts".format(
            model_name, numCapturesPerModel))
        spawn_model(model_name)

        for i in range(numCapturesPerModel):
            # make five attempts to get a valid a point cloud then give up
            sample_was_good = False
            try_count = 0

            while not sample_was_good and try_count < numRetriesPerCapture:
                sample_cloud = capture_sample()
                sample_cloud_arr = ros_to_pcl(sample_cloud).to_array()

                # Check for invalid clouds.
                if sample_cloud_arr.shape[0] == 0:
                    print('Invalid cloud detected')
                    try_count += 1
                else:
                    sample_was_good = True

            if (sample_was_good):
                # Extract histogram features
                chists = pclproc.compute_color_histograms(sample_cloud,
                                                          doConvertToHSV=True)

                normals = get_normals(sample_cloud)
                nhists = pclproc.compute_normal_histograms(normals)

                feature = np.concatenate((chists, nhists))
                labeled_features.append([feature, model_name])

        delete_model()

    pickle.dump(labeled_features, open('training_set.sav', 'wb'))
    def run(self):
        """
        Produces training_set.sav
        Formatted as [param, data], where:
        - param : {'hsv':bool, 'bin':int}
            hsv : hsv colorspace flag (otherwise rgb)
            bin : number of histogram bins for feature extraction
        - data : [{name : [features]} for name in models]
        """
        initial_setup()
        # save collection parameters
        param = {'hsv': self._as_hsv, 'bin': self._nbins}
        data = {}
        m_n = len(self._models)
        for m_i, model_name in enumerate(self._models):
            rospy.loginfo('[{}/{}] Processing Model Name : {}'.format(
                m_i, m_n, model_name))
            model_data = []
            spawn_model(model_name)

            for i in range(self._steps):
                # get_cloud()
                sample_cloud = None
                for j in range(self._max_try):
                    sample_cloud = capture_sample()
                    sample_cloud_arr = ros_to_pcl(sample_cloud).to_array()
                    if sample_cloud_arr.shape[0] == 0:
                        rospy.loginfo('')
                        print('Invalid cloud detected')
                    else:
                        break
                # save_data()
                if sample_cloud is not None:
                    if self._as_feature:
                        # Extract histogram features
                        normals = get_normals(sample_cloud)
                        feature = cloud2feature(sample_cloud,
                                                normals,
                                                hsv=self._as_hsv,
                                                bins=self._nbins)
                        model_data.append(feature)
                    else:
                        model_data.append(sample_cloud)

            data[model_name] = model_data
            delete_model()

        # save data with pickle
        with open(self._path, 'wb') as f:
            pickle.dump([param, data], f)
def CaptureCloud(numRetriesPerCapture=3):
    try_count = 0
    sample_was_good = False

    while not sample_was_good and try_count < numRetriesPerCapture:
        sample_cloud = capture_sample()
        sample_cloud_arr = pcl_helper.ros_to_pcl(sample_cloud).to_array()

        # Check for invalid clouds.
        if sample_cloud_arr.shape[0] == 0:
            try_count += 1
        else:
            sample_was_good = True

    return try_count, sample_was_good, sample_cloud
Exemple #4
0
def CaptureCloud(numRetriesPerCapture=3):
    try_count = 0
    sample_was_good = False

    while not sample_was_good and try_count < numRetriesPerCapture:
        print(str(try_count)),
        sys.stdout.flush()

        sample_cloud = capture_sample()
        sample_cloud_arr = ros_to_pcl(sample_cloud).to_array()

        # Check for invalid clouds.
        if sample_cloud_arr.shape[0] == 0:
            print('*BAD,'),
            try_count += 1
        else:
            print('good,'),
            sample_was_good = True
        sys.stdout.flush()

    return sample_was_good, sample_cloud
Exemple #5
0
        "eraser"
    ]

    # Disable gravity and delete the ground plane
    initial_setup()
    labeled_features = []

    for model_name in models:
        spawn_model(model_name)
        print(model_name)
        for i in range(nb_point):
            # make five attempts to get a valid a point cloud then give up
            sample_was_good = False
            try_count = 0
            while not sample_was_good and try_count < 5:
                sample_cloud = capture_sample()
                sample_cloud_arr = ros_to_pcl(sample_cloud).to_array()

                # Check for invalid clouds.
                if sample_cloud_arr.shape[0] == 0:
                    print('Invalid cloud detected')
                    try_count += 1
                else:
                    sample_was_good = True
            # Save point cloud
            # Extract histogram features
            feature = extract_features(sample_cloud, get_normals)
            labeled_features.append([feature, model_name])

        delete_model()
Exemple #6
0
    pitch_ticks = 10
    yaw_ticks = 10
    for model_name in models:
        spawn_model(model_name)

        for i in range(pitch_ticks):
            pitch = float(i) / pitch_ticks * np.pi
            for j in range(yaw_ticks):
                yaw = float(j) / yaw_ticks * 2 * np.pi
                # make five attempts to get a valid a point cloud then give up
                sample_was_good = False
                try_count = 0
                while not sample_was_good and try_count < 5:
                    print(0, 0, pitch, yaw)
                    sample_cloud = capture_sample(0.0, pitch, yaw)
                    sample_cloud_arr = ros_to_pcl(sample_cloud).to_array()

                    # Check for invalid clouds.
                    if sample_cloud_arr.shape[0] == 0:
                        print('Invalid cloud detected')
                        try_count += 1
                    else:
                        sample_was_good = True

                # Extract histogram features
                chists = compute_color_histograms(sample_cloud, using_hsv=True)
                normals = get_normals(sample_cloud)
                nhists = compute_normal_histograms(normals)
                feature = np.concatenate((chists, nhists))
                labeled_features.append([feature, model_name])
       'plastic_cup',
       'soda_can']

    # Disable gravity and delete the ground plane
    initial_setup()
    labeled_features = []

    for model_name in models:
        spawn_model(model_name)

        for i in range(5):
            # make five attempts to get a valid a point cloud then give up
            sample_was_good = False
            try_count = 0
            while not sample_was_good and try_count < 5:
                sample_cloud = capture_sample()
                sample_cloud_arr = ros_to_pcl(sample_cloud).to_array()

                # Check for invalid clouds.
                if sample_cloud_arr.shape[0] == 0:
                    print('Invalid cloud detected')
                    try_count += 1
                else:
                    sample_was_good = True

            # Extract histogram features
            chists = compute_color_histograms(sample_cloud, using_hsv=False)
            normals = get_normals(sample_cloud)
            nhists = compute_normal_histograms(normals)
            feature = np.concatenate((chists, nhists))
            labeled_features.append([feature, model_name])