Beispiel #1
0
    def kitti_dataset_analysis(self):
        searchlabel = os.path.join(path_kitti, "image_*", "*.png")
        fileslabel = glob.glob(searchlabel)
        fileslabel.sort()

        dilatation = 10
        threshold = 0.1

        for i in range(len(fileslabel)):

            img = cv2.imread(fileslabel[i])

            img = cv2.imread(fileslabel[i], -1)
            img = img.astype(np.uint16)
            img = cv2.resize(img, (1024, 320))

            results = self.model.detect([img],
                                        dilatation,
                                        threshold,
                                        verbose=1)
            r = results[0]

            selected_class = self.class_selection(r['masks'], r['class_ids'])
            #selected_class = r['masks']

            result_image = visualize_cv.cv_img_masked(img, r['rois'],
                                                      selected_class,
                                                      r['class_ids'],
                                                      self.class_names,
                                                      r['scores'])

            cv2.imwrite(fileslabel[i], result_image.astype('uint8'))
        print("Batch done")
Beispiel #2
0
    def live_depth_analysis(self):
        #Live stream video analysis

        while not rospy.is_shutdown():

            #print("Looking for a frame")

            current_frame = self.frame
            current_depth_frame = self.depth_frame

            if (current_frame != [] and current_depth_frame != []):
                #print("got frame")
                #image = cv2.imread("/home/pmcrivet/catkin_ws/src/Mask_RCNN/script/images/frame0057.jpg")

                #img = numpy.asarray(frame,dtype='uint8')

                #cv2.imshow("image",image)
                #cv2.waitKey(0)
                #cv2.destroyAllWindows()

                #print image.shape
                #print image.dtype

                #Dilatation effect on masks for better feature masking
                dilatation = 20
                threshold = 0.3

                results = self.model.detect([current_frame],
                                            dilatation,
                                            threshold,
                                            verbose=1)
                r = results[0]

                #selected_class = self.class_selection(r['masks'], r['class_ids'])
                selected_class = r['masks']

                result_image = visualize_cv.cv_img_masked(
                    current_frame, r['rois'], selected_class, r['class_ids'],
                    self.class_names, r['scores'])
                result_depth_image = visualize_cv.cv_depth_img_masked(
                    current_depth_frame, r['rois'], selected_class,
                    r['class_ids'], self.class_names, r['scores'])

                DITS = Image()
                ITS = Image()
                DITS = self.bridge.cv2_to_imgmsg(result_depth_image, '16UC1')
                ITS = self.bridge.cv2_to_imgmsg(result_image, 'bgr8')
                DITS.header = self.depth_msg_header
                ITS.header = self.msg_header
                self.image_pub.publish(ITS)
                self.depth_image_pub.publish(DITS)
                print("Publishing img")
            else:
                print("Waiting for frame")
Beispiel #3
0
 def process_image(self, image):
     dilatation = 1
     threshold = 0.1
     results = self.model.detect([image], dilatation, threshold, verbose=1)
     r = results[0]
     selected_class = r['masks']
     result_image = visualize_cv.cv_img_masked(image, r['rois'],
                                               selected_class,
                                               r['class_ids'],
                                               self.class_names,
                                               r['scores'])
     return result_image
Beispiel #4
0
    def live_analysis(self):
        #Live stream video analysis

        while not rospy.is_shutdown():

            #print("Looking for a frame")

            current_frame = self.frame

            if current_frame != []:
                #print("got frame")
                #image = cv2.imread("/home/pmcrivet/catkin_ws/src/Mask_RCNN/script/images/frame0057.jpg")

                #img = numpy.asarray(frame,dtype='uint8')

                #cv2.imshow("image",image)
                #cv2.waitKey(0)
                #cv2.destroyAllWindows()

                #print image.shape
                #print image.dtype

                results = self.model.detect([current_frame], verbose=1)
                r = results[0]
                result_image = visualize_cv.cv_img_masked(
                    current_frame, r['rois'], r['masks'], r['class_ids'],
                    self.class_names, r['scores'])

                cv2.namedWindow('result_image', cv2.WINDOW_NORMAL)
                #cv2.resizeWindow('result_image', 1920, 1080)
                cv2.imshow("result_image", result_image)

                print("Did something")

                #results = self.model.detect([self.frame], verbose=1)
                #r = results[0]
                #visualize_cv.display_instances(image, r['rois'], r['masks'], r['class_ids'],self.class_names, r['scores'])

                ITS = Image()
                ITS = self.bridge.cv2_to_imgmsg(result_image, 'bgr8')
                ITS.header = self.msg_header
                self.image_pub.publish(ITS)
                print("Publishing img")
            else:
                print("Waiting for frame")
Beispiel #5
0
    def tum_dataset_analysis(self):
        searchlabel = os.path.join(path_tum, "rgb_sync", "*.png")
        fileslabel = glob.glob(searchlabel)
        fileslabel.sort()

        searchanot = os.path.join(path_tum, "depth_sync", "*.png")
        filesanot = glob.glob(searchanot)
        filesanot.sort()

        dilatation = 20
        threshold = 0.3

        for i in range(len(filesanot)):

            img = cv2.imread(fileslabel[i])
            #depth_img = cv2.cvtColor(cv2.imread(filesanot[i]), cv2.COLOR_BGR2GRAY)
            depth_img = cv2.imread(filesanot[i], -1)
            depth_img = depth_img.astype(np.uint16)

            results = self.model.detect([img],
                                        dilatation,
                                        threshold,
                                        verbose=1)
            r = results[0]

            selected_class = self.class_selection(r['masks'], r['class_ids'])
            #selected_class = r['masks']

            result_image = visualize_cv.cv_img_masked(img, r['rois'],
                                                      selected_class,
                                                      r['class_ids'],
                                                      self.class_names,
                                                      r['scores'])
            result_depth_image = visualize_cv.cv_depth_img_masked(
                depth_img, r['rois'], selected_class, r['class_ids'],
                self.class_names, r['scores'])

            cv2.imwrite(filesanot[i], result_depth_image)
        print("Batch done")