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

Use GPUImage to enhance scanned documents #49

Closed
julianschiavo opened this issue Aug 1, 2018 · 19 comments
Closed

Use GPUImage to enhance scanned documents #49

julianschiavo opened this issue Aug 1, 2018 · 19 comments
Labels
enhancement New feature or request

Comments

@julianschiavo
Copy link
Contributor

julianschiavo commented Aug 1, 2018

I think we could use GPUImage(2)'s AdaptiveThresholding to enhance the scanned image (It would be optional).

Example:
Example of Adaptive Thresholding

@Boris-Em Boris-Em added the enhancement New feature or request label Aug 1, 2018
@Boris-Em
Copy link
Contributor

Boris-Em commented Aug 1, 2018

I think that we want to limit the use of third party libraries. Could we look into implementing this feature using Apple's APIs?

@julianschiavo
Copy link
Contributor Author

I believe it requires OpenCV or other frameworks, but i'll look into it.

@julianschiavo
Copy link
Contributor Author

julianschiavo commented Aug 2, 2018

Update on this after I made a test implementation:

  1. Adaptive thresholding requires OpenCV or GPUImage from what I can tell.
  2. Adaptive thresholding can sometimes make the image worse, and should be optional
  3. Adaptive thresholding might make sense as a hidden property passed to the host app, as it probably results in better OCR. On the other hand, the host app could just do it themselves.

@oferRounds
Copy link

oferRounds commented Aug 21, 2018

@Boris-Em GPUImage is a great high-quality library, which is well tested. In my opinion we shouldn’t be too picky in using third-parties like this one

@jcampbell05
Copy link
Contributor

In theory this could be done in Metal :)

@saormart
Copy link

@justjs, any update on this ? This will be added to the framework / and also in the example?
Thanks!

@oferRounds
Copy link

@jcampbell05 GPUImage 3 already uses Metal

@saormart
Copy link

saormart commented Nov 8, 2018

Well I was able to make it by using Adaptive thresholding with OpenCV2. (that works for me so far)

@julianschiavo
Copy link
Contributor Author

I've started work on a Pull Request that implements this, likely with GPUImage.

A few things:

  • GPUImage3 does use metal, but it's barely done yet and is still missing a lot of functionality. As per the docs, however, we should be able to replace GPUImage2 with GPUImage3 relatively easily when it's time.
  • I'm aware that 3rd party libraries can be an issue, but I do think GPUImage2 is a highly tested, reliable library that would greatly improve WeScan

I'll update this issue later if/when I get the basic functionality working.

@jcampbell05
Copy link
Contributor

Perhaps it may just be enougth for WeScan to have hooks for users to extend for their own need. i.e allow user's to run their own preprocessing code for the image generation via a delegate callback. WeScan keeps 3rd party dependencies out of it's code but users can utilize GPU Image as needed to enhance what is shown in the cropping screen.

Could open door for other things like extending the scanning functionality by allowing access to each frame from the buffer (if say someone wanted user to scan QR Codes)

@julianschiavo
Copy link
Contributor Author

julianschiavo commented Nov 13, 2018

🤔 While I do somewhat agree with that, I feel like getting the thresholding/enhancing right is something that most developers don't have time for, but would still be useful to most, if not all, people who implement WeScan.

Any other thoughts on this? For now I'm working on the PR as it's not too hard, we can discuss further later on if needed.

@Boris-Em
Copy link
Contributor

Thanks for picking this up @justjs.
I don't think that using GPUImage is a good solution here.
One of our values is to keep WeScan as small of a dependency as possible. GPUImage is a huge library that does way more than what we need, even for this feature.

@jcampbell05, this is a better solution, but it would probably add quite a bit of complexity to the project both for us and our users. If we could avoid it, that'd be great!

Could we take a look at implementing this feature ourselves? It doesn't seem like it would be a lot of work.

@jcampbell05
Copy link
Contributor

@jcampbell05, this is a better solution, but it would probably add quite a bit of complexity to the project both for us and our users. If we could avoid it, that'd be great!

Good point.

Do we have a list of what they do ? is it just a basic curve adjustment (like you would do in photoshop) ?

@julianschiavo
Copy link
Contributor Author

Fair enough @Boris-Em. I've basically finished the GPUImage2 version as a quick proof of concept (it's on justJS:WeScan develop branch), so at least we can see what it looks like for now.

I'll see what I can do on the other implementations.

@julianschiavo
Copy link
Contributor Author

If anyone wants to play around with it as a demo, I've got adaptive thresholding working with GPUImage2. Make sure to run git submodule update --init.https://github.com/justJS/WeScan/tree/develop

@julianschiavo
Copy link
Contributor Author

Very happy to announce that I managed to get it working (way quicker than I expected) without GPUImage2! #80

@jcampbell05
Copy link
Contributor

Lets close this :)

@julianschiavo
Copy link
Contributor Author

Closed as added in #80

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

No branches or pull requests

5 participants