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

Return box coordinates of scanned codes #52

Open
dustin-graham opened this issue Dec 12, 2021 · 12 comments
Open

Return box coordinates of scanned codes #52

dustin-graham opened this issue Dec 12, 2021 · 12 comments

Comments

@dustin-graham
Copy link
Collaborator

Hello,
I'm very pleased with this plugin. One thing that is missing for us is the ability to paint boxes around the scanned codes from the camera. I know MLKit reports the coordinates of the scanned codes, would it be possible to report coordinates along with the barcode values?

Thank you!

@jhoogstraat
Copy link
Owner

Hi, glad you like the plugin!

That is totally something I will implement into 2.0!
Just please bear with my, as I won't have time to work in the plugin until next year, as I am in my critical phase of my masters thesis right now.

In fact if you are proficient in flutter, Swift or Kotlin, I will gladly accept any pull request on the develop branch (will will become 2.0) :)

@dustin-graham
Copy link
Collaborator Author

dustin-graham commented Dec 12, 2021 via email

@dustin-graham
Copy link
Collaborator Author

@jhoogstraat , I'm working on this feature right now. I have one initial question as I look at this code. Is there a specific reason why the plugin only sends the first code it scans?

@SuppressLint("UnsafeOptInUsageError")
    private fun initialize(configuration: HashMap<String, Any>): Task<PreviewConfiguration> {
        if (this.camera != null)
            throw ScannerException.AlreadyInitialized()

        val pluginBinding = this.pluginBinding ?: throw ScannerException.ActivityNotConnected()
        val activityBinding = this.activityBinding ?: throw ScannerException.ActivityNotConnected()

        val camera = Camera(
            activityBinding.activity,
            pluginBinding.textureRegistry.createSurfaceTexture(),
            configuration
        ) { barcodes ->

            // *** Question: should we return all the codes? *****
            detectionEventSink?.success(encode(barcodes.first()))

        }

        this.camera = camera

        activityBinding.addRequestPermissionsResultListener(camera)

        return camera.requestPermissions()
            .continueWithTask { camera.loadCamera() }
    }

In my use case, my drivers scan a packing label that may have multiple codes on it. The native functionality is to return a list of all visible codes. Would it be ok to just pass them all through?

@jhoogstraat
Copy link
Owner

Yeah definitely. My use case just only required scanning one code at a time.
It even does on the develop branch:

@dustin-graham
Copy link
Collaborator Author

@jhoogstraat , I'm continuing work today on this. I'm looking at the event channel messages we are sending between native and dart. Since I'm adding in coordinates and also passing through all the barcodes instead of just the first in the list, I'd like to move to something like Pigeon to make the platform communication easier. https://pub.dev/packages/pigeon. Any objections to this?

@jhoogstraat
Copy link
Owner

I never worked with Pigeon. Does using it mean to rewrite the whole communication part between native and flutter?
I tried to keep the implementation as lean as possible for now, but I see that something like Pigeon does have benefits. If you think Pigeon is worth the effort, I support the idea.

@dustin-graham
Copy link
Collaborator Author

dustin-graham commented Jan 6, 2022

@jhoogstraat , thanks for the feedback. Pigeon is new to me, but I've been looking into it. But yes, Pigeon would replace the current communication layer with generated code. It looks to be a fairly large lift, so for now I'm going to first get box coordinates working for the single barcode with the communication layer as-is and then I'll probably open up a separate issue for supporting multiple barcodes at once. Pigeon makes more sense when supporting multiple codes I think.

I'm almost done with drawing the boxes around the barcode. It took a little bit of thinking to make sure the coordinate translation is correct.
Screen Shot 2022-01-05 at 5 42 17 PM

I'm going to be adding a CodeBoundaryOverlay to the library which will do the drawing. I'm going to provide an API that will allow the user to specify the Paint. My use case includes a requirement to print the code value along with the box. I'm going to try and find a nice API so that users can add their own additions to the box.

Do you have any additional requests or suggestions for customization?

@dustin-graham
Copy link
Collaborator Author

@jhoogstraat , I was thinking that I need to account for different camera orientations. The orientation system can often be confusing to me, so I apologize if I misunderstand, but it appears that the current code assumes portrait orientation? That seems to be how the native camera code is configured and he sample is locked into portrait. Is landscape orientation supposed to be supported for scanning? I'd actually be completely comfortable if we just support portrait orientation. That is the most conducive to effective scanning UI I think. But please let me know if I'm mistaken.

@jhoogstraat
Copy link
Owner

jhoogstraat commented Jan 6, 2022

Yeah, good idea to put Pigeon into another issue.
Also the CodeBoundaryOverlay is a very cool use of the overlay mechanism!
Allowing the user to provide a Paint should allow the user to completely configure the border, no?

One notion: You only need two coordinates (diagonals) to fully describe the rectangle. I dont know any code type that is not rectangular or square.

I have to ask: Do you base your changes onto the main or the develop branch?
Cause I changed the camera quite a bit.

Orientation and resolution are the hardest thing about cameras and viewfinders. I am okay with portrait only.

@dustin-graham
Copy link
Collaborator Author

dustin-graham commented Jan 6, 2022

@jhoogstraat , I'm based on develop right now.

With regard to coordinates, I'm sending all 4 corners to provide a nice, neat fit. The codes are square, but if your camera is pointed at the code at an angle, the square code is skewed in the 2D image. sending all 4 corners allows us to match the camera skew.

Screenshot_20220106-163317_Photos

This is especially nice when the camera is rotated slightly. If you just draw the box it creates an upright box that circumscribes all the corners. This looks better:

Screenshot_20220106-163543

@jhoogstraat
Copy link
Owner

You are right, totally missed that!
That looks really really good, I am looking forward to your pr!

@dustin-graham
Copy link
Collaborator Author

@jhoogstraat PR is up.

jhoogstraat pushed a commit that referenced this issue Feb 11, 2022
* Android code coordinate implementation

* ios code coordinate implementation

* cleanup

* resolve analysis warnings

* fix method channel test

* fix formatting of PreviewConfiguration.kt

* remove analysis string in message channel

* clean up kotlin code style

* make overlay configurable

* improve class naming

* move coordinate conversion to swift plugin

* make PreviewView not static

* improve file and class naming
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

No branches or pull requests

2 participants