tony-xlh / react-native-document-scanner

React Native Document Scanner using Vision Camera
17 stars 2 forks source link

Normalized image displaying incorrectly in result view #1

Closed robcabardo closed 1 year ago

robcabardo commented 1 year ago

The normalized image displayed in the result view page does not match the detected document captured from the scanner. Any advice how to resolve? I'm running on an android 12 device.

xulihang commented 1 year ago

How is it different from the detected document in the scanner page? Could you show me some screenshots?

robcabardo commented 1 year ago

Screenshot_2022-12-01-20-52-27-53_78cced8be8f3f5405c7dc272a6cadc03

Screenshot_2022-12-01-20-35-58-74_78cced8be8f3f5405c7dc272a6cadc03

xulihang commented 1 year ago

I see. The image taken by the vision camera is rotated. It is strange that it does not happen on my device.

xulihang commented 1 year ago

Is the image rotated at this stage where there are two buttons below?

image

robcabardo commented 1 year ago

Yes that's correct.

xulihang commented 1 year ago

It is rotated? Could you share a screenshot?

If it is rotated, I will try to fix this by checking the image's orientation and rotating it if needed.

robcabardo commented 1 year ago

https://user-images.githubusercontent.com/105320775/205198123-a4273131-2113-4347-9b28-1447af3060e1.mp4

xulihang commented 1 year ago

Thanks for the video. By the way, what is your device model?

robcabardo commented 1 year ago

OnePlus 8, model: IN2017

xulihang commented 1 year ago

Could you paste the photo info in the metro's log here?

You can find a log like this:

{"height": 2610, "isRawPhoto": false, "metadata": {"Orientation": 0, "{Exif}": {"ApertureValue": 2, "BrightnessValue": 0, "ColorSpace": 1, "DateTimeDigitized": "2022:12:02 10:40:34", "DateTimeOriginal": "2022:12:02 10:40:34", "ExifVersion": "0220", "ExposureBiasValue": 0, "ExposureMode": 0, "ExposureProgram": 0, "ExposureTime": 0.04, "FNumber": 2, "Flash": 16, "FocalLenIn35mmFilm": 0, "FocalLength": 4.26, "ISOSpeedRatings": [Array], "LensMake": null, "LensModel": null, "LensSpecification": [Array], "MeteringMode": 0, "OffsetTime": null, "OffsetTimeDigitized": null, "OffsetTimeOriginal": null, "PixelXDimension": 4640, "PixelYDimension": 2610, "SceneType": 1, "SensingMethod": 0, "ShutterSpeedValue": 4.643, "SubjectArea": [Array], "SubsecTimeDigitized": "305421", "SubsecTimeOriginal": "305421", "WhiteBalance": 0}, "{TIFF}": {"DateTime": "2022:12:02 10:40:34", "Make": "OnePlus", "Model": "ONEPLUS A3010", "ResolutionUnit": 2, "Software": "OnePlus3-user 9 PKQ1.181203.001 1906222331 release-keys", "XResolution": 72, "YResolution": 72}}, "path": "/data/user/0/com.documentscanner/cache/mrousavy4993141523157599810.jpg", "width": 4640}

robcabardo commented 1 year ago

{"height": 2250, "isRawPhoto": false, "metadata": {"Orientation": 6, "{Exif}": {"ApertureValue": 1.61, "BrightnessValue": -1.97, "ColorSpace": 1, "DateTimeDigitized": "2022:12:01 22:05:34", "DateTimeOriginal": "2022:12:01 22:05:34", "ExifVersion": "0220", "ExposureBiasValue": 0, "ExposureMode": 0, "ExposureProgram": 2, "ExposureTime": 0.04, "FNumber": 1.75, "Flash": 16, "FocalLenIn35mmFilm": 0, "FocalLength": 4.745, "ISOSpeedRatings": [Array], "LensMake": null, "LensModel": null, "LensSpecification": [Array], "MeteringMode": 2, "OffsetTime": null, "OffsetTimeDigitized": null, "OffsetTimeOriginal": null, "PixelXDimension": 4000, "PixelYDimension": 2250, "SceneType": 1, "SensingMethod": 0, "ShutterSpeedValue": 4.643, "SubjectArea": [Array], "SubsecTimeDigitized": "000890", "SubsecTimeOriginal": "000890", "WhiteBalance": 0}, "{TIFF}": {"DateTime": "2022:12:01 22:05:34", "Make": "OnePlus", "Model": "IN2017", "ResolutionUnit": 2, "Software": null, "XResolution": 72, "YResolution": 72}}, "path": "/data/user/0/com.documentscanner/cache/mrousavy7583408544107601380.jpg", "width": 4000}

xulihang commented 1 year ago

I will try to update the plugin and the project to solve this problem.

xulihang commented 1 year ago

I've added checking of the orientation. If the image is rotated by 90 degrees (the orientation is 6), then rotate it. Please try again if it works.

https://github.com/tony-xlh/react-native-document-scanner/commit/54dda80c8b1d6ceddad95ec1b4f914832b13aadb

robcabardo commented 1 year ago

This causes the normalizeFile function to return an Error: The quadrilateral is invalid

xulihang commented 1 year ago

I see. I will update the demo to get the quadrilateral from the photo taken instead of the camera preview frames. It is a bit hard for me to test it as I don't have a device to reproduce the problem.

xulihang commented 1 year ago

I've updated the demo. You could try again.

robcabardo commented 1 year ago

It's working now as expected. Thanks!