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

boundingBox transformation #13

Closed
saddy001 opened this issue Apr 23, 2019 · 4 comments · Fixed by #17
Closed

boundingBox transformation #13

saddy001 opened this issue Apr 23, 2019 · 4 comments · Fixed by #17
Labels
question Further information is requested

Comments

@saddy001
Copy link
Contributor

Hey, at first thanks for this useful package.
Currently I'm drawing bounding boxes around text in the live preview (examples/main_live.dart) with CustomPainter. However, when using the ocrElement.boundingBox left, top, right and bottom properties, the box appears displaced and not directly around the recognized words.
So I guess the coordinates must be scaled or shifted somehow.

For top and bottom, there seems to be a constant scaling factor that fixes the issue (e.g. ocrElement.boundingBox.top * 0.96). For left and right, this is not the case: If the detected text is on the left hand side of the image, the box appears too far right and if it's on the right hand side, the box is too far left.

I had a look at the new ScannerOverlayShape in example/main.dart, but there is much scaling going on. Could you explain how the X and Y coordinates must be transformed to display the boxes at the right location?

@jaumard
Copy link
Collaborator

jaumard commented Apr 23, 2019

Hey @saddy001 did you check https://github.com/bparrishMines/mlkit_demo ? it does draw boxes on detected text already, might help you :)

@Kleak Kleak added the question Further information is requested label Apr 24, 2019
@saddy001
Copy link
Contributor Author

saddy001 commented Apr 24, 2019

Yes, they use the following scaling:

final double scaleX = widgetSize.width / imageSize.width;
final double scaleY = widgetSize.height / imageSize.height;

return Rect.fromLTRB(
    rect.left.toDouble() * scaleX,
    rect.top.toDouble() * scaleY,
    rect.right.toDouble() * scaleX,
    rect.bottom.toDouble() * scaleY,
);

I also tried to scale it this way, with the widgetSize being the size parameter of the paint(Canvas canvas, Size size) function in CustomPainter, and imageSize being the CameraMlVision.size.width and height attributes. The bbox is still displaced. Here is the result:

a b
Screenshot_20190424-175428 Screenshot_20190424-175250
:-------------------------: :-------------------------:
Screenshot_20190424-175230 Screenshot_20190424-175205
:-------------------------: :-------------------------:
Screenshot_20190424-175043

@saddy001
Copy link
Contributor Author

saddy001 commented Apr 27, 2019

I got it. I was using CameraMlVision.size, where I should have used _cameraController.value.previewSize.

However, the CameraMlVisionState._cameraController property is private in flutter_camera_ml_vision.dart. Could you please find a way to make it accessible from outside packages or at least define a get-method for previewSize?

@saddy001
Copy link
Contributor Author

Thanks!

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

Successfully merging a pull request may close this issue.

3 participants