@@ -2284,11 +2284,29 @@ var JSONResponse = {
2284
2284
2285
2285
var x = bbox . x || bbox . x0 || bbox . x1 || bbox . startX || bbox . xStart || bbox . leftTopX || bbox . topLeftX || bbox . start_x || bbox . x_start || bbox . left_top_x || bbox . top_left_x || 0 ;
2286
2286
var y = bbox . y || bbox . y0 || bbox . y1 || bbox . startY || bbox . yStart || bbox . leftTopY || bbox . topLeftY || bbox . start_y || bbox . y_start || bbox . left_top_y || bbox . top_left_y || 0 ;
2287
- var w = bbox . w || bbox . width || ( ( bbox . x2 || bbox . x1 || bbox . rbx || bbox . brx || bbox . endX || bbox . xEnd || bbox . rightBottomX || bbox . bottomRightX || bbox . end_x || bbox . x_end || bbox . right_bottom_x || bbox . bottom_right_x || 0 ) - x ) ;
2288
- var h = bbox . h || bbox . height || ( ( bbox . y2 || bbox . y1 || bbox . rby || bbox . bry || bbox . endY || bbox . yEnd || bbox . rightBottomY || bbox . bottomRightY || bbox . end_y || bbox . y_end || bbox . right_bottom_y || bbox . bottom_right_y || 0 ) - y ) ;
2287
+ var w = bbox . width || bbox . w || ( ( bbox . x2 || bbox . x1 || bbox . rbx || bbox . brx || bbox . endX || bbox . xEnd || bbox . rightBottomX || bbox . bottomRightX || bbox . end_x || bbox . x_end || bbox . right_bottom_x || bbox . bottom_right_x || 0 ) - x ) ;
2288
+ var h = bbox . height || bbox . h || ( ( bbox . y2 || bbox . y1 || bbox . rby || bbox . bry || bbox . endY || bbox . yEnd || bbox . rightBottomY || bbox . bottomRightY || bbox . end_y || bbox . y_end || bbox . right_bottom_y || bbox . bottom_right_y || 0 ) - y ) ;
2289
2289
var d = bbox . degree || bbox . angle || bbox . rotate || bbox . perspective || bbox . d || bbox . r || bbox . p || bbox . a ;
2290
2290
return [ + ( x || 0 ) , + ( y || 0 ) , + ( w || 0 ) , + ( h || 0 ) , + ( d || 0 ) ] ;
2291
2291
} ,
2292
+ getXYXYD : function ( bbox ) {
2293
+ if ( bbox == null ) {
2294
+ return null ;
2295
+ }
2296
+ if ( JSONResponse . isString ( bbox ) ) {
2297
+ bbox = StringUtil . split ( bbox , ',' , true ) ;
2298
+ }
2299
+ if ( bbox instanceof Array ) {
2300
+ return [ + ( bbox [ 0 ] || 0 ) , + ( bbox [ 1 ] || 0 ) , + ( bbox [ 2 ] || 0 ) , + ( bbox [ 3 ] || 0 ) , + ( bbox [ 4 ] || 0 ) ] ;
2301
+ }
2302
+
2303
+ var x = bbox . x || bbox . x0 || bbox . x1 || bbox . startX || bbox . xStart || bbox . leftTopX || bbox . topLeftX || bbox . start_x || bbox . x_start || bbox . left_top_x || bbox . top_left_x || 0 ;
2304
+ var y = bbox . y || bbox . y0 || bbox . y1 || bbox . startY || bbox . yStart || bbox . leftTopY || bbox . topLeftY || bbox . start_y || bbox . y_start || bbox . left_top_y || bbox . top_left_y || 0 ;
2305
+ var x2 = bbox . x2 || bbox . x1 || bbox . rbx || bbox . brx || bbox . endX || bbox . xEnd || bbox . rightBottomX || bbox . bottomRightX || bbox . end_x || bbox . x_end || bbox . right_bottom_x || bbox . bottom_right_x || ( ( bbox . width || bbox . w || 0 ) + x ) ;
2306
+ var y2 = bbox . y2 || bbox . y1 || bbox . rby || bbox . bry || bbox . endY || bbox . yEnd || bbox . rightBottomY || bbox . bottomRightY || bbox . end_y || bbox . y_end || bbox . right_bottom_y || bbox . bottom_right_y || ( ( bbox . height || bbox . h || 0 ) + y ) ;
2307
+ var d = bbox . degree || bbox . angle || bbox . rotate || bbox . perspective || bbox . d || bbox . r || bbox . p || bbox . a ;
2308
+ return [ + ( x || 0 ) , + ( y || 0 ) , + ( x2 || 0 ) , + ( y2 || 0 ) , + ( d || 0 ) ] ;
2309
+ } ,
2292
2310
/**
2293
2311
* 计算两个 bbox([x, y, w, h, r])的 IoU
2294
2312
*/
@@ -2528,7 +2546,7 @@ var JSONResponse = {
2528
2546
}
2529
2547
2530
2548
const [ r , g , b , a ] = color || [ 0 , 255 , 0 , 255 ] ;
2531
- const rgba = `rgba(${ r } , ${ g } , ${ b } , ${ hoverBoxId != null || ! isHovered ? 0.3 : Math . min ( 0.5 , a < 1 ? a : a / 255 ) } )` ;
2549
+ const rgba = `rgba(${ r } , ${ g } , ${ b } , ${ hoverBoxId != null && ! isHovered ? 0.3 : Math . min ( 0.5 , a < 1 ? a : a / 255 ) } )` ;
2532
2550
2533
2551
const reversedRgba = `rgba(${ 255 - r } , ${ 255 - g } , ${ 255 - b } , ${ isHovered || hoverBoxId == null ? 1 : 0.3 } )` ;
2534
2552
// const luma = 0.299 * r + 0.587 * g + 0.114 * b;
@@ -2553,8 +2571,16 @@ var JSONResponse = {
2553
2571
return
2554
2572
}
2555
2573
2574
+ is_before = item [ '@before' ] ;
2575
+ mark = '' ;
2576
+ if ( markable && is_before != true ) {
2577
+ const isWrong = wrongs . indexOf ( isDiff ? item [ '@index' ] : index ) >= 0 ; // item.correct === false;
2578
+ // 绘制 √ 和 ×
2579
+ mark = isWrong ? '× ' : '✓ ' ;
2580
+ }
2581
+
2556
2582
// Label
2557
- const label = ( isDiff ? ( item [ '@before' ] ? '- ' : '+ ' ) : '' ) + `${ item . ocr || item . label || '' } -${ item . id || '' } ${ ( ( JSONResponse . getScore ( item ) || 0 ) * 100 ) . toFixed ( 0 ) } %${ angle == 0 ? '' : ' ' + Math . round ( angle ) + '°' } ` ;
2583
+ const label = mark + ( isDiff ? ( is_before ? '- ' : '+ ' ) : '' ) + `${ item . ocr || item . label || '' } -${ item . id || '' } ${ ( ( JSONResponse . getScore ( item ) || 0 ) * 100 ) . toFixed ( 0 ) } %${ angle == 0 ? '' : ' ' + Math . round ( angle ) + '°' } ` ;
2558
2584
// ctx.font = 'bold 36px';
2559
2585
// const size = ctx.measureText(label);
2560
2586
// const textHeight = size.height || height*0.1; // Math.max(height*0.1, size.height);
@@ -2606,17 +2632,6 @@ var JSONResponse = {
2606
2632
ctx . fillText ( label , labelX , labelY ) ;
2607
2633
ctx . restore ( ) ;
2608
2634
2609
- if ( markable && item [ '@before' ] != true ) {
2610
- const isWrong = wrongs . indexOf ( isDiff ? item [ '@index' ] : index ) >= 0 ; // item.correct === false;
2611
- // 绘制 √ 和 ×
2612
- ctx . font = `bold ${ fontSize } px sans-serif` ;
2613
- // ctx.fillStyle = isWrong ? 'red' : 'green';
2614
- ctx . fillStyle = isWrong ? 'red' : 'green' ;
2615
- const checkX = labelX + textWidth + 4 ;
2616
- const checkY = labelY ;
2617
- ctx . fillText ( isWrong ? '×' : '√' , checkX , checkY ) ;
2618
- }
2619
-
2620
2635
JSONResponse . drawDetections ( canvas , item , options , img , ctx ) ;
2621
2636
} ) ;
2622
2637
}
@@ -2629,12 +2644,12 @@ var JSONResponse = {
2629
2644
return ;
2630
2645
}
2631
2646
2632
- var [ x , y , w , h , d ] = JSONResponse . getXYWHD ( item ) ;
2633
- const isRate = Math . abs ( x ) < 1 && Math . abs ( y ) < 1 && Math . abs ( w ) < 1 && Math . abs ( h ) < 1 ;
2647
+ var [ x , y , x2 , y2 , d ] = JSONResponse . getXYXYD ( item ) ;
2648
+ const isRate = Math . abs ( x ) < 1 && Math . abs ( y ) < 1 && Math . abs ( x2 ) < 1 && Math . abs ( y2 ) < 1 ;
2634
2649
x = isRate ? x * width : x * xRate ;
2635
2650
y = isRate ? y * height : y * yRate ;
2636
- w = isRate ? w * width : w * xRate ;
2637
- h = isRate ? h * height : h * yRate ;
2651
+ x2 = isRate ? x2 * width : x2 * xRate ;
2652
+ y2 = isRate ? y2 * height : y2 * yRate ;
2638
2653
2639
2654
const color = item . color || detection . color || detection . bbox ?. color ;
2640
2655
const rgba = color == null || color . length <= 0 ? null : `rgba(${ color . join ( ',' ) } )` ;
@@ -2645,7 +2660,7 @@ var JSONResponse = {
2645
2660
2646
2661
ctx . beginPath ( ) ;
2647
2662
ctx . moveTo ( x , y ) ;
2648
- ctx . lineTo ( x + w , y + h ) ;
2663
+ ctx . lineTo ( x2 , y2 ) ;
2649
2664
ctx . stroke ( ) ;
2650
2665
2651
2666
if ( isRoot ) {
0 commit comments