From d253c19deb2722b4af4138d49b6661763928a3c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=91=E8=BD=BB=E7=8B=82?= <1677568218@qq.com> Date: Mon, 26 Dec 2022 17:05:27 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=95=B0=E6=8D=AE=E6=A0=87=E6=B3=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/settings.json | 1 + app/api/annotation_data/data.json | 120 ++++++++ app/api/annotation_data/dataset.json | 145 ++++++++++ app/api/api.py | 55 +++- src/pages/Personalization/annotations.vue | 316 +++++++++++++++++++++- 5 files changed, 617 insertions(+), 20 deletions(-) create mode 100644 app/api/annotation_data/data.json create mode 100644 app/api/annotation_data/dataset.json diff --git a/.vscode/settings.json b/.vscode/settings.json index d36c539..1f087d9 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -10,6 +10,7 @@ "pnpm", "pyinstaller", "pywebview", + "supercategory", "unocss", "unplugin", "Vite", diff --git a/app/api/annotation_data/data.json b/app/api/annotation_data/data.json new file mode 100644 index 0000000..4776b17 --- /dev/null +++ b/app/api/annotation_data/data.json @@ -0,0 +1,120 @@ +{ + "2022-12-22-15-30-01.jpg": { + "image": { + "file_name": "2022-12-22-15-30-01.jpg", + "height": 480, + "width": 640 + }, + "annotation": [ + { + "area": 690, + "iscrowd": 0, + "bbox": [ + 357, + 268, + 46, + 15 + ], + "category_id": 3, + "ignore": 0 + }, + { + "area": 946, + "iscrowd": 0, + "bbox": [ + 453, + 260, + 43, + 22 + ], + "category_id": 3, + "ignore": 0 + }, + { + "area": 4900, + "iscrowd": 0, + "bbox": [ + 391, + 353, + 98, + 50 + ], + "category_id": 2, + "ignore": 0 + } + ] + }, + "2022-12-22-15-38-16.jpg": { + "image": { + "file_name": "2022-12-22-15-38-16.jpg", + "height": 480, + "width": 640 + }, + "annotation": [ + { + "area": 680, + "iscrowd": 0, + "bbox": [ + 211, + 356, + 40, + 17 + ], + "category_id": 3, + "ignore": 0 + }, + { + "area": 728, + "iscrowd": 0, + "bbox": [ + 289, + 347, + 52, + 14 + ], + "category_id": 3, + "ignore": 0 + } + ] + }, + "2022-12-22-15-44-48.jpg": { + "image": { + "file_name": "2022-12-22-15-44-48.jpg", + "height": 480, + "width": 640 + }, + "annotation": [] + }, + "2022-12-22-15-44-49.jpg": { + "image": { + "file_name": "2022-12-22-15-44-49.jpg", + "height": 480, + "width": 640 + }, + "annotation": [] + }, + "2022-12-22-15-44-55.jpg": { + "image": { + "file_name": "2022-12-22-15-44-55.jpg", + "height": 480, + "width": 640 + }, + "annotation": [] + }, + "2022-12-26-10-03-41.jpg": { + "image": { + "file_name": "2022-12-26-10-03-41.jpg", + "height": 480, + "width": 640 + }, + "annotation": [] + }, + "2022-12-26-10-40-15.jpg": { + "image": { + "file_name": "2022-12-26-10-40-15.jpg", + "height": 480, + "width": 640 + }, + "annotation": [] + } +} \ No newline at end of file diff --git a/app/api/annotation_data/dataset.json b/app/api/annotation_data/dataset.json new file mode 100644 index 0000000..3feaad8 --- /dev/null +++ b/app/api/annotation_data/dataset.json @@ -0,0 +1,145 @@ +{ + "images": [ + { + "file_name": "2022-12-22-15-30-01.jpg", + "height": 480, + "width": 640, + "id": 0 + }, + { + "file_name": "2022-12-22-15-38-16.jpg", + "height": 480, + "width": 640, + "id": 1 + }, + { + "file_name": "2022-12-22-15-44-48.jpg", + "height": 480, + "width": 640, + "id": 2 + }, + { + "file_name": "2022-12-22-15-44-49.jpg", + "height": 480, + "width": 640, + "id": 3 + }, + { + "file_name": "2022-12-22-15-44-55.jpg", + "height": 480, + "width": 640, + "id": 4 + }, + { + "file_name": "2022-12-26-10-03-41.jpg", + "height": 480, + "width": 640, + "id": 5 + }, + { + "file_name": "2022-12-26-10-40-15.jpg", + "height": 480, + "width": 640, + "id": 6 + } + ], + "type": "instances", + "annotations": [ + { + "area": 690, + "iscrowd": 0, + "bbox": [ + 357, + 268, + 46, + 15 + ], + "category_id": 3, + "ignore": 0, + "image_id": 0, + "id": 0 + }, + { + "area": 946, + "iscrowd": 0, + "bbox": [ + 453, + 260, + 43, + 22 + ], + "category_id": 3, + "ignore": 0, + "image_id": 0, + "id": 1 + }, + { + "area": 4900, + "iscrowd": 0, + "bbox": [ + 391, + 353, + 98, + 50 + ], + "category_id": 2, + "ignore": 0, + "image_id": 0, + "id": 2 + }, + { + "area": 680, + "iscrowd": 0, + "bbox": [ + 211, + 356, + 40, + 17 + ], + "category_id": 3, + "ignore": 0, + "image_id": 1, + "id": 3 + }, + { + "area": 728, + "iscrowd": 0, + "bbox": [ + 289, + 347, + 52, + 14 + ], + "category_id": 3, + "ignore": 0, + "image_id": 1, + "id": 4 + } + ], + "categories": [ + { + "supercategory": "none", + "id": 1, + "name": "closed_eye", + "color": "#E3170D85" + }, + { + "supercategory": "none", + "id": 2, + "name": "closed_mouth", + "color": "#1E90FF85" + }, + { + "supercategory": "none", + "id": 3, + "name": "open_eye", + "color": "#32CD3285" + }, + { + "supercategory": "none", + "id": 4, + "name": "open_mouth", + "color": "#C0C0C085" + } + ] +} \ No newline at end of file diff --git a/app/api/api.py b/app/api/api.py index e7cd07c..8c58e62 100644 --- a/app/api/api.py +++ b/app/api/api.py @@ -148,7 +148,7 @@ class API: if(os.path.exists(getFile("primary_img"))==False): #不存在则创建 os.mkdir(getFile("primary_img")) - #返回该文件夹下png文件的数量和列表 + #返回该文件夹下jpg文件的数量和列表 return [len(os.listdir(getFile("primary_img"))),os.listdir(getFile("primary_img"))] def setPersonalizationPrimaryImg(self,type="不裁剪"): #判断是否存在"primary_img"文件夹 @@ -159,7 +159,7 @@ class API: # 图片名字是当前时间 # 三种处理图片的方式:不裁剪、居中裁剪成224*224、居中裁剪成320*320。 if(type=="不裁剪"): - cv2.imwrite(getFile("primary_img")+"/"+time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime())+".png",get_photo(self.cap)) + cv2.imwrite(getFile("primary_img")+"/"+time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime())+".jpg",get_photo(self.cap)) elif(type=="居中裁剪成224*224"): img = get_photo(self.cap) height=len(img) @@ -172,7 +172,7 @@ class API: x2 = x0+112 y2 = y0+112 img = img[y1:y2, x1:x2] - cv2.imwrite(getFile("primary_img")+"/"+time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime())+".png",img) + cv2.imwrite(getFile("primary_img")+"/"+time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime())+".jpg",img) elif(type=="居中裁剪成320*320"): img = get_photo(self.cap) height=len(img) @@ -185,8 +185,8 @@ class API: x2 = x0+160 y2 = y0+160 img = img[y1:y2, x1:x2] - cv2.imwrite(getFile("primary_img")+"/"+time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime())+".png",img) - #返回该文件夹下png文件的数量和列表 + cv2.imwrite(getFile("primary_img")+"/"+time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime())+".jpg",img) + #返回该文件夹下jpg文件的数量和列表 return [len(os.listdir(getFile("primary_img"))),os.listdir(getFile("primary_img"))] def openPrimaryImgFiles(self): #判断是否存在"primary_img"文件夹 @@ -194,4 +194,47 @@ class API: #不存在则创建 os.mkdir(getFile("primary_img")) #打开文件夹 - os.startfile(getFile("primary_img")) \ No newline at end of file + os.startfile(getFile("primary_img")) + def getPrimaryListImg(self,img_name): + #判断是否存在"primary_img"文件夹 + if(os.path.exists(getFile("primary_img"))==False): + #不存在则创建 + os.mkdir(getFile("primary_img")) + #读取图片 + img = cv2.imread(getFile("primary_img")+"/"+img_name) + #返回图片 + return mat2base64(img) + def saveAnnotationData(self,data,dataset): + #判断是否存在"annotation_data"文件夹 + if(os.path.exists(getFile("annotation_data"))==False): + #不存在则创建 + os.mkdir(getFile("annotation_data")) + #保存COCO数据集 + with open(getFile("annotation_data")+"/"+"dataset.json",'w',encoding='utf8')as fp: + json.dump(dataset,fp,ensure_ascii=False,indent=4) + #保存标注数据 + with open(getFile("annotation_data")+"/"+"data.json",'w',encoding='utf8')as fp: + json.dump(data,fp,ensure_ascii=False,indent=4) + def getAnnotationData(self): + #判断是否存在"annotation_data"文件夹 + if(os.path.exists(getFile("annotation_data"))==False): + #不存在则创建 + os.mkdir(getFile("annotation_data")) + #判断是否存在"dataset.json"文件 + if(os.path.exists(getFile("annotation_data")+"/"+"dataset.json")): + #存在则读取 + with open(getFile("annotation_data")+"/"+"dataset.json",'r',encoding='utf8')as fp: + dataset = json.load(fp) + else: + #不存在则创建 + return {} + #判断是否存在"data.json"文件 + if(os.path.exists(getFile("annotation_data")+"/"+"data.json")): + #存在则读取 + with open(getFile("annotation_data")+"/"+"data.json",'r',encoding='utf8')as fp: + data = json.load(fp) + else: + #不存在则创建 + return {} + #返回数据 + return {"mergeData":dataset,"annotationData":data} \ No newline at end of file diff --git a/src/pages/Personalization/annotations.vue b/src/pages/Personalization/annotations.vue index 2d9e69a..4e845d0 100644 --- a/src/pages/Personalization/annotations.vue +++ b/src/pages/Personalization/annotations.vue @@ -1,5 +1,268 @@ @@ -41,15 +304,21 @@ const { t } = useI18n() 标注类别-眼睛 - - 眼睛开 + + 眼睛开 + + + 眼睛闭 - 眼睛闭 标注类别-嘴巴 - 嘴巴开 - 嘴巴闭 + + 嘴巴开 + + + 嘴巴闭 + @@ -59,7 +328,7 @@ const { t } = useI18n() 已标记 - 200 + {{ ImgList.length }} @@ -68,32 +337,42 @@ const { t } = useI18n() 未标记 - 18 + {{ ImgList.length - Object.keys(expertData.annotationData).length }} - + + + + + + + + - + - + - + - + @@ -128,12 +407,12 @@ const { t } = useI18n() - + 云端训练 - + 本地训练 @@ -214,4 +493,13 @@ const { t } = useI18n() padding-top: .5rem; padding-bottom: .5rem; } + +.CanvasWrapper { + position: relative; + width: 100%; +} + +.CanvasWrapper canvas { + position: absolute; +}