Page 1 of 1

Detect bounding box of characters written by convert

Posted: 2019-08-08T03:01:39-07:00
by kymillev
I came across a paper (https://arxiv.org/pdf/1608.04224.pdf) which uses synthetic handwriting data generated with the ImageMagick convert command, using a lot of different handwriting fonts like the images below.
Image
I am new to using the ImageMagick tool but I was wondering if I can get a tight bounding box for each individual character in each word. I'm not sure how the convert function works, but if it writes each letter separately, it should be possible to get the bounding box after writing the letter right?

Re: Detect bounding box of characters written by convert

Posted: 2019-08-08T03:44:57-07:00
by snibgo
The PDF has error 403 "Forbidden". If you give the title and author, perhaps the paper is available elsewhere.

IM calls a delegate to rasterize text strings. It can do this multiple times to build up a string, which could give the bounding box of each added character. It's a bit messy because glyphs can overlap.

For example, it can rasterize "easil" and then "easily". The difference between these gives the bounding box of the final "y".

Re: Detect bounding box of characters written by convert

Posted: 2019-08-08T08:52:44-07:00
by fmw42
If each character is separate (does not touch any other character), then you can use -connected-components to get the bounding boxes of each character. If they touch, then it would get the bounding box of all connected characters and not each one separately. See https://imagemagick.org/script/connected-components.php. Once you have the bounding boxes, you can draw boxes around each separate region.

Re: Detect bounding box of characters written by convert

Posted: 2019-08-13T05:38:45-07:00
by kymillev
Thanks for the advice, I have solved the problem by generating each letter iteratively and masking the previously generated letters to get the bounding box of the new one with OpenCV. This of course causes a lot of overlap for each bounding box, but that should be fine.

Example output:
Image