@@ -2462,7 +2462,7 @@ var JSONResponse = {
2462
2462
return item . bbox || item . box || item
2463
2463
} ,
2464
2464
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 ;
2466
2466
} ,
2467
2467
2468
2468
drawDetections : function ( canvas , detection , options , img , ctx ) {
@@ -2485,11 +2485,11 @@ var JSONResponse = {
2485
2485
ctx . textBaseline = 'top' ;
2486
2486
2487
2487
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 ;
2493
2493
const stage = options . stage ;
2494
2494
const isDiff = stage === 'diff' ;
2495
2495
const markable = options . markable || stage !== 'before' ;
@@ -2504,7 +2504,7 @@ var JSONResponse = {
2504
2504
// Draw bboxes
2505
2505
var bboxes = JSONResponse . getBboxes ( detection ) || [ ]
2506
2506
bboxes ?. forEach ( ( item , index ) => {
2507
- const isHovered = item . id === hoverBoxId ;
2507
+ const isHovered = index === hoverBoxId ;
2508
2508
const visible = ! visiblePaths || visiblePaths . length <= 0 || visiblePaths . includes ( item . path || item . id ) ;
2509
2509
if ( ! visible ) {
2510
2510
return ;
@@ -2527,9 +2527,9 @@ var JSONResponse = {
2527
2527
}
2528
2528
2529
2529
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 ) } )` ;
2531
2531
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 } ) `;
2533
2533
// const luma = 0.299 * r + 0.587 * g + 0.114 * b;
2534
2534
const backgroundFill = rgba; // 还是有些看不清 luma > 186 ? 'rgba(0, 0, 0, 0.5)' : 'rgba(255, 255, 255, 0.5)';
2535
2535
@@ -2548,6 +2548,10 @@ var JSONResponse = {
2548
2548
ctx.restore();
2549
2549
}
2550
2550
2551
+ if (hoverBoxId != null && ! isHovered) {
2552
+ return
2553
+ }
2554
+
2551
2555
// Label
2552
2556
const label = (isDiff ? (item['@before'] ? '- ' : '+ ') : '') + ` $ { item . ocr || item . label || '' } - $ { item . id || '' } ${( ( JSONResponse . getScore ( item ) || 0 ) * 100 ) . toFixed ( 0 ) } % $ { angle == 0 ? '' : ' ' + Math . round ( angle ) + '°' } `;
2553
2557
// ctx.font = 'bold 36px';
@@ -2618,7 +2622,11 @@ var JSONResponse = {
2618
2622
// Draw lines
2619
2623
var lines = JSONResponse . getLines ( detection ) ;
2620
2624
if ( lines instanceof Array ) {
2621
- lines ?. forEach ( ( item ) => {
2625
+ lines ?. forEach ( ( item , index ) => {
2626
+ if ( isRoot && hoverBoxId != null && index != hoverBoxId ) {
2627
+ return ;
2628
+ }
2629
+
2622
2630
var [ x , y , w , h , d ] = JSONResponse . getXYWHD ( item ) ;
2623
2631
const isRate = Math . abs ( x ) < 1 && Math . abs ( y ) < 1 && Math . abs ( w ) < 1 && Math . abs ( h ) < 1 ;
2624
2632
x = isRate ? x * width : x * xRate ;
@@ -2651,7 +2659,11 @@ var JSONResponse = {
2651
2659
// Draw points
2652
2660
var points = JSONResponse . getPoints ( detection ) ;
2653
2661
if ( points instanceof Array ) {
2654
- points ?. forEach ( ( item ) => {
2662
+ points ?. forEach ( ( item , index ) => {
2663
+ if ( isRoot && hoverBoxId != null && index != hoverBoxId ) {
2664
+ return ;
2665
+ }
2666
+
2655
2667
var [ x , y , w , h , d ] = JSONResponse . getXYWHD ( item ) ;
2656
2668
const isRate = Math . abs ( x ) < 1 && Math . abs ( y ) < 1 && Math . abs ( w ) < 1 && Math . abs ( h ) < 1 ;
2657
2669
x = isRate ? x * width : x * xRate ;
@@ -2681,10 +2693,19 @@ var JSONResponse = {
2681
2693
// Draw polygons
2682
2694
var polygons = JSONResponse . getPolygons ( detection ) ;
2683
2695
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
+
2685
2701
var points = JSONResponse . getPoints ( item ) || item ;
2686
2702
if ( points instanceof Array ) {
2687
2703
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
+
2688
2709
const rgba = color == null || color . length < 3 ? null : `rgba(${ color . join ( ',' ) } )` ;
2689
2710
if ( rgba != null ) {
2690
2711
ctx . fillStyle = rgba ;
0 commit comments