-
Notifications
You must be signed in to change notification settings - Fork 62
Boost quality of scan #65
Comments
Is this on Android? Couple of things:
What I suspect is that for your device, it doesn't have a matching high resolution capture size, only a lower resolution. This is device specific which causes slightly different results for different devices. So with that said, there isn't much that can be done about that. There is a potential solution by removing the "ratio matching" part of the captured resolution size, and effectively just getting the highest quality image possible. This can be done by changing this line to just get the largest resolution from If you find that is successfully works for you and on a few different devices, please create a PR! This would be a great addition! |
You have pointed my the right direction. This is how I have forced the camera use the highest possible resolution.
// param.setPictureSize(maxRes.width, maxRes.height); It did created another issue. With max possible resolution the camera takes too long to take the picture. The Issue is that while taking picture with flash, the flash goes out too soon and the picture is super dark. Do you know how can be extended the time for how long the flash stays on while taking a picture? |
That's rather interesting. I turn the flash off in the after the image is taken here. So I'm not sure how that could happen. You could maybe try moving that function call to after converting the captured data into an image here. As for how long the image takes to capture, that's actually why I include the Let me know if that works for you! |
I have played with the captureQuality while forcing the camera take the highest resolution picture and it seams not to have any effect on the speed of capturing the picture, interestingly enough the picture seams brighter when taken with flash. All my test since beginning I was performing on Android using Asus Zenphone. Today I dis some test with Samsung S6, this device doesn't have any of issues mentioned above. So I'm going with the result than Asus Zenphone doesn't have a good camera. Perhaps good to mention then forcing the highest camera resolution and camputeQuality is down to 0.1 the picture is still brilliant. I'm thinking about making a function to force the highest resolution on press of a button. But I have never written app in java and not sure about the procedure I should follow. Any recommendation on that? |
Hmm that's interesting. The first phone I tested this on was an LG G3 (good to know it works on a 6 year old phone!) and noticed the camera preview was really dark. The final photo was fine though so it could be related to the phone's hardware. It might not be a bad idea to just default to highest resolution? If you wanted to take a crack at it, I find the best way to develop (and honestly, I'm not sure if there is another decent way to do this) is just to make the changes in your So basically, fork this repository. Then make the changes in the node_modules, which will then show up in your app you are developing, then copy the code over to the forked repository. I've really wanted to add tests and stuff for this but I haven't found a decent sample project showing how to do that. |
Thank you for the advice. My friend has tested for me the app on Samsung S10E (Android10). The detection seams to be way off. By his description he did not manage to detect the notebook on the table at all. Do you have any idea? I have been trying to find the rectangle detection algorithm but I didn't find it and if I did it din't recognize it. Can you point in the file where the rectangle is detected so I can try find out how is detected and find out what happened when it was tested on S10E. |
Whoah that is quite far off. I wonder if this has something to do with the different resolution/ratio sizes. I have some functions to assist with that but like I said, forcing the highest resolution might have some unintended side affects. Check out detectRectangleInFrame. It takes an image, finds the edges, and finds the rectangle from those edges. It should at least find something close. I don't know why you are getting those results unless that resolution/ratio change you made is causing that issue. You could check the rotation of the image as well. For some reason, the preview image output might be rotated incorrectly (I have a function at the bottom of that file that is meant to fix that as well). |
The whole thing has been done with out forcing the max resolution. I have been using fresh install with no changes in the Java files. We have run some more test and find the potential problem. [Wed Aug 12 2020 10:43:25.905] LOG Window dimensions: {"fontScale": 1, "height": 673.3333333333334, "scale": 3, "width": 360} this is what is send to onDeviceSetup: We have tried and force height to 1 in preview size, which stretched the view over whole screen (see the zip file). Note that the object is more of a square than rectangle. It reams that the aspect ratio of the S10E is not matching up with preview size returned by the rectangle-scanner. The same logs from my phone: Do You have any thoughts? Line 275 in 07c0678
and Line 365 in d36f6fe
But could not see anything obvious. |
Yeah that would be a result from trying to find a matching screen and preview ratio. The reason I have those Take a look at the Quadrilateral.java file. It is responsible for converting the rectangle detection to match the ratio and resolution of the captured image. (crops the captured image to the same ratio, then scales the rectangle to match the resolution). Otherwise, what I suspect might be happening here is that the height and width percents are styled on the component rather than on a view that includes the detected rectangle component. Here is the code I use in my production app, maybe this will help: const previewSize = this.getPreviewSize();
let rectangleOverlay = null;
if (!this.state.loadingCamera && !this.state.processingImage) {
rectangleOverlay = (
<RectangleOverlay
detectedRectangle={this.state.detectedRectangle}
previewRatio={previewSize}
onDetectedCapture={this.capture}
allowDetection
/>
);
}
return (
<View style={{ backgroundColor: 'rgba(0, 0, 0, 0)', position: 'relative', marginTop: previewSize.marginTop, marginLeft: previewSize.marginLeft, height: `${previewSize.height * 100}%`, width: `${previewSize.width * 100}%` }}>
<Scanner
onPictureTaken={this.onPictureTaken}
onPictureProcessed={this.onPictureProcessed}
onErrorProcessingImage={this.onErrorProcessingImage}
enableTorch={this.state.flashEnabled}
filterId={this.state.filterId}
ref={this.camera}
capturedQuality={0.7}
onRectangleDetected={({ detectedRectangle }) => this.setState({ detectedRectangle })}
onDeviceSetup={this.onDeviceSetup}
onTorchChanged={({ enabled }) => this.setState({ flashEnabled: enabled })}
style={{ flex: 1 }}
/>
{rectangleOverlay}
<FlashAnimation overlayFlashOpacity={this.state.overlayFlashOpacity} />
{this.renderCameraOverlay()}
</View>
); And the getPreviewSize function for reference getPreviewSize() {
const dimensions = Dimensions.get('window');
const heightMargin = (1 - this.state.device.previewHeightPercent) * dimensions.height / 2;
const widthMargin = (1 - this.state.device.previewWidthPercent) * dimensions.width / 2;
if (dimensions.height > dimensions.width) {
// Portrait
return {
height: this.state.device.previewHeightPercent,
width: this.state.device.previewWidthPercent,
marginTop: heightMargin,
marginLeft: widthMargin,
};
}
// Landscape
return {
width: this.state.device.previewHeightPercent,
height: this.state.device.previewWidthPercent,
marginTop: widthMargin,
marginLeft: heightMargin,
};
} |
Hi mate. The rectangle is on right spot now, I missed previewRatio={previewSize} in RectangleOverlay. Still having Issues with the preview size. It seams that S10E gives incorrect height of the screen in hardware request. If I use the same dimensions as S10E has, your code work great an I can see that the basic height is different. I'm doing some test and will keep you updated on that one. |
Hmm interesting. Are the Unfortunately I don't have a great solution for that iOS problem. This is one instance that the Android simulator really shines. I originally tried to swap out the camera feed for an image but the APIs are all so different that it just didn't work very well. I'm definitely open to a PR on this one as it would make developing for iOS waaaay easier. |
yes, the real S10E gives the "height": 673.3333333333334 and emulator with the same dimensions gives "height": 712 and from there everything is affected. |
What is the maximum picture Quality possible? with capturedQuality set to 1 I do have issue reading scanned documents. Quality of a picture taken just with my phone camera is higher that the quality from the scanner. Can I boost the scanner picture quality?
The text was updated successfully, but these errors were encountered: