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

Fixed opencv runtime initialization #7101

Merged
merged 5 commits into from
Nov 6, 2023
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### Fixed

- OpenCV runtime initialization
(<https://github.com/opencv/cvat/pull/7101>)
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,8 @@ class OpenCVControlComponent extends React.PureComponent<Props & DispatchToProps
} else if (libraryInitialized !== openCVWrapper.isInitialized) {
this.setState({
libraryInitialized: openCVWrapper.isInitialized,
trackers: Object.values(openCVWrapper.tracking),
activeTracker: Object.values(openCVWrapper.tracking)[0] || null,
});
}
}}
Expand Down
14 changes: 10 additions & 4 deletions cvat-ui/src/utils/opencv-wrapper/opencv-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//
// SPDX-License-Identifier: MIT

import waitFor from 'utils/wait-for';
import HistogramEqualizationImplementation, { HistogramEqualization } from './histogram-equalization';
import TrackerMImplementation from './tracker-mil';
import IntelligentScissorsImplementation, { IntelligentScissors } from './intelligent-scissors';
Expand Down Expand Up @@ -94,14 +95,19 @@ export class OpenCVWrapper {
}
}

let runtimeInitialized = false;
(window as any).Module = {
onRuntimeInitialized: () => {
runtimeInitialized = true;
delete (window as any).Module;
},
};
// Inject opencv to DOM
// eslint-disable-next-line @typescript-eslint/no-implied-eval
const OpenCVConstructor = new Function(decodedScript);
OpenCVConstructor();

const global = window as any;

this.cv = global.cv;
this.cv = (window as any).cv;
await waitFor(2, () => runtimeInitialized);
}

public async initialize(onProgress: (percent: number) => void): Promise<void> {
Expand Down
Loading