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 TrackerMIL one frame late #7399

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

- OpenCV tracker MIL works one frame behind
(<https://github.com/opencv/cvat/pull/7399>)
2 changes: 1 addition & 1 deletion cvat-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cvat-ui",
"version": "1.61.2",
"version": "1.61.3",
"description": "CVAT single-page application",
"main": "src/index.tsx",
"scripts": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import withVisibilityHandling from './handle-popover-visibility';
interface Props {
labels: any[];
canvasInstance: Canvas;
canvasReady: boolean;
jobInstance: any;
isActivated: boolean;
states: any[];
Expand Down Expand Up @@ -85,6 +86,7 @@ interface State {
trackedShapes: TrackedShape[];
activeTracker: OpenCVTracker | null;
trackers: OpenCVTracker[];
lastTrackedFrame: number | null;
}

const core = getCore();
Expand All @@ -98,7 +100,7 @@ function mapStateToProps(state: CombinedState): Props {
zLayer: { cur: curZOrder },
},
job: { instance: jobInstance, labels },
canvas: { activeControl, instance: canvasInstance },
canvas: { activeControl, instance: canvasInstance, ready: canvasReady },
player: {
frame: { number: frame, data: frameData },
},
Expand All @@ -113,6 +115,7 @@ function mapStateToProps(state: CombinedState): Props {
isActivated: activeControl === ActiveControl.OPENCV_TOOLS,
activeControl,
canvasInstance: canvasInstance as Canvas,
canvasReady,
defaultApproxPolyAccuracy,
jobInstance,
curZOrder,
Expand Down Expand Up @@ -157,6 +160,7 @@ class OpenCVControlComponent extends React.PureComponent<Props & DispatchToProps
trackedShapes: [],
trackers: openCVWrapper.isInitialized ? Object.values(openCVWrapper.tracking) : [],
activeTracker: openCVWrapper.isInitialized ? Object.values(openCVWrapper.tracking)[0] : null,
lastTrackedFrame: null,
};
}

Expand All @@ -168,7 +172,7 @@ class OpenCVControlComponent extends React.PureComponent<Props & DispatchToProps
public componentDidUpdate(prevProps: Props, prevState: State): void {
const { approxPolyAccuracy } = this.state;
const {
isActivated, defaultApproxPolyAccuracy, canvasInstance, toolsBlockerState,
isActivated, defaultApproxPolyAccuracy, canvasInstance, canvasReady, toolsBlockerState,
} = this.props;

if (!prevProps.isActivated && isActivated) {
Expand Down Expand Up @@ -202,7 +206,8 @@ class OpenCVControlComponent extends React.PureComponent<Props & DispatchToProps
!!this.activeTool?.switchBlockMode) {
this.activeTool.switchBlockMode(toolsBlockerState.algorithmsLocked);
}
this.checkTrackedStates(prevProps);

if (canvasReady) this.checkTrackedStates();
}

public componentWillUnmount(): void {
Expand Down Expand Up @@ -419,15 +424,19 @@ class OpenCVControlComponent extends React.PureComponent<Props & DispatchToProps
});
};

private checkTrackedStates(prevProps: Props): void {
private checkTrackedStates(): void {
const {
frame,
states: objectStates,
fetchAnnotations,
switchNavigationBlocked,
} = this.props;
const { trackedShapes } = this.state;
if (prevProps.frame !== frame && trackedShapes.length) {
const { trackedShapes, lastTrackedFrame } = this.state;
if (lastTrackedFrame !== frame && trackedShapes.length) {
this.setState({
lastTrackedFrame: frame,
});

type AccumulatorType = {
[index: string]: TrackedShape[];
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,10 @@ context('OpenCV. Intelligent scissors. Histogram Equalization. TrackerMIL.', ()
// On each frame text is moved by 5px on x and y axis,
// so we expect shape to be close to real text positions
cy.get('#cvat_canvas_shape_3').invoke('attr', 'x').then((xVal) => {
expect(parseFloat(xVal)).to.be.closeTo(x + (i - 1) * 5, 2.0);
expect(parseFloat(xVal)).to.be.closeTo(x + (i - 1) * 5, 3.0);
});
cy.get('#cvat_canvas_shape_3').invoke('attr', 'y').then((yVal) => {
expect(parseFloat(yVal)).to.be.closeTo(y + (i - 1) * 5, 2.0);
expect(parseFloat(yVal)).to.be.closeTo(y + (i - 1) * 5, 3.0);
});
cy.get('#cvat-objects-sidebar-state-item-3')
.should('contain', 'RECTANGLE TRACK')
Expand Down
Loading