Skip to content

Commit

Permalink
Fixed TrackerMIL one frame late (#7399)
Browse files Browse the repository at this point in the history
  • Loading branch information
klakhov authored Jan 26, 2024
1 parent 34bc61e commit ed9439b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
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

0 comments on commit ed9439b

Please sign in to comment.