mirror of
https://github.com/ZoneMinder/zoneminder.git
synced 2026-11-30 04:04:03 -05:00
fix: training editor drops detection results for a frame that is no longer shown refs #6819
This commit is contained in:
1 parent
b529a752b3
commit
9abb63fa27
2 files changed
+59
No files matched your search
@@ -0,0 +1,56 @@
|
||||
'use strict';
|
||||
|
||||
// Detection results were applied to whatever frame was showing when the
|
||||
// reply arrived. Moving to the next frame during a slow detect put the
|
||||
// previous frame's boxes on the new frame, marked dirty and ready to save.
|
||||
|
||||
const assert = require('assert');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const vm = require('vm');
|
||||
|
||||
const src = fs.readFileSync(process.env.TRAINING_JS ||
|
||||
path.join(__dirname, '../../web/skins/classic/views/js/training.js'), 'utf8');
|
||||
const match = src.match(/AnnotationEditor\.prototype\.detect = function\(\) \{[\s\S]*?\n\};\n/);
|
||||
assert.ok(match, 'detect not found in training.js');
|
||||
|
||||
let reply = null;
|
||||
const $j = () => ({prop() {}});
|
||||
$j.ajax = () => {
|
||||
const p = {
|
||||
done(cb) {
|
||||
reply = cb; return p;
|
||||
},
|
||||
fail() {
|
||||
return p;
|
||||
},
|
||||
};
|
||||
return p;
|
||||
};
|
||||
const sandbox = {$j, thisUrl: '?', logAjaxFail() {}, AnnotationEditor: function() {}};
|
||||
vm.createContext(sandbox);
|
||||
vm.runInContext(match[0], sandbox);
|
||||
|
||||
function editorOn(frame) {
|
||||
const e = Object.create(sandbox.AnnotationEditor.prototype);
|
||||
Object.assign(e, {
|
||||
hasDetectScript: true, currentFrameId: frame, eventId: 1, monitorId: 2,
|
||||
annotations: [], dirty: false, translations: {},
|
||||
_setStatus() {}, _pushUndo() {}, _updateSidebar() {}, _render() {},
|
||||
});
|
||||
return e;
|
||||
}
|
||||
const found = {result: 'Ok', response: {detections: [{label: 'person', confidence: 0.9, bbox: [1, 2, 3, 4]}]}};
|
||||
|
||||
let editor = editorOn('5');
|
||||
editor.detect();
|
||||
editor.currentFrameId = '6';
|
||||
reply(found);
|
||||
assert.strictEqual(editor.annotations.length, 0, 'frame 5 detections are not put on frame 6');
|
||||
assert.strictEqual(editor.dirty, false, 'and frame 6 is not marked dirty');
|
||||
|
||||
editor = editorOn('5');
|
||||
editor.detect();
|
||||
reply(found);
|
||||
assert.strictEqual(editor.annotations.length, 1, 'detections still land on the frame they were run on');
|
||||
console.log('ok - detect results stay with their frame');
|
||||
@@ -1201,6 +1201,8 @@ AnnotationEditor.prototype.detect = function() {
|
||||
);
|
||||
|
||||
$j('#annotationDetectBtn').prop('disabled', true);
|
||||
// Detection can be slow; the user may move to another frame meanwhile.
|
||||
const fid = this.currentFrameId;
|
||||
|
||||
$j.ajax({
|
||||
url: thisUrl + '?request=training&action=detect',
|
||||
@@ -1213,6 +1215,7 @@ AnnotationEditor.prototype.detect = function() {
|
||||
dataType: 'json'
|
||||
}).done(function(data) {
|
||||
$j('#annotationDetectBtn').prop('disabled', false);
|
||||
if (self.currentFrameId !== fid) return;
|
||||
|
||||
if (data.result === 'Error') {
|
||||
self._setStatus(data.message, 'error');
|
||||
|
||||
Reference in new issue
Block a user