1

I have found this simple code below on some internet page, but I'm getting an error trying to execute it on my laptop. It should display an image with some bounding boxes on it.

The error occurs not in my code, but in ingaug.py, so inside of the package file. Is it some bug in the imgaug package?

I'm using MacOS, installed imgaug with condo from condo-forge channel.

Python code:

import imageio
import imgaug as ia
from imgaug.augmentables.bbs import BoundingBox, BoundingBoxesOnImage
%matplotlib inline
ia.seed(1)

image = imageio.imread("https://upload.wikimedia.org/wikipedia/commons/8/8e/Yellow-headed_caracara_%28Milvago_chimachima%29_on_capybara_%28Hydrochoeris_hydrochaeris%29.JPG")
image = ia.imresize_single_image(image, (298, 447))

bbs = BoundingBoxesOnImage([
    BoundingBox(x1=0.2*447, x2=0.85*447, y1=0.3*298, y2=0.95*298),
    BoundingBox(x1=0.4*447, x2=0.65*447, y1=0.1*298, y2=0.4*298)
], shape=image.shape)

ia.imshow(bbs.draw_on_image(image, size=2))

Error massage:

AttributeError                            Traceback (most recent call last)
Cell In[1], line 15
      8 image = ia.imresize_single_image(image, (298, 447))
     10 bbs = BoundingBoxesOnImage([
     11     BoundingBox(x1=0.2*447, x2=0.85*447, y1=0.3*298, y2=0.95*298),
     12     BoundingBox(x1=0.4*447, x2=0.65*447, y1=0.1*298, y2=0.4*298)
     13 ], shape=image.shape)
---> 15 ia.imshow(bbs.draw_on_image(image, size=2))

File ~/miniconda3/envs/imgaug/lib/python3.11/site-packages/imgaug/imgaug.py:2120, in imshow(image, backend)
   2117 w = max(w, 6)
   2119 fig, ax = plt.subplots(figsize=(w, h), dpi=dpi)
-> 2120 fig.canvas.set_window_title("imgaug.imshow(%s)" % (image.shape,))
   2121 # cmap=gray is automatically only activate for grayscale images
   2122 ax.imshow(image, cmap="gray")

AttributeError: 'FigureCanvasAgg' object has no attribute 'set_window_title'
tomxor
  • 11
  • 1
  • 2

2 Answers2

3
  • Open "imgaug.py" file, change line 2120 to:

fig.canvas.manager.set_window_title("imgaug.imshow(%s)" % (image.shape,))

HugeHard
  • 31
  • 2
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 11 '23 at 02:17
1

Changing matplotlib version to 3.5 works.

都津齐
  • 11
  • 1
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 13 '23 at 08:50