evermeer / PassportScanner

Scan the MRZ code of a passport and extract the firstname, lastname, passport number, nationality, date of birth, expiration date and personal numer.
BSD 3-Clause "New" or "Revised" License
457 stars 101 forks source link

Camera Scanning is not clear #4

Closed krmadhan closed 7 years ago

krmadhan commented 8 years ago

I am developing Passport Scanner app by referring PassportScanner program (https://github.com/evermeer/PassportScanner). I am testing above code on iPod 5th Gen. But I am facing problem in that, the problem is “camera to scan the MRZ code of a passport”, once it is launched is not coming clear and Pink dots are coming. How to get clear camera scanning, Do I have to change any camera parameter? Please help me to improve camera scanning.

passportscanner

evermeer commented 8 years ago

That does not look right... I have no experience with an iPod and I don't have access to any iPod. I do use a couple of hardware exelerated video filters that could be the problem could you try disabeling the hardware exelerated filters by changing the PassportScannerController.swift (you can find it in the Pod folder)

You can do that by: change videoCamera.addTarget(exposure) to videoCamera.addTarget(self.filterView) comment out the line contrast.addTarget(self.filterView)

Probably the scan won't work, but you will see the video. If that's the case, then I have to investigate if those filters can work on an iPod.

krmadhan commented 8 years ago

Thank you very much for your support. I commented this two line: contrast.addTarget(crop) crop.addTarget(averageColor)

Now it is working fine.

evermeer commented 8 years ago

That is good to hear. Those 2 lines are used to create an extra filter that will be used for dynamically setting the exposure. On an iPhone this resulted in faster and more accurate scans. You can see that around line 94 inside the colorAverageProcessingFinishedBlock. I think we can conclude that the logic for calculating the exposure is not good for an iPod. For now I think I should disable the exposure change for iPod.

Or are you able to come up with a calculation that works for iPad?

The current logic is: lighting is the sum of the colors and therefore will be between 0 (black) and 3 (white) If the color is too dark, the exposure will be increased if the color is to light, the exposure will be decreased We aim for an exposure between 2.85 and 2.91

jrodriguezq commented 8 years ago

Hello,

First of all, many thanks for this project, I'm trying to run this app on an iPhone 6s and I have run into a similar issue(see attached image).

When I replace "videoCamera.addTarget(exposure)" for "videoCamera.addTarget(self.filterView)" and comment "contrast.addTarget(self.filterView)" the camera looks normal, but it doesn't scan for MRZ(error is: could not get snapshot from camera).

Commenting "contrast.addTarget(crop)" and "crop.addTarget(averageColor)" does not remove the distortion on the camera.

Is there any way around this?

Thanks.

img_3024

evermeer commented 8 years ago

I'm close to a conversion of GpuImage2 what will solve a couple of things. I hope to be able to create a working version later today.

evermeer commented 8 years ago

@krmadhan I was able to fix the problem. It could happen that the exposure correction went out of control and went up to 100+ where 3 would already be more than enough. I have pushed the fix as version 1.0.4 to GitHub and Cocoapods.

I'm still struggling with the migration to GPUImage2. It's working again, but it's not 100% stable. I will push this to GitHub when it's stable. (Or to a new branch if that does not happen soon). The code looks a lot cleaner now it's pure Swift. I will keep you posted...

jrodriguezq commented 7 years ago

Hello, The last commit fixes the issue that I had with the camera, now it looks like this: img_3139

The OCR it's working, but I'm not able to correctly read the MRZ. As you can see, the image appears to be clear enough. The usual case of the mrz captured it's something like this:

INCHL1D41230409D26<<<<<<<<<<<< 9002063M2002064CHL17409866<2<6 CORTES<CONTRERAS<<SERGIO<JAV ll 12

This appears to be almost correct, but some numbers and blank characters usually stand in the way and I'm not able to scan the MRZ. Is there any configuration that I'm missing?

Again, many thanks for the library.

evermeer commented 7 years ago

That looks almost good. The picture should have been recognized correctly. I do notice that the image is a litle darker than i would expect. This could mean that device specific filters are needed. Was this stil taken with the iPod?

Also i have only implemented the MRZ of a passport. I think this is an id card isn't it? I have to look up the validation rules for that. I'm now on vacation. It will have to wait 2 weeks.

evermeer commented 7 years ago

To keep things clean I added a new issue for adding support of an ID card

This original issue 'scanning not clear' is fixed so I will close this issue.

P.S. As mentioned earlier I have just added a GPUImage2 branch which looks promising but still has a small probelem.

ankushmittal87 commented 5 years ago

I am trying to scan passport from paper but everytime framework is giving me Scan quality insufficient : 0.0. I do not know where do i need to make required changes to make sample application work.

Although scanning from laptop screen is working absolutely fine. Facing problem only in scanning from original passport or passport xerox copy.

I am using GPUImage2 branch because master branch has got some compile time issues.