Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust scale before running recognition model #91

Merged
merged 1 commit into from
Oct 26, 2019
Merged

Conversation

kingst
Copy link
Collaborator

@kingst kingst commented Oct 26, 2019

This PR uses the bounding box around the card number detection model to adjust the scale for recognition boxes. The underlying assumption is that clusters of 4 digits maintain the same aspect ratio, thus you can get more consistent digit sizes when we do recognition.

This scaling technique only applies to horizontal cards.

@kingst kingst requested review from dxaen and jaimejiyepark October 26, 2019 17:08
let numberMaxX = line.map({ $0.rect.maxX }).max() ?? 0.0
let numberWidth = numberMaxX - numberMinX
let boxWidth = line.first?.rect.width ?? 1.0
let scale = Double(numberWidth * 1.2 / (boxWidth * 4.0))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please explain this line? Why 1.2?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, does it apply to Amex cards?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I evaluated this empirically. On our validation set from TestOcr the frame prediction recall went from 54% to 64% and on our test set it went from 44% to 65%. The larger increase in testing is likely due to the fact that our testing set has more embossed cards, which appear to benefit more from this optimization.

So in other words, I pulled it out of thin air, but it does seem to work :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It only applies to horizontal 16 digit cards. Check out the changes to FindFourOcr.swift, if you expand the hidden parts you'll see that when it calls the number method on vertical and amex that useScale uses the default value (ie false)

@kingst kingst merged commit dc25c66 into master Oct 26, 2019
@kingst kingst deleted the adjust_scale branch October 26, 2019 17:32
Copy link
Collaborator Author

@kingst kingst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still figuring out github

let numberMaxX = line.map({ $0.rect.maxX }).max() ?? 0.0
let numberWidth = numberMaxX - numberMinX
let boxWidth = line.first?.rect.width ?? 1.0
let scale = Double(numberWidth * 1.2 / (boxWidth * 4.0))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It only applies to horizontal 16 digit cards. Check out the changes to FindFourOcr.swift, if you expand the hidden parts you'll see that when it calls the number method on vertical and amex that useScale uses the default value (ie false)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants