Skip to content

Commit 9488d2f

Browse files
committed
CVAuto:存取标记对错的框,光标上框及关键点和连线等高亮、其它框只显示半透明框,优化 UI 和代码
1 parent 9cef38b commit 9488d2f

File tree

3 files changed

+78
-43
lines changed

3 files changed

+78
-43
lines changed

APIJSON-Java-Server/APIJSONBoot-MultiDataSource/src/main/resources/static/cv/apijson/JSONResponse.js

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2462,7 +2462,7 @@ var JSONResponse = {
24622462
return item.bbox || item.box || item
24632463
},
24642464
getScore: function (item) {
2465-
return item.score || item.probability || item.possibility || item.feasibility || item.eventuality || item.odds || item.prob || item.possib || item.feasib || item.eventual;
2465+
return item.score || item.confidence || item.probability || item.possibility || item.feasibility || item.eventuality || item.odds || item.conf || item.prob || item.possib || item.feasib || item.eventual;
24662466
},
24672467

24682468
drawDetections: function(canvas, detection, options, img, ctx) {
@@ -2485,11 +2485,11 @@ var JSONResponse = {
24852485
ctx.textBaseline = 'top';
24862486

24872487
const placedLabels = [];
2488-
const rotateBoxes = options.rotateBoxes || false;
2489-
const rotateText = options.rotateText || false;
2490-
const showLabelBackground = options.labelBackground || false;
2491-
const hoverBoxId = options.hoverBoxId || null;
2492-
const visiblePaths = options.visiblePaths || null;
2488+
const rotateBoxes = options.rotateBoxes;
2489+
const rotateText = options.rotateText;
2490+
const showLabelBackground = options.labelBackground;
2491+
const hoverBoxId = options.hoverBoxId;
2492+
const visiblePaths = options.visiblePaths;
24932493
const stage = options.stage;
24942494
const isDiff = stage === 'diff';
24952495
const markable = options.markable || stage !== 'before';
@@ -2504,7 +2504,7 @@ var JSONResponse = {
25042504
// Draw bboxes
25052505
var bboxes = JSONResponse.getBboxes(detection) || []
25062506
bboxes?.forEach((item, index) => {
2507-
const isHovered = item.id === hoverBoxId;
2507+
const isHovered = index === hoverBoxId;
25082508
const visible = ! visiblePaths || visiblePaths.length <= 0 || visiblePaths.includes(item.path || item.id);
25092509
if (! visible) {
25102510
return;
@@ -2527,9 +2527,9 @@ var JSONResponse = {
25272527
}
25282528

25292529
const [r, g, b, a] = color || [0, 255, 0, 255];
2530-
const rgba = `rgba(${r}, ${g}, ${b}, ${Math.min(0.5, a / 255)})`;
2530+
const rgba = `rgba(${r}, ${g}, ${b}, ${hoverBoxId != null || ! isHovered ? 0.3 : Math.min(0.5, a < 1 ? a : a / 255)})`;
25312531

2532-
const reversedRgba = `rgba(${255 - r}, ${255 - g}, ${255 - b}`; // , 0.2`; // ${1 - a/255})`;
2532+
const reversedRgba = `rgba(${255 - r}, ${255 - g}, ${255 - b}`, ${isHovered || hoverBoxId == null ? 1 : 0.3})`;
25332533
// const luma = 0.299 * r + 0.587 * g + 0.114 * b;
25342534
const backgroundFill = rgba; // 还是有些看不清 luma > 186 ? 'rgba(0, 0, 0, 0.5)' : 'rgba(255, 255, 255, 0.5)';
25352535
@@ -2548,6 +2548,10 @@ var JSONResponse = {
25482548
ctx.restore();
25492549
}
25502550
2551+
if (hoverBoxId != null && ! isHovered) {
2552+
return
2553+
}
2554+
25512555
// Label
25522556
const label = (isDiff ? (item['@before'] ? '- ' : '+ ') : '') + `${item.ocr || item.label || ''}-${item.id || ''} ${((JSONResponse.getScore(item) || 0)*100).toFixed(0)}%${angle == 0 ? '' : ' ' + Math.round(angle) + '°'}`;
25532557
// ctx.font = 'bold 36px';
@@ -2618,7 +2622,11 @@ var JSONResponse = {
26182622
// Draw lines
26192623
var lines = JSONResponse.getLines(detection);
26202624
if (lines instanceof Array) {
2621-
lines?.forEach((item) => {
2625+
lines?.forEach((item, index) => {
2626+
if (isRoot && hoverBoxId != null && index != hoverBoxId) {
2627+
return;
2628+
}
2629+
26222630
var [x, y, w, h, d] = JSONResponse.getXYWHD(item);
26232631
const isRate = Math.abs(x) < 1 && Math.abs(y) < 1 && Math.abs(w) < 1 && Math.abs(h) < 1;
26242632
x = isRate ? x*width : x*xRate;
@@ -2651,7 +2659,11 @@ var JSONResponse = {
26512659
// Draw points
26522660
var points = JSONResponse.getPoints(detection);
26532661
if (points instanceof Array) {
2654-
points?.forEach((item) => {
2662+
points?.forEach((item, index) => {
2663+
if (isRoot && hoverBoxId != null && index != hoverBoxId) {
2664+
return;
2665+
}
2666+
26552667
var [x, y, w, h, d] = JSONResponse.getXYWHD(item);
26562668
const isRate = Math.abs(x) < 1 && Math.abs(y) < 1 && Math.abs(w) < 1 && Math.abs(h) < 1;
26572669
x = isRate ? x*width : x*xRate;
@@ -2681,10 +2693,19 @@ var JSONResponse = {
26812693
// Draw polygons
26822694
var polygons = JSONResponse.getPolygons(detection);
26832695
if (polygons instanceof Array) {
2684-
polygons.forEach((item, i) => {
2696+
polygons.forEach((item, index) => {
2697+
if (isRoot && hoverBoxId != null && index != hoverBoxId) {
2698+
return;
2699+
}
2700+
26852701
var points = JSONResponse.getPoints(item) || item;
26862702
if (points instanceof Array) {
26872703
const color = item.color || detection.color || detection.bbox?.color;
2704+
if (color != null && color.length >= 3) {
2705+
var alpha = color[3] || 0.5;
2706+
color[3] = alpha <= 1 ? alpha : alpha/255;
2707+
}
2708+
26882709
const rgba = color == null || color.length < 3 ? null : `rgba(${color.join(',')})`;
26892710
if (rgba != null) {
26902711
ctx.fillStyle = rgba;

APIJSON-Java-Server/APIJSONBoot-MultiDataSource/src/main/resources/static/cv/index.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -494,15 +494,15 @@
494494
</div>
495495

496496
<div id="vAllContainer" v-show="isRandomListShow || isRandomSubListShow" style="width: 100%; margin-top: 40px; position: absolute; background-color: rgba(255, 255, 255, 0.5); display: flex; flex-direction: column;" @click="detection.isShowNum = ! detection.isShowNum">
497-
<div id="vAllAfterTitle" style="padding: 0; position: absolute; width: 100%; height: 25px;" >
497+
<div id="vAllAfterTitle" style="background-color: rgba(255, 255, 255, 0.5); padding: 0; position: absolute; width: 100%; height: 25px;" >
498498
<a style="font-size: small; font-weight: bold; color: black">本次: </a>
499499
<a style="font-size: small; margin-left: -6px">{{ detection.isShowNum ? '正确(图' + detection.afterImgCorrect + ' 框' + detection.afterAllCorrect + ') 误报(图' + detection.afterImgWrong + ' 框' + detection.afterAllWrong + ') 漏检(图' + detection.afterImgMiss + ' 框' + detection.afterAllMiss + ')' : '召回(图' + detection.afterImgRecallStr + ' 框' + detection.afterAllRecallStr + ')% 精确(图' + detection.afterImgPrecisionStr + ' 框' + detection.afterAllPrecisionStr + ')% F1(图' + detection.afterImgF1Str + ' 框' + detection.afterAllF1Str + ')%' }} </a>
500500
</div>
501-
<div id="vAllDiffTitle" style="padding: 0; position: absolute; width: 100%; height: 25px; margin-top: 25px" >
501+
<div id="vAllDiffTitle" style="background-color: rgba(255, 255, 255, 0.5); padding: 0; position: absolute; width: 100%; height: 25px; margin-top: 25px" >
502502
<a style="font-size: small; font-weight: bold; color: black">差异: </a>
503503
<a style="font-size: small; margin-left: -6px">{{ detection.isShowNum ? '正确(图' + detection.diffImgCorrectStr + ' 框' + detection.diffAllCorrectStr + ') 误报(图' + detection.diffImgWrongStr + ' 框' + detection.diffAllWrongStr + ') 漏检(图' + detection.diffImgMissStr + ' 框' + detection.diffAllMissStr + ')' : '召回(图' + detection.diffImgRecallStr + ' 框' + detection.diffAllRecallStr + ')% 精确(图' + detection.diffImgPrecisionStr + ' 框' + detection.diffAllPrecisionStr + ')% F1(图' + detection.diffImgF1Str + ' 框' + detection.diffAllF1Str + ')%' }} </a>
504504
</div>
505-
<div id="vAllBeforeTitle" style="padding: 0; position: absolute; width: 100%; height: 25px; margin-top: 50px" >
505+
<div id="vAllBeforeTitle" style="background-color: rgba(255, 255, 255, 0.5); padding: 0; position: absolute; width: 100%; height: 25px; margin-top: 50px" >
506506
<a style="font-size: small; font-weight: bold; color: black">之前: </a>
507507
<a style="font-size: small; margin-left: -6px">{{ detection.isShowNum ? '正确(图' + detection.beforeImgCorrect + ' 框' + detection.beforeAllCorrect + ') 误报(图' + detection.beforeImgWrong + ' 框' + detection.beforeAllWrong + ') 漏检(图' + detection.beforeImgMiss + ' 框' + detection.beforeAllMiss + ')' : '召回(图' + detection.beforeImgRecallStr + ' 框' + detection.beforeAllRecallStr + ')% 精确(图' + detection.beforeImgPrecisionStr + ' 框' + detection.beforeAllPrecisionStr + ')% F1(图' + detection.beforeImgF1Str + ' 框' + detection.beforeAllF1Str + ')%' }} </a>
508508
</div>
@@ -511,7 +511,7 @@
511511
<input id="vRandomKeyPath" v-show="isRandomListShow || isRandomSubListShow" v-model="((currentRemoteItem || {}).Document || {}).path" style="width: 100%; text-align: center; margin-top: 115px; background-color: rgba(255, 255, 255, 0.5); border: #DDD 1px solid; border-radius: 2px" @keyup="doOnKeyUp(event, 'randomKeyPath', false, {'path': vRandomKeyPath.value})" placeholder="image: 图片的 JSON key 路径,以 / 分隔,转义特殊字符 / 等" />
512512

513513
<!-- 临时生成的配置子项 -->
514-
<ul v-show="isRandomSubListShow" class="historys" style="width: 100%;height: 100%; background-color: transparent; overflow: hidden;overflow-y: scroll; padding-bottom: 150px">
514+
<ul v-show="isRandomSubListShow" class="historys" style="width: 100%;height: 100%; background-color: transparent; overflow: hidden;overflow-y: scroll; padding-bottom: 215px">
515515
<li style="width: 100%; background-color: white; " v-for="(item, index) in randomSubs" :id="'randomSubItem' + index" >
516516
<img id="vRandomSubImg" :src="(item.Random || {}).img || 'img/add_light.png'" style="height: 90px; min-width: 90px" @click="onClickAddRandom(currentRandomIndex, index)">
517517

@@ -542,7 +542,7 @@
542542
</div>
543543

544544
<!-- 持久化存储的配置项 -->
545-
<ul v-show="isRandomListShow" class="historys" style="width: 100%;height: 100%; background-color: transparent;overflow: hidden;overflow-y: scroll;padding-bottom: 150px">
545+
<ul v-show="isRandomListShow" class="historys" style="width: 100%;height: 100%; background-color: transparent;overflow: hidden;overflow-y: scroll;padding-bottom: 215px">
546546
<li style="width: 100%; display: inline-flex; background-color: rgba(255, 255, 255, 0.5)" v-for="(item, index) in randoms" :id="'randomItem' + index" >
547547
<img id="vRandomImg" :src="(item.Random || {}).img || 'img/add_light.png'" style="height: 90px; min-width: 90px; background-color: rgba(255, 255, 255, 0.5); position: relative" @click="onClickAddRandom(index)" @load="var target = $event.target || {}; (item.Random || {}).width = target.naturalWidth; (item.Random || {}).height = target.naturalHeight">
548548

0 commit comments

Comments
 (0)