Skip to main content
Known Participant
April 13, 2023
Question

letters recognition from paths

  • April 13, 2023
  • 6 replies
  • 3710 views

In Adobe Illustrator I have several paths like English letters for example “A”, note that this is a path or compound path and not a outlined text, so I need to recognize each letter from these paths using script.

is it possible?

This topic has been closed for replies.

6 replies

Inventsable
Legend
April 14, 2023

I don't think this would be difficult unless the hand-drawn font doesn't share exact path data. If you're duplicating these characters from the same source then it wouldn't be hard to recognize paths as a specific letter:

 

The letter A will always have the same amount of pathPoints, the length from anchors A1 > A2 and so on is always going to be the same and even if scaled differently (since it's still proportional), so if you transpose the PathPoints to being relative instead of absolute by something like any anchor of geometricBounds then you could work with ratios and the length from A1 > A2 then A2 > A3 even if not identical would still be a multiple or proportionate from one scale to another, and the same applies to handles.

 

The difficulty of going this route would be that you'd need to record each character that needs to be recognized and store this in something like a JSON so that a script could parse it then take PathPoints and do a lookup to:

 

  1.  Find every letter that has the same amount of pathPoints and same amount of handles inside as a possible match
  2. Transpose the incoming letter as relative coordinates
  3. Either compare all x and y positions including handles or do something like using a Math.hypot() polyfill or other simple means to just get the distance between two coordinate points and measure distances between 1 > 2 > 3 to compare each, though on false match you'd need to continue checking subsequent points and divide the smallest length by largest to get a ratio and begin checking if the ratio is the same for every point which accounts for differences in scaling, and this would need to be done on every single point and handle

 

If this matches then it'd be the same exact character. This is probably more complex than you're looking for but I do think it's important to point out that sure, it could be done through scripting and Javascript if you have a shared character base since you just need coordinate data.

m1b
Community Expert
Community Expert
April 14, 2023

I have written this exact script! I use it to select similar items to the selected item on the page. I make a sort-of-hash array of each path item of segment length as ratio to path lengths and angles of each point. It works very well for exact duplicates (even when scaled or rotated) but not so well when the paths have been modified, although it makes a good attempt!

 

However, I didn't mention it here because I think the OP has different needs.

- Mark

AliTleissAuthor
Known Participant
April 14, 2023

I benefited greatly from the methodology of thinking  @Inventsable 

thanks.

Legend
April 14, 2023

ExtendScript alone is very difficult; AppleScript or CEP (Node.js) makes it relatively easy to achieve.

 

It is recommended to use OCR for text recognition. For example, the following.

 

The process flow is as follows: 

  1. Convert compound path to png by imageCapture
  2. Recognize text from png by OCR (AppleScript or Node.js are needed at this step)
m1b
Community Expert
Community Expert
April 14, 2023

As @sttk3 mentioned, as you appear to be using MacOS, AppleScript and the Vision framework may come to the rescue. See this script for a great example. You could combine it with Document.ImageCapture to return text from on the selection, or the artboard bounds, for example.

- Mark

m1b
Community Expert
Community Expert
April 14, 2023

Can you post some indicative example files? (Post as .pdfs because forum software doesn't accept .ai files.)

m1b
Community Expert
Community Expert
April 14, 2023

Hi @AliTleiss, so just to confirm: each letter path is different, for example an "C" path may have different number and placement of points than another "C"? Or will each "C" be identical (aside from position, scale and rotation of course).

- Mark

CarlosCanto
Community Expert
Community Expert
April 13, 2023

There's a slight chance these elements could be targeted. If there was a pattern a script could follow it could be possible. For example, the letter B should be a compound path with 3 path items in it, if you don't expect other art to have this particular setup then it could be found.

AliTleissAuthor
Known Participant
April 13, 2023

ok true, the compound path "B" has 3 paths so i can detect it by this features.

but what for other letters

CarlosCanto
Community Expert
Community Expert
April 13, 2023

That was a random example, your actual files would need to  be analized to find solutions.

Monika Gause
Community Expert
Community Expert
April 13, 2023

The plugin VectorFirstAid can do it provided that the original font is installed on your computer.

AliTleissAuthor
Known Participant
April 13, 2023

 VectorFirstAid

CLEAN UP VECTOR DOCUMENTS

  • Convert outline text back to editable text
  • Change text-point alignment
  • Reduce file size by eliminating redundant information
  • Recover resources from old files

This is what this plugin does, and your reply meant "convert outline text back into editable text", but before I say it's a path and not an outline text, so the source for these paths is not an outline text.

I think I need to work with every point in the path (Anchor, LeftDirection, RigthDirection).

I think but how?

Monika Gause
Community Expert
Community Expert
April 13, 2023

In your screenshot the examples look like a real font.

So it's not? You have drawn them freely?

It's probably not possible to recognize a letter from the path direction, because each letter can be drawn in several different ways. This even applies to the letter I