@@ -2461,20 +2461,59 @@ var JSONResponse = {
2461
2461
2462
2462
return detection . polygons
2463
2463
} ,
2464
+ getPolygon : function ( item ) {
2465
+ if ( JSONResponse . isString ( item ) ) {
2466
+ return StringUtil . split ( item ) ;
2467
+ }
2468
+ if ( item instanceof Array ) {
2469
+ return item ;
2470
+ }
2471
+ if ( ! JSONResponse . isObject ( item ) ) {
2472
+ return null ;
2473
+ }
2474
+
2475
+ return item . polygon || item
2476
+ } ,
2464
2477
getLines : function ( detection ) {
2465
2478
if ( ! JSONResponse . isObject ( detection ) ) {
2466
2479
return null ;
2467
2480
}
2468
2481
2469
2482
return detection . lines || detection . keyLines || detection . key_lines
2470
2483
} ,
2484
+ getLine : function ( item ) {
2485
+ if ( JSONResponse . isString ( item ) ) {
2486
+ return StringUtil . split ( item ) ;
2487
+ }
2488
+ if ( item instanceof Array ) {
2489
+ return item ;
2490
+ }
2491
+ if ( ! JSONResponse . isObject ( item ) ) {
2492
+ return null ;
2493
+ }
2494
+
2495
+ return item . line || item . keyLine || item . key_line || item
2496
+ } ,
2471
2497
getPoints : function ( detection ) {
2472
2498
if ( ! JSONResponse . isObject ( detection ) ) {
2473
2499
return null ;
2474
2500
}
2475
2501
2476
2502
return detection . points || detection . keyPoints || detection . key_points
2477
2503
} ,
2504
+ getPoint : function ( item ) {
2505
+ if ( JSONResponse . isString ( item ) ) {
2506
+ return StringUtil . split ( item ) ;
2507
+ }
2508
+ if ( item instanceof Array ) {
2509
+ return item ;
2510
+ }
2511
+ if ( ! JSONResponse . isObject ( item ) ) {
2512
+ return null ;
2513
+ }
2514
+
2515
+ return item . point || item . keyPoint || item . key_point || item
2516
+ } ,
2478
2517
getBboxes : function ( detection ) {
2479
2518
if ( ! JSONResponse . isObject ( detection ) ) {
2480
2519
return null ;
@@ -2483,7 +2522,10 @@ var JSONResponse = {
2483
2522
return detection . bboxes || detection . boxes || detection . targets
2484
2523
} ,
2485
2524
getBbox : function ( item ) {
2486
- if ( item instanceof Array || JSONResponse . isString ( item ) ) {
2525
+ if ( JSONResponse . isString ( item ) ) {
2526
+ return StringUtil . split ( item ) ;
2527
+ }
2528
+ if ( item instanceof Array ) {
2487
2529
return item ;
2488
2530
}
2489
2531
if ( ! JSONResponse . isObject ( item ) ) {
@@ -2696,7 +2738,7 @@ var JSONResponse = {
2696
2738
return ;
2697
2739
}
2698
2740
2699
- var [ x , y , x2 , y2 , d ] = JSONResponse . getXYXYD ( item , width , height , xRate , yRate ) ;
2741
+ var [ x , y , x2 , y2 , d ] = JSONResponse . getXYXYD ( JSONResponse . getLine ( item ) || item , width , height , xRate , yRate ) ;
2700
2742
2701
2743
const color = JSONResponse . getColor ( item ) || JSONResponse . getColor ( detection ) || JSONResponse . getColor ( detection . bbox ) ;
2702
2744
const rgba = color == null || color . length <= 0 ? null : `rgba(${ color . join ( ',' ) } )` ;
@@ -2728,7 +2770,7 @@ var JSONResponse = {
2728
2770
return ;
2729
2771
}
2730
2772
2731
- var [ x , y , w , h , d ] = JSONResponse . getXYWHD ( item , width , height , xRate , yRate ) ;
2773
+ var [ x , y , w , h , d ] = JSONResponse . getXYWHD ( JSONResponse . getPoint ( item ) || item , width , height , xRate , yRate ) ;
2732
2774
2733
2775
const color = JSONResponse . getColor ( item ) || JSONResponse . getColor ( detection ) || JSONResponse . getColor ( detection . bbox ) ;
2734
2776
const rgba = color == null || color . length <= 0 ? null : `rgba(${ color . join ( ',' ) } )` ;
@@ -2739,7 +2781,8 @@ var JSONResponse = {
2739
2781
2740
2782
ctx . beginPath ( ) ;
2741
2783
ctx . arc ( x , y , Math . max ( 2 , height * 0.005 ) , 0 , 2 * Math . PI ) ;
2742
- if ( JSONResponse . getFill ( item ) != false ) {
2784
+ let fill = JSONResponse . getFill ( item ) ;
2785
+ if ( fill || ( fill == null && JSONResponse . getFill ( detection ) != false ) ) {
2743
2786
ctx . fill ( ) ;
2744
2787
}
2745
2788
@@ -2761,7 +2804,8 @@ var JSONResponse = {
2761
2804
return ;
2762
2805
}
2763
2806
2764
- var points = JSONResponse . getPoints ( item ) || item ;
2807
+ var polygon = JSONResponse . getPolygon ( item ) || item ;
2808
+ var points = JSONResponse . getPoints ( polygon ) || item ;
2765
2809
if ( points instanceof Array ) {
2766
2810
const color = JSONResponse . getColor ( item ) || JSONResponse . getColor ( detection ) || JSONResponse . getColor ( detection . bbox ) ;
2767
2811
if ( color != null && color . length >= 3 ) {
@@ -2777,8 +2821,8 @@ var JSONResponse = {
2777
2821
}
2778
2822
2779
2823
ctx . beginPath ( ) ;
2780
- points . forEach ( ( item , i ) => {
2781
- var [ x , y , w , h , d ] = JSONResponse . getXYWHD ( item , width , height , xRate , yRate ) ;
2824
+ points . forEach ( ( item2 , i ) => {
2825
+ var [ x , y , w , h , d ] = JSONResponse . getXYWHD ( JSONResponse . getPoint ( item2 ) || item2 , width , height , xRate , yRate ) ;
2782
2826
2783
2827
if ( i <= 0 ) {
2784
2828
ctx . moveTo ( x , y ) ;
@@ -2788,7 +2832,8 @@ var JSONResponse = {
2788
2832
} ) ;
2789
2833
ctx . closePath ( ) ;
2790
2834
ctx . stroke ( ) ;
2791
- if ( JSONResponse . getFill ( item ) ) {
2835
+ let fill = JSONResponse . getFill ( item ) ;
2836
+ if ( fill || ( fill == null && JSONResponse . getFill ( detection ) ) ) {
2792
2837
ctx . fill ( ) ;
2793
2838
}
2794
2839
}
0 commit comments