浏览代码

Resolve "bounding box copies"

Eric Tröbs 4 年之前
父节点
当前提交
8bba48ac87

+ 2 - 0
pycs/frontend/WebServer.py

@@ -226,10 +226,12 @@ class WebServer:
                     target_object.remove_results()
                 elif 'x' not in result:
                     if result['label']:
+                        result['type'] = 'labeled-image'
                         target_object.add_global_result(result)
                     else:
                         target_object.remove_global_result()
                 else:
+                    result['type'] = 'labeled-bounding-box' if 'label' in result else 'bounding-box'
                     target_object.add_result(result)
 
             # return default success response

+ 4 - 4
pycs/projects/Project.py

@@ -42,8 +42,11 @@ class Project(ObservableDict):
             for key in obj['data'].keys():
                 obj['data'][key] = self.create_media_file(obj['data'][key])
 
+        # initialize super
+        super().__init__(obj, parent)
+
         # handle unmanaged files
-        else:
+        if obj['unmanaged'] is not None:
             prev = None
             for file in listdir(obj['unmanaged']):
                 uuid, ext = splitext(file)
@@ -67,9 +70,6 @@ class Project(ObservableDict):
             for key in self.unmanaged_files:
                 self.unmanaged_files[key].length(length)
 
-        # initialize super
-        super().__init__(obj, parent)
-
         # create data and temp
         data_path = path.join('projects', self['id'], 'data')
         if not path.exists(data_path):

+ 17 - 5
webui/src/components/media/annotated-image.vue

@@ -170,6 +170,17 @@ export default {
           this.selectedBoundingBox = this.predictions.length;
 
         this.selectedBoundingBox -= 1;
+      } else if (event.key === 'v') {
+        navigator.clipboard.readText().then(text => {
+          const obj = JSON.parse(text);
+          if (obj.type === 'bounding-box' || obj.type === 'labeled-bounding-box') {
+            if (this.data.type === 'video')
+              obj.frame = this.video.frame;
+
+            this.socket.post(this.mediaUrl, obj).then(this.update);
+            console.log('paste', obj);
+          }
+        });
       }
     },
     update: function () {
@@ -267,17 +278,18 @@ export default {
     },
     release: function () {
       if (this.start && !this.extremeClicking) {
-        if (this.callback)
+        if (this.callback) {
           this.callback(this.current);
-        else
-          this.socket.post(this.mediaUrl, this.current);
+          this.update();
+        } else {
+          this.socket.post(this.mediaUrl, this.current)
+              .then(this.update);
+        }
 
         this.start = false;
         this.fixed = false;
         this.current = false;
         this.callback = false;
-
-        this.update();
       }
     },
     move: function (event, position, callback) {

+ 11 - 0
webui/src/components/media/annotation-box.vue

@@ -134,6 +134,17 @@ export default {
         this.confirmSelf();
       else if (event.key === 'e')
         this.deleteSelf();
+      else if (event.key === 'c') {
+        const copy = {};
+        for (let key in this.position) {
+          if (key !== 'id' && key !== 'origin' && key !== 'frame') {
+            copy[key] = this.position[key];
+          }
+        }
+
+        navigator.clipboard.writeText(JSON.stringify(copy));
+        console.log('copy', copy);
+      }
     },
     confirmSelf: function () {
       this.updateSelf(this.position);