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

CAPI-233: optimise demo gif #12

Merged
merged 4 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [1.5.1] - 11-06-2024

- (chore): load demo gif asynchronously before init is called
- (chore): reduce demo gif size
- (fix): race condition when environment loads its own opencv

## [1.5.0] - 05-06-2024

- (feat): pre-process image for quality check using opencv before resolving `init` promise
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"author": "Anyline",
"name": "@anyline/anyline-guidance-sdk",
"version": "1.5.0",
"version": "1.5.1",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"types": "dist/esm/index.d.ts",
Expand Down
8 changes: 8 additions & 0 deletions src/camera/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ import { type Config } from '../modules/ConfigManager';
import OpenCVManager from '../modules/OpenCVManager';
import DocumentScrollController from '../modules/DocumentScrollController';

// load demoInstructionsImage chunk before it is requested
// to ensure lower loading time for the gif when sdk is initialised
void import(
'../screens/onboardingInstructions/instructionsBody/demoInstructionsImage'
).catch(() => {
console.log('Error loading demo gif');
});

export interface ImageMetadata {
width: number;
height: number;
Expand Down
19 changes: 11 additions & 8 deletions src/modules/ImageChecker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,17 @@ export default class ImageChecker {

public async isImageQualityGood(): Promise<boolean> {
if (this.blob === null) throw new Error('No image to process');
const { isBlurDetected, isContrastLow, isEdgeDetected } =
await preProcessImage(this.blob);

return (
!(isBlurDetected ?? false) &&
(isEdgeDetected ?? false) &&
!(isContrastLow ?? false)
);
try {
const { isBlurDetected, isContrastLow, isEdgeDetected } =
await preProcessImage(this.blob);
return (
!(isBlurDetected ?? false) &&
(isEdgeDetected ?? false) &&
!(isContrastLow ?? false)
);
} catch (err) {
return true;
}
}

public destroy(): void {
Expand Down
5 changes: 1 addition & 4 deletions src/modules/OpenCVManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ export default class OpenCVManager {
}

public loadOpenCV(): void {
if (
Boolean((window as any).cv?.getBuildInformation()) &&
this.opencvLoadedResolve !== null
) {
if (Boolean((window as any)?.cv) && this.opencvLoadedResolve !== null) {
this.opencvLoadedResolve();
return;
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.