facebookresearch / detectron2

Detectron2 is a platform for object detection, segmentation and other visual recognition tasks.
https://detectron2.readthedocs.io/en/latest/
Apache License 2.0
29.3k stars 7.32k forks source link

🐛 Minor Bug: PointsVisualizer() throws error when passed floating coordinate values #5249

Open soumya997 opened 2 months ago

soumya997 commented 2 months ago
  1. Issue: I can't share my code but below is a minimal code sample to reproduce the error. My code calls the function DensePoseDataPointsVisualizer() and internally it calls PointsVisualizer(), at the 108 line cv2.circle() gets called, but as the centre coordinates passed in that function is in float, cv2 throws an error, as cv2.circle() expects integer pixel coordinates as centre.

Here is the google colab notebbok that reproduces the error.

height, width = 400, 400
radius = 50
image = np.random.randint(0, 256, (height, width, 3), dtype=np.uint8)
centers = [(100.09, 100.5), (300.6, 300.89)]

viz_func = PointsVisualizer()
viz_func.visualize(image, centers)
  1. Error Log:
    
    ---------------------------------------------------------------------------
    error                                     Traceback (most recent call last)
    [<ipython-input-3-fe6e38084d89>](https://localhost:8080/#) in <cell line: 2>()
      1 viz_func = PointsVisualizer()
    ----> 2 viz_func.visualize(image, centers)

/content/detectron2/projects/DensePose/densepose/vis/base.py in visualize(self, image_bgr, pts_xy, colors_bgr, rs) 106 color_bgr = colors_bgr[j] if colors_bgr is not None else self.color_bgr 107 r = rs[j] if rs is not None else self.r --> 108 cv2.circle(image_bgr, (x, y), r, color_bgr, -1) 109 return image_bgr 110

error: OpenCV(4.8.0) :-1: error: (-5:Bad argument) in function 'circle'

Overload resolution failed:

  • Can't parse 'center'. Sequence item with index 0 has a wrong type
  • Can't parse 'center'. Sequence item with index 0 has a wrong type
  1. Changes Made: changed, x, y = pt_xy to x, y = [int(val) for val in pt_xy]

https://github.com/soumya997/detectron2/blob/somusan-fixes/projects/DensePose/densepose/vis/base.py#L95C1-L109C25

  1. output of git rev-parse HEAD; git diff 0f3f9920d3e98e4db7442c19262d5f0eade25581