Exemplo n.º 1
0
    def callback(self, obst_list, image):
        self.publisher_bblinelist.publish(
            self.bbmarker)  # since a single publish is likely to get lost
        # print "CALLBACK HERE"
        if (self.show_marker):
            marker_list = self.visualizer.visualize_marker(obst_list)
            self.publisher_marker.publish(marker_list)

        # 4. EVENTUALLY DISPLAY IMAGE
        if (self.show_image):
            obst_image = CompressedImage()
            obst_image.header.stamp = image.header.stamp
            obst_image.format = "jpeg"
            obst_image.data = self.visualizer.visualize_image(
                rectify(rgb_from_ros(image), self.intrinsics), obst_list)
            self.publisher_img.publish(obst_image.data)
    def ProcessRawImage(self, img_raw):
        # rectify image
        img_undistorted = dt.rectify(dt.rgb_from_ros(img_raw), self.intrinsics)

        # compute grayscale image
        img_gray = cv2.cvtColor(img_undistorted, cv2.COLOR_RGB2GRAY)

        # detect edges
        img_canny = cv2.Canny(img_gray, self.canny_lower_threshold, self.canny_upper_threshold,
                              apertureSize=self.canny_aperture_size)

        # apply mask
        img_mask = cv2.bitwise_and(img_canny,self.mask_visible)

        # pad image to avoid running into borders
        img_processed = cv2.copyMakeBorder(img_mask, self.line_search_length, self.line_search_length,
                                           self.line_search_length, self.line_search_length, cv2.BORDER_CONSTANT,
                                           value=0)

        return img_processed, img_gray
Exemplo n.º 3
0
    def callback(self, image):
        if not self.active:
            return

        if not self.thread_lock.acquire(False):
            return

        #start = time.time()
        obst_list = PoseArray()
        marker_list = MarkerArray()

        # pass RECTIFIED IMAGE TO DETECTOR MODULE
        #1. EXTRACT OBSTACLES and return the pose array
        obst_list = self.detector.process_image(
            rectify(rgb_from_ros(image), self.intrinsics))

        obst_list.header.stamp = image.header.stamp  #for synchronization
        #interessant um zu schauen ob stau oder nicht!!!!
        #print image.header.stamp.to_sec()
        self.publisher_arr.publish(obst_list)
        #EXPLANATION: (x,y) is world coordinates of obstacle, z is radius of obstacle
        #QUATERNION HAS NO MEANING!!!!

        #3. VISUALIZE POSE ARRAY IN TF
        if (self.show_marker):
            marker_list = self.visualizer.visualize_marker(obst_list)
            self.publisher_marker.publish(marker_list)

        #4. EVENTUALLY DISPLAY !!!!CROPPED!!!!!! IMAGE
        if (self.show_image):
            obst_image = CompressedImage()
            obst_image.header.stamp = image.header.stamp
            obst_image.format = "jpeg"
            obst_image.data = self.visualizer.visualize_image(
                rectify(rgb_from_ros(image), self.intrinsics), obst_list)
            #here i want to display cropped image
            rgb_image = rgb_from_ros(obst_image.data)
            obst_image.data = d8_compressed_image_from_cv_image(
                rgb_image[self.detector.crop:, :, ::-1])
            #THIS part only to visualize the cropped version -> somehow a little inefficient but keeps
            #the visualizer.py modular!!!
            self.publisher_img.publish(obst_image.data)

        if (self.show_bird_perspective):
            bird_perspective_image = CompressedImage()
            bird_perspective_image.header.stamp = image.header.stamp
            bird_perspective_image.format = "jpeg"
            bird_perspective_image.data = self.visualizer.visualize_bird_perspective(
                rectify(rgb_from_ros(image), self.intrinsics), obst_list)
            #here i want to display cropped image
            rgb_image = rgb_from_ros(obst_image.data)
            obst_image.data = d8_compressed_image_from_cv_image(rgb_image)
            #THIS part only to visualize the cropped version -> somehow a little inefficient but keeps
            #the visualizer.py modular!!!
            self.publisher_img_bird_perspective.publish(obst_image.data)

        #end = time.time()
        #print "OBST DETECTION TOOK: s"
        #print(end - start)
        self.r.sleep()
        self.thread_lock.release()
Exemplo n.º 4
0
#cv2.imwrite(dir+ '/' + str(i) + '.jpg',im1)

nummer = 1

while (True):
    filename = im_path + '/' + str(nummer) + '.jpg'
    im1 = cv2.imread(filename)  #reads BGR
    if (im1 is None):
        #stop it!
        break

    else:  #START MODIFYING THE IMAGE!!!
        #-------------HERE GOES THE REAL CODE-----------------------------------------------------------
        #-----------------------------------------------------------------------------------------------

        obst_list = detector.process_image(rectify(im1[:, :, ::-1],
                                                   intrinsics))
        obst_image = CompressedImage()
        obst_image.format = "jpeg"
        obst_image.data = visualizer.visualize_image(
            rectify(im1[:, :, ::-1], intrinsics), obst_list)
        #here i want to display cropped image
        image = rgb_from_ros(obst_image.data)
        image = image[crop:, :, :]
        #THIS part only to visualize the cropped version -> somehow a little inefficient but keeps
        #the visualizer.py modular!!!
        #plt.imshow(image[detector.crop:,:,:]);plt.show() #the cropped image
        #plt.imshow(image);plt.show()                     #normal sized image
        #SAVE THE IMAGE
        conv = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
        cv2.imwrite(dir_path + '/' + str(nummer) + '.jpg', conv)
        nummer += 1
Exemplo n.º 5
0
 def process_image(self, image):
     return d8_compressed_image_from_cv_image(
         rectify(image[..., ::-1], self.intrinsics)).data