def test_draw_keypoints_on_image_array(self):
    test_image = self.create_colorful_test_image()
    width_original = test_image.shape[0]
    height_original = test_image.shape[1]
    keypoints = [[0.25, 0.75], [0.4, 0.6], [0.1, 0.1], [0.9, 0.9]]

    visualization_utils.draw_keypoints_on_image_array(test_image, keypoints)
    width_final = test_image.shape[0]
    height_final = test_image.shape[1]

    self.assertEqual(width_original, width_final)
    self.assertEqual(height_original, height_final)
  def test_draw_keypoints_on_image_array(self):
    test_image = self.create_colorful_test_image()
    width_original = test_image.shape[0]
    height_original = test_image.shape[1]
    keypoints = [[0.25, 0.75], [0.4, 0.6], [0.1, 0.1], [0.9, 0.9]]

    visualization_utils.draw_keypoints_on_image_array(test_image, keypoints)
    width_final = test_image.shape[0]
    height_final = test_image.shape[1]

    self.assertEqual(width_original, width_final)
    self.assertEqual(height_original, height_final)
示例#3
0
    def test_draw_keypoints_on_image_array(self):
        test_image = self.create_colorful_test_image()
        width_original = test_image.shape[0]
        height_original = test_image.shape[1]
        keypoints = [[0.25, 0.75], [0.4, 0.6], [0.1, 0.1], [0.9, 0.9]]
        keypoint_edges = [(0, 1), (1, 2), (2, 3), (3, 0)]

        visualization_utils.draw_keypoints_on_image_array(
            test_image,
            keypoints,
            keypoint_edges=keypoint_edges,
            keypoint_edge_width=1,
            keypoint_edge_color='green')
        width_final = test_image.shape[0]
        height_final = test_image.shape[1]

        self.assertEqual(width_original, width_final)
        self.assertEqual(height_original, height_final)
示例#4
0
文件: test.py 项目: mojtaba1989/TAD
            try:
                QtGui.QApplication.processEvents()
                time.sleep(.1)
            except KeyboardInterrupt:

                win.close()
                break

    elif OUTPUT == 'image':
        image = pdf.undistort(PATH_TO_IMAGE)
        rows, cols, ch = image.shape

        M = cv2.getRotationMatrix2D((cols / 2, rows / 2), 0, 1)
        image = cv2.warpAffine(image, M, (cols, rows))

        vis_util.draw_keypoints_on_image_array(image,
                                               keypoints,
                                               color='blue',
                                               radius=5,
                                               use_normalized_coordinates=True)

        # All the results have been drawn on image. Now display the image.
        image = cv2.resize(image, (800, 600))
        cv2.imshow('Object detector', image)

        # Press any key to close the image
        cv2.waitKey(0)

        # Clean up
        cv2.destroyAllWindows()
示例#5
0
def visualize_boxes_with_opc_info(image,
                                  boxes,
                                  classes,
                                  scores,
                                  category_index,
                                  instance_masks=None,
                                  keypoints=None,
                                  use_normalized_coordinates=False,
                                  max_boxes_to_draw=20,
                                  min_score_thresh=.5,
                                  agnostic_mode=False,
                                  line_thickness=4):
    """Overlay labeled boxes on an image with formatted scores and label names.

  This function groups boxes that correspond to the same location
  and creates a display string for each detection and overlays these
  on the image. Note that this function modifies the image in place, and returns
  that same image.

  Args:
    image: uint8 numpy array with shape (img_height, img_width, 3)
    boxes: a numpy array of shape [N, 4]
    classes: a numpy array of shape [N]. Note that class indices are 1-based,
      and match the keys in the label map.
    scores: a numpy array of shape [N] or None.  If scores=None, then
      this function assumes that the boxes to be plotted are groundtruth
      boxes and plot all boxes as black with no classes or scores.
    category_index: a dict containing category dictionaries (each holding
      category index `id` and category name `name`) keyed by category indices.
    instance_masks: a numpy array of shape [N, image_height, image_width], can
      be None
    keypoints: a numpy array of shape [N, num_keypoints, 2], can
      be None
    use_normalized_coordinates: whether boxes is to be interpreted as
      normalized coordinates or not.
    max_boxes_to_draw: maximum number of boxes to visualize.  If None, draw
      all boxes.
    min_score_thresh: minimum score threshold for a box to be visualized
    agnostic_mode: boolean (default: False) controlling whether to evaluate in
      class-agnostic mode or not.  This mode will display scores but ignore
      classes.
    line_thickness: integer (default: 4) controlling line width of the boxes.

  Returns:
    uint8 numpy array with shape (img_height, img_width, 3) with overlaid boxes.
  """
    # Create a display string (and color) for every box location, group any boxes
    # that correspond to the same location.
    box_to_display_str_map = collections.defaultdict(list)
    box_to_color_map = collections.defaultdict(str)
    box_to_instance_masks_map = {}
    box_to_keypoints_map = collections.defaultdict(list)
    if not max_boxes_to_draw:
        max_boxes_to_draw = boxes.shape[0]
    for i in range(min(max_boxes_to_draw, boxes.shape[0])):
        if scores is None or scores[i] > min_score_thresh:
            box = tuple(boxes[i].tolist())
            if instance_masks is not None:
                box_to_instance_masks_map[box] = instance_masks[i]
            if keypoints is not None:
                box_to_keypoints_map[box].extend(keypoints[i])
            if scores is None:
                box_to_color_map[box] = 'black'
            else:
                if not agnostic_mode:
                    if classes[i] in category_index.keys():
                        class_name = category_index[classes[i]]['name']
                    else:
                        class_name = 'N/A'
                    display_str = '{}: {}%'.format(class_name,
                                                   int(100 * scores[i]))
                else:
                    display_str = 'score: {}%'.format(int(100 * scores[i]))

                if class_name in opc_client.opc_id.keys():
                    display_str = display_str + " " + opc_info.get_value(
                        class_name)
                    print display_str
                box_to_display_str_map[box].append(display_str)
                if agnostic_mode:
                    box_to_color_map[box] = 'DarkOrange'
                else:
                    box_to_color_map[box] = vis_util.STANDARD_COLORS[
                        classes[i] % len(vis_util.STANDARD_COLORS)]

    # Draw all boxes onto image.
    for box, color in box_to_color_map.items():
        ymin, xmin, ymax, xmax = box
        if instance_masks is not None:
            vis_util.draw_mask_on_image_array(image,
                                              box_to_instance_masks_map[box],
                                              color=color)
        vis_util.draw_bounding_box_on_image_array(
            image,
            ymin,
            xmin,
            ymax,
            xmax,
            color=color,
            thickness=line_thickness,
            display_str_list=box_to_display_str_map[box],
            use_normalized_coordinates=use_normalized_coordinates)
        if keypoints is not None:
            vis_util.draw_keypoints_on_image_array(
                image,
                box_to_keypoints_map[box],
                color=color,
                radius=line_thickness / 2,
                use_normalized_coordinates=use_normalized_coordinates)

    return image