Ask Your Question
0

How to compare two handwriting characters to get similarity score

asked 2018-07-16 02:34:53 -0600

sinojelly gravatar image

I want to compare two handwriting Chinese characters to get the similarity score(percent). We think that one is the normative writing, and the other is to evaluate the similarity with the normative one.

Handwriting with a higher similarity score should: 1 The structure is most similar to the normative one. 2 Strokes are smooth. 3 Stroke shapes are most similar to the normative one.

The two handwriting characters are in two images with the same size, and all with white background color and black foreground color.

How to get the most accurate similarity score and have a faster speed?

Should I use cvMatchTemplate? and get the similarity score(max_val) with cvMinMaxLoc?

Or use HausdorffDistanceExtractor, and getRankProportion () as the similarity score?

Or use ShapeContextDistanceExtractor, and call computeDistance (img1, img2) to get the distance as similarity? But how to convert it to a percentage form?

Any suggestions would be appreciated.

Thanks!

edit retag flag offensive close merge delete

Comments

1

none of those ideas will reliably work, and you should NOT try anything with the deprecated c-api (cv* functions)

in the end, you'll need some form of machine learning here, like a training a cnn

berak gravatar imageberak ( 2018-07-16 03:00:27 -0600 )edit

I also thought about CNN or DNN, but I haven't figured out how to convert this problem into a neural network problem. Is it an image classification problem? Like this: I use all the normative writing words as training data, and the label corresponding to each word picture is this word. Then, rotate all the normative writing words to obtain a larger amount of data, and then the data is used to train the neural network. Finally, enter the neural network with the word to be scored. It gives the similarity to a certain word, and this is the score.

The neural network requires a lot of data, so the rotation and other transformations are used to generate more data. Does this affect the result? Can I add words of different fonts as training data?Is there a model I can transfer learning from?

sinojelly gravatar imagesinojelly ( 2018-07-16 03:54:28 -0600 )edit

I also thought about CNN or DNN, but I haven't figured out how to convert this problem into a neural network problem. Is it an image classification problem?

Well you could consider every unique character as a class. A popular example of this is the mnist dataset . This dataset is used to train a cnn to detect handwritten digits. And each digit is a class in the resulting model (0-9).

You dont always need to train from scratch / define your own dataset. Maybe you find a pre trained model which can already extract chinese characters.

And you could even evaluate this model via the opencv dnn module. I say could - not must - you can always use the api on which the model was trained(caffe, tensorflow, torch, etc.)

holger gravatar imageholger ( 2018-07-16 04:29:45 -0600 )edit
1

What i want to say - forget about similarity / template matching - find a cnn model which can extract the chinese characters into text and then just do a simple string comparison in the programming language of your choice.

holger gravatar imageholger ( 2018-07-16 04:36:14 -0600 )edit
1

Do you really need to do this using OpenCV or some CNN / DNN framework? If Holger's approach does work for you, I would suggest not to expend too much effort training your own network. A very quick and pragmatic approach would be to leverage cognitive services text analytic APIs from Google, Microsoft, etc. Just pointing this out as it can save you a lot of time and effort; however, I do appreciate you may have constraints or objectives that prevent you from using such cloud services.

Evren gravatar imageEvren ( 2018-07-16 11:22:09 -0600 )edit

If I use CNN, the question of how similar the handwriting is to the standard word is a classification problem or a regression problem? Because in fact, I really need a percentage of similarity. I also hope that there will be an AI cloud services, and it is best to use Core ML for simple calls. But I looked at the Microsoft Vision cloud service, which only has OCR for English characters. I also looked at the Google Vision cloud service. Dragging a Chinese character image into it, I got only the information like Black 95%, and I couldn't find how to get the similarity between the two word images.

sinojelly gravatar imagesinojelly ( 2018-07-16 21:39:39 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2018-07-17 03:59:07 -0600

Evren gravatar image

updated 2018-07-17 04:00:12 -0600

A CNN can do classification or regression, it depends on what you are building it for. If you wanted to look at similarity between images, you can perhaps explore one shot learning approaches. You really need to be clear about your objective here. Is it that you need to find similarity between a few / small group of Chinese words or is it detecting similarity between any word? More importantly, why are you finding similarity? If you are trying to see if one word matches another, then a classification type outcome is OK. However, if you are trying to detect if one piece of hand writing compared to another was written by the same person, then the challenge and associated solution would be very different.

Azure Cognitive Services OCR is not limited to English and does OCR Chinese characters. But you need to use the OCR service. There is a new Recognise Text service which is English only, but the OCR works fine. I have tested it at this location with the below sample image:

https://northeurope.dev.cognitive.mic...

{"url":"http://www.words-chinese.com/images2/chinese_symbols_for_power_6637_2_110.png"}

edit flag offensive delete link more

Comments

Thank you for your detailed reply.Yes, I just want to look at similarity between images. I just want to compare the similarity between the words written by the students and the standard words to evaluate the quality of the students' writing.Of course it's better to detect similarity between any word.I don't have an Ocp-Apim-Subscription-Key, so I can't get the result Azure Cognitive Services OCR returned.Would you do me a favor to paste it here? I want to know how to get the similarity from the result.Thanks very much!

sinojelly gravatar imagesinojelly ( 2018-07-17 19:41:41 -0600 )edit

You can get a subscription key for free by signing up to Azure Portal and you will be able to run plenty of tests without having to pay a penny. These keys are sensitive and I cannot share mine online.

I think you need to refine your approach based on what you are trying to achieve. It sounds like you want to evaluate students against multiple criteria, yet you are trying to capture the outcome under one similarity metric. This would result in a situation where a student may be rated as not being similar enough to the desired word, but there would be no way of indicating why. If I were you, I would break this problem in to smaller objectives.

For measuring similarity, you can try experimenting with approaches such as one shot learning and triplet loss but you do have a challenge ahead.

Evren gravatar imageEvren ( 2018-07-18 11:57:49 -0600 )edit

Thanks! Maybe I should try one shot learning or Siamese Network, and I found a paper here, it seems meet my requirements very much, but I can't find an implementation. https://cims.nyu.edu/~brenden/LakeEtA...

sinojelly gravatar imagesinojelly ( 2018-07-18 19:33:11 -0600 )edit

This walkthrough may be a starting point for you to build one yourself using Keras:

One Shot Learning and Siamese Networks in Keras

If this answer has been useful and is putting you on the right track, please accept it so that others can benefit from the information shared.

Evren gravatar imageEvren ( 2018-07-19 02:56:01 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2018-07-16 02:34:53 -0600

Seen: 1,836 times

Last updated: Jul 17 '18