前言

在遥感目标检测中,由于DOTA数据集本身类别的样本数量是极度不均衡的;所以,使用合适的数据增强,可以在一定程度上提升模型的最终检测性能。而在之前的一篇博客中,我提到过使用随机旋转的方法进行增强,但是代码运行完毕之后最好还是需要进行可视化操作验证更为稳妥,所以便有了cv2.polylines这一函数的出现,该函数可以画任意的多边形。

正文

这里使用python版本的函数举例,可以发现该函数所需要的参数主要为

polylines(img, pts, isClosed, color, thickness=None, lineType=None, shift=None)

参数:
img(array):为ndarray类型(可以为cv.imread)直接读取的数据
pts(array):为所画多边形的顶点坐标,举个简单的例子:当一张图片需要有多个四边形时,该数组ndarray的shape应该为(N,4,2)
isClosed(bool):所画四边形是否闭合,通常为True
color(tuple):BGR三个通道的值
thickness(int):画线的粗细
shift:顶点坐标中小数的位数

接下来便是实战来观察实际的效果:
首先准备的图片为:(个人认为这张图片十分经典)

而这张图片对应的label如下:

807.0 331.0 800.0 324.0 817.0 309.0 823.0 316.0 ship 0
879.0 366.0 888.0 373.0 870.0 393.0 861.0 386.0 ship 0
862.0 384.0 855.0 377.0 873.0 356.0 882.0 363.0 ship 0
867.0 348.0 874.0 355.0 856.0 375.0 849.0 369.0 ship 0
840.0 362.0 832.0 354.0 850.0 335.0 859.0 343.0 ship 0
828.0 352.0 823.0 345.0 845.0 327.0 851.0 334.0 ship 0
823.0 344.0 817.0 335.0 839.0 317.0 847.0 326.0 ship 0
899.0 278.0 907.0 286.0 882.0 308.0 875.0 300.0 ship 0
891.0 269.0 899.0 276.0 875.0 300.0 867.0 292.0 ship 0
884.0 260.0 891.0 269.0 872.0 287.0 865.0 280.0 ship 0
876.0 253.0 884.0 260.0 862.0 283.0 855.0 276.0 ship 0
869.0 245.0 875.0 252.0 854.0 271.0 846.0 263.0 ship 0
862.0 238.0 869.0 245.0 848.0 262.0 842.0 254.0 ship 0
852.0 231.0 858.0 237.0 839.0 257.0 831.0 250.0 ship 0
816.0 337.0 809.0 329.0 835.0 306.0 841.0 314.0 ship 0
801.0 322.0 795.0 315.0 816.0 296.0 823.0 304.0 ship 0
853.0 401.0 861.0 409.0 839.0 431.0 831.0 424.0 ship 0
809.0 288.0 816.0 296.0 793.0 316.0 786.0 309.0 ship 0
385.0 595.0 394.0 604.0 367.0 634.0 357.0 624.0 ship 0
395.0 605.0 404.0 615.0 376.0 642.0 367.0 633.0 ship 0
404.0 616.0 413.0 626.0 383.0 653.0 375.0 643.0 ship 0
391.0 671.0 380.0 660.0 414.0 624.0 425.0 636.0 ship 0
423.0 637.0 431.0 644.0 404.0 678.0 395.0 669.0 ship 0
412.0 688.0 403.0 678.0 434.0 644.0 444.0 655.0 ship 0
444.0 654.0 453.0 663.0 423.0 696.0 414.0 687.0 ship 0
453.0 663.0 463.0 673.0 436.0 705.0 426.0 697.0 ship 0
441.0 717.0 432.0 707.0 460.0 677.0 470.0 687.0 ship 0
456.0 723.0 447.0 712.0 473.0 686.0 483.0 697.0 ship 0
482.0 697.0 491.0 707.0 464.0 729.0 456.0 720.0 ship 0
492.0 704.0 503.0 715.0 470.0 744.0 460.0 734.0 ship 0
503.0 715.0 513.0 724.0 481.0 754.0 472.0 743.0 ship 0
889.0 377.0 896.0 385.0 876.0 401.0 870.0 393.0 ship 0
862.0 409.0 870.0 416.0 851.0 436.0 843.0 428.0 ship 0
922.0 447.0 915.0 440.0 936.0 420.0 943.0 427.0 ship 0
952.0 330.0 959.0 337.0 938.0 357.0 930.0 350.0 ship 0
939.0 315.0 944.0 321.0 925.0 338.0 919.0 332.0 ship 0
1009.0 531.0 1002.0 524.0 1023.0 503.0 1024.0 515.0 ship 0
1000.0 524.0 992.0 516.0 1012.0 495.0 1021.0 504.0 ship 0
991.0 516.0 983.0 508.0 1003.0 489.0 1010.0 497.0 ship 0
980.0 528.0 986.0 536.0 961.0 557.0 955.0 549.0 ship 0
970.0 519.0 977.0 526.0 949.0 552.0 942.0 543.0 ship 0
976.0 501.0 969.0 493.0 989.0 474.0 996.0 482.0 ship 0
970.0 491.0 964.0 484.0 984.0 465.0 991.0 472.0 ship 0
975.0 459.0 983.0 468.0 961.0 487.0 954.0 478.0 ship 0
953.0 478.0 946.0 472.0 965.0 453.0 971.0 460.0 ship 0
948.0 469.0 941.0 462.0 962.0 437.0 971.0 445.0 ship 0
951.0 432.0 959.0 440.0 938.0 463.0 931.0 455.0 ship 0
944.0 425.0 951.0 432.0 932.0 454.0 924.0 447.0 ship 0
916.0 439.0 908.0 430.0 928.0 411.0 936.0 419.0 ship 0
854.0 451.0 846.0 443.0 869.0 417.0 878.0 426.0 ship 0
908.0 431.0 902.0 424.0 920.0 407.0 926.0 413.0 ship 0
900.0 423.0 893.0 415.0 916.0 394.0 924.0 403.0 ship 0
890.0 416.0 885.0 408.0 905.0 390.0 911.0 399.0 ship 0
885.0 407.0 879.0 400.0 895.0 384.0 902.0 391.0 ship 0
962.0 511.0 968.0 518.0 944.0 541.0 936.0 533.0 ship 0
952.0 500.0 960.0 509.0 936.0 532.0 928.0 524.0 ship 0
944.0 494.0 950.0 502.0 927.0 523.0 920.0 516.0 ship 0
936.0 486.0 943.0 492.0 924.0 512.0 916.0 505.0 ship 0
919.0 470.0 927.0 478.0 904.0 500.0 896.0 492.0 ship 0
912.0 461.0 919.0 469.0 895.0 493.0 887.0 485.0 ship 0
903.0 453.0 910.0 462.0 886.0 485.0 879.0 477.0 ship 0
896.0 443.0 905.0 451.0 883.0 471.0 875.0 463.0 ship 0
886.0 436.0 894.0 445.0 872.0 468.0 864.0 460.0 ship 0
877.0 427.0 886.0 436.0 861.0 461.0 853.0 453.0 ship 0
510.0 726.0 520.0 736.0 491.0 766.0 482.0 756.0 ship 0
523.0 734.0 532.0 744.0 506.0 772.0 497.0 762.0 ship 0
537.0 755.0 548.0 764.0 520.0 795.0 509.0 785.0 ship 0
251.0 457.0 260.0 466.0 235.0 493.0 226.0 485.0 ship 0
299.0 720.0 290.0 710.0 320.0 681.0 329.0 692.0 ship 0
287.0 713.0 277.0 704.0 309.0 671.0 320.0 681.0 ship 0
277.0 704.0 268.0 695.0 298.0 661.0 308.0 673.0 ship 0
286.0 654.0 295.0 663.0 268.0 693.0 258.0 683.0 ship 0
257.0 682.0 247.0 673.0 270.0 648.0 281.0 658.0 ship 0
251.0 671.0 241.0 663.0 267.0 633.0 278.0 641.0 ship 0
239.0 662.0 230.0 653.0 259.0 621.0 268.0 631.0 ship 0
230.0 651.0 222.0 642.0 247.0 615.0 256.0 623.0 ship 0
221.0 641.0 213.0 633.0 242.0 600.0 250.0 609.0 ship 0
210.0 632.0 202.0 626.0 217.0 606.0 225.0 613.0 ship 0
200.0 623.0 191.0 614.0 214.0 589.0 223.0 597.0 ship 0
192.0 612.0 184.0 603.0 211.0 577.0 218.0 584.0 ship 0
182.0 601.0 173.0 591.0 200.0 565.0 208.0 576.0 ship 0
219.0 484.0 210.0 474.0 235.0 452.0 244.0 463.0 ship 0
243.0 504.0 234.0 495.0 260.0 467.0 269.0 476.0 ship 0
550.0 766.0 559.0 775.0 532.0 801.0 524.0 792.0 ship 0
270.0 478.0 278.0 488.0 250.0 513.0 242.0 504.0 ship 0
259.0 525.0 249.0 515.0 280.0 487.0 289.0 497.0 ship 0
299.0 509.0 308.0 519.0 274.0 550.0 265.0 540.0 ship 0
290.0 499.0 296.0 506.0 282.0 519.0 276.0 513.0 ship 0
307.0 518.0 316.0 525.0 295.0 551.0 286.0 544.0 ship 0
327.0 534.0 337.0 545.0 304.0 578.0 293.0 567.0 ship 0
338.0 547.0 347.0 555.0 322.0 580.0 314.0 572.0 ship 0
328.0 592.0 319.0 582.0 347.0 557.0 356.0 568.0 ship 0
336.0 607.0 326.0 597.0 355.0 568.0 365.0 577.0 ship 0
366.0 577.0 375.0 587.0 349.0 613.0 340.0 603.0 ship 0
691.0 822.0 699.0 831.0 670.0 861.0 660.0 852.0 ship 0
659.0 851.0 650.0 843.0 674.0 818.0 684.0 827.0 ship 0
650.0 842.0 642.0 834.0 668.0 806.0 677.0 814.0 ship 0
641.0 833.0 632.0 823.0 660.0 795.0 670.0 803.0 ship 0
305.0 731.0 298.0 724.0 316.0 705.0 324.0 713.0 ship 0
342.0 699.0 361.0 718.0 328.0 751.0 309.0 732.0 ship 0
336.0 762.0 329.0 754.0 359.0 722.0 367.0 731.0 ship 0
356.0 781.0 347.0 771.0 374.0 742.0 384.0 751.0 ship 0
559.0 775.0 568.0 784.0 540.0 819.0 529.0 809.0 ship 0
567.0 786.0 577.0 794.0 553.0 821.0 545.0 813.0 ship 0
577.0 795.0 587.0 804.0 559.0 833.0 550.0 824.0 ship 0
584.0 807.0 593.0 817.0 569.0 842.0 559.0 832.0 ship 0
600.0 814.0 609.0 824.0 579.0 850.0 571.0 840.0 ship 0
608.0 824.0 618.0 833.0 587.0 861.0 579.0 851.0 ship 0
618.0 834.0 627.0 844.0 597.0 873.0 589.0 863.0 ship 0
629.0 845.0 637.0 854.0 609.0 881.0 600.0 871.0 ship 0
619.0 894.0 609.0 883.0 639.0 854.0 649.0 864.0 ship 0
645.0 869.0 653.0 878.0 627.0 903.0 619.0 896.0 ship 0
574.0 935.0 583.0 946.0 551.0 977.0 541.0 969.0 ship 0
560.0 927.0 571.0 938.0 541.0 970.0 530.0 959.0 ship 0
531.0 959.0 520.0 951.0 544.0 924.0 554.0 933.0 ship 0
522.0 947.0 513.0 940.0 535.0 913.0 545.0 920.0 ship 0
527.0 902.0 537.0 911.0 510.0 940.0 501.0 932.0 ship 0
500.0 928.0 492.0 919.0 517.0 892.0 526.0 900.0 ship 0
492.0 919.0 484.0 911.0 505.0 887.0 514.0 895.0 ship 0
483.0 910.0 473.0 900.0 504.0 868.0 515.0 879.0 ship 0
489.0 862.0 499.0 873.0 473.0 901.0 462.0 891.0 ship 0
462.0 891.0 453.0 882.0 479.0 852.0 490.0 861.0 ship 0
452.0 882.0 444.0 872.0 469.0 845.0 478.0 853.0 ship 0
443.0 869.0 435.0 862.0 458.0 832.0 467.0 840.0 ship 0
434.0 862.0 425.0 853.0 447.0 824.0 458.0 833.0 ship 0
445.0 808.0 455.0 816.0 425.0 850.0 414.0 841.0 ship 0
413.0 841.0 404.0 831.0 434.0 800.0 443.0 809.0 ship 0
396.0 820.0 387.0 812.0 412.0 782.0 422.0 790.0 ship 0
401.0 771.0 412.0 780.0 384.0 813.0 374.0 803.0 ship 0
375.0 801.0 366.0 792.0 392.0 763.0 402.0 773.0 ship 0
366.0 791.0 356.0 783.0 382.0 754.0 392.0 763.0 ship 0
960.0 340.0 966.0 347.0 949.0 362.0 942.0 355.0 ship 0
974.0 352.0 983.0 360.0 961.0 385.0 951.0 377.0 ship 0
989.0 370.0 996.0 377.0 979.0 394.0 972.0 387.0 ship 0
617.0 136.0 609.0 127.0 632.0 108.0 641.0 117.0 ship 0
380.0 185.0 369.0 196.0 333.0 159.0 344.0 147.0 ship 0
393.0 174.0 382.0 183.0 344.0 144.0 353.0 134.0 ship 0
355.0 135.0 360.0 128.0 378.0 145.0 371.0 152.0 ship 0
419.0 160.0 407.0 173.0 361.0 127.0 372.0 116.0 ship 0
425.0 142.0 413.0 152.0 375.0 115.0 386.0 103.0 ship 0
427.0 124.0 417.0 133.0 387.0 105.0 397.0 93.0 ship 0
444.0 116.0 434.0 127.0 398.0 94.0 408.0 82.0 ship 0
469.0 91.0 459.0 100.0 429.0 67.0 440.0 57.0 ship 0
478.0 80.0 467.0 89.0 441.0 55.0 453.0 47.0 ship 0
506.0 74.0 492.0 86.0 453.0 44.0 467.0 31.0 ship 0
510.0 52.0 500.0 63.0 467.0 31.0 478.0 20.0 ship 0
526.0 44.0 515.0 56.0 477.0 18.0 488.0 7.0 ship 0
594.0 112.0 587.0 103.0 610.0 84.0 617.0 94.0 ship 0
601.0 120.0 595.0 112.0 618.0 93.0 626.0 102.0 ship 0
626.0 146.0 618.0 139.0 637.0 119.0 645.0 128.0 ship 0
324.0 849.0 314.0 837.0 351.0 800.0 361.0 811.0 ship 0
141.0 465.0 152.0 477.0 120.0 511.0 107.0 499.0 ship 0
150.0 573.0 142.0 564.0 164.0 537.0 174.0 546.0 ship 0
183.0 536.0 194.0 545.0 162.0 585.0 151.0 575.0 ship 0
187.0 558.0 195.0 567.0 171.0 592.0 162.0 584.0 ship 0
53.0 509.0 42.0 521.0 3.0 482.0 13.0 471.0 ship 0
47.0 530.0 32.0 543.0 1.0 507.0 1.0 482.0 ship 1
29.0 541.0 18.0 552.0 0.0 534.0 1.0 510.0 ship 1
236.0 762.0 224.0 748.0 260.0 712.0 272.0 724.0 ship 0
272.0 724.0 282.0 733.0 253.0 767.0 241.0 757.0 ship 0
284.0 735.0 295.0 746.0 261.0 780.0 250.0 768.0 ship 0
295.0 746.0 305.0 756.0 272.0 793.0 261.0 783.0 ship 0
307.0 755.0 318.0 766.0 286.0 799.0 276.0 789.0 ship 0
321.0 768.0 330.0 780.0 292.0 811.0 283.0 800.0 ship 0
329.0 780.0 340.0 790.0 301.0 828.0 291.0 817.0 ship 0
369.0 196.0 359.0 208.0 319.0 169.0 331.0 157.0 ship 0
357.0 212.0 347.0 222.0 307.0 181.0 317.0 169.0 ship 0
343.0 219.0 335.0 228.0 298.0 192.0 306.0 182.0 ship 0
323.0 222.0 314.0 230.0 287.0 200.0 296.0 192.0 ship 0
478.0 214.0 488.0 202.0 908.0 628.0 895.0 640.0 harbor 0
358.0 330.0 370.0 320.0 781.0 736.0 771.0 748.0 harbor 0
241.0 447.0 253.0 435.0 663.0 856.0 652.0 866.0 harbor 0
118.0 566.0 130.0 554.0 542.0 975.0 531.0 986.0 harbor 0
117.0 630.0 107.0 618.0 140.0 588.0 150.0 599.0 ship 0
90.0 616.0 79.0 603.0 117.0 567.0 128.0 578.0 ship 0
136.0 658.0 125.0 646.0 161.0 610.0 173.0 622.0 ship 0
173.0 622.0 183.0 632.0 150.0 667.0 139.0 656.0 ship 0
156.0 683.0 144.0 671.0 183.0 633.0 196.0 646.0 ship 0
196.0 646.0 206.0 656.0 171.0 692.0 160.0 680.0 ship 0
206.0 656.0 216.0 666.0 176.0 709.0 165.0 697.0 ship 0
216.0 666.0 227.0 676.0 198.0 712.0 186.0 701.0 ship 0
227.0 678.0 238.0 689.0 206.0 728.0 194.0 716.0 ship 0
224.0 731.0 212.0 721.0 239.0 689.0 250.0 701.0 ship 0
250.0 701.0 260.0 712.0 230.0 742.0 220.0 731.0 ship 0
155.0 399.0 144.0 411.0 108.0 376.0 119.0 365.0 ship 0
163.0 383.0 154.0 394.0 121.0 365.0 131.0 354.0 ship 0
179.0 373.0 170.0 383.0 130.0 352.0 140.0 340.0 ship 0
182.0 359.0 175.0 369.0 141.0 341.0 150.0 330.0 ship 0
204.0 359.0 193.0 370.0 153.0 328.0 164.0 317.0 ship 0
223.0 347.0 211.0 359.0 169.0 321.0 180.0 309.0 ship 0
185.0 301.0 194.0 291.0 229.0 324.0 220.0 334.0 ship 0
247.0 321.0 233.0 331.0 198.0 287.0 211.0 278.0 ship 0
255.0 296.0 245.0 306.0 210.0 274.0 221.0 263.0 ship 0
264.0 282.0 256.0 291.0 225.0 260.0 233.0 251.0 ship 0
246.0 243.0 254.0 232.0 285.0 259.0 277.0 269.0 ship 0
308.0 258.0 297.0 270.0 255.0 232.0 265.0 220.0 ship 0
303.0 237.0 294.0 245.0 269.0 219.0 277.0 210.0 ship 0
312.0 228.0 304.0 237.0 277.0 210.0 285.0 201.0 ship 0
340.0 789.0 350.0 801.0 314.0 837.0 305.0 826.0 ship 0
361.0 811.0 372.0 822.0 337.0 859.0 326.0 848.0 ship 0
1004.0 384.0 1012.0 392.0 989.0 412.0 982.0 405.0 ship 0
999.0 931.0 986.0 944.0 944.0 896.0 956.0 884.0 ship 0
792.0 1017.0 783.0 1024.0 754.0 999.0 763.0 989.0 ship 0
769.0 989.0 777.0 979.0 802.0 1005.0 795.0 1013.0 ship 0
835.0 988.0 849.0 974.0 893.0 1022.0 872.0 1024.0 ship 0
782.0 1022.0 798.0 1010.0 810.0 1024.0 783.0 1024.0 ship 2
923.0 979.0 914.0 989.0 871.0 951.0 882.0 939.0 ship 0
885.0 937.0 897.0 928.0 940.0 973.0 930.0 983.0 ship 0
900.0 928.0 913.0 918.0 948.0 961.0 936.0 971.0 ship 0
964.0 950.0 952.0 961.0 912.0 917.0 924.0 906.0 ship 0
981.0 940.0 969.0 952.0 926.0 906.0 939.0 893.0 ship 0
1008.0 912.0 997.0 924.0 952.0 881.0 962.0 868.0 ship 0
372.0 822.0 383.0 833.0 349.0 870.0 339.0 860.0 ship 0
964.0 864.0 976.0 853.0 1013.0 890.0 1003.0 902.0 ship 0
1024.0 874.0 1023.0 896.0 973.0 851.0 984.0 839.0 ship 0
1024.0 847.0 1024.0 873.0 986.0 839.0 999.0 825.0 ship 2
1001.0 826.0 1012.0 814.0 1024.0 825.0 1024.0 846.0 ship 2
1024.0 409.0 1024.0 425.0 1013.0 441.0 1005.0 435.0 ship 0
1022.0 401.0 1024.0 410.0 1006.0 428.0 997.0 419.0 ship 0
807.0 938.0 814.0 930.0 836.0 953.0 828.0 960.0 ship 0
815.0 920.0 823.0 911.0 854.0 941.0 845.0 950.0 ship 0
795.0 941.0 785.0 929.0 814.0 902.0 824.0 912.0 ship 0
782.0 892.0 774.0 898.0 754.0 874.0 762.0 868.0 ship 0
384.0 833.0 394.0 844.0 359.0 880.0 350.0 870.0 ship 0
395.0 845.0 405.0 855.0 371.0 889.0 361.0 879.0 ship 0
403.0 857.0 414.0 868.0 381.0 900.0 371.0 890.0 ship 0
414.0 867.0 425.0 878.0 394.0 909.0 383.0 898.0 ship 0
403.0 927.0 392.0 914.0 426.0 881.0 436.0 894.0 ship 0
413.0 937.0 403.0 927.0 439.0 892.0 448.0 901.0 ship 0
428.0 944.0 417.0 932.0 448.0 902.0 460.0 914.0 ship 0
460.0 914.0 471.0 924.0 435.0 965.0 423.0 952.0 ship 0
449.0 970.0 439.0 960.0 471.0 925.0 482.0 936.0 ship 0
482.0 936.0 493.0 946.0 457.0 986.0 446.0 976.0 ship 0
493.0 947.0 504.0 958.0 470.0 994.0 458.0 984.0 ship 0
513.0 971.0 523.0 980.0 492.0 1014.0 481.0 1003.0 ship 0
503.0 962.0 513.0 971.0 481.0 1003.0 472.0 993.0 ship 0
502.0 1024.0 492.0 1016.0 526.0 981.0 536.0 992.0 ship 0
633.0 967.0 646.0 959.0 679.0 1004.0 668.0 1013.0 ship 0
652.0 953.0 663.0 944.0 697.0 984.0 687.0 994.0 ship 0
673.0 936.0 686.0 926.0 714.0 961.0 701.0 971.0 ship 0
782.0 925.0 772.0 915.0 800.0 886.0 810.0 896.0 ship 0
795.0 884.0 787.0 893.0 755.0 862.0 765.0 852.0 ship 0
631.0 822.0 622.0 813.0 648.0 785.0 658.0 795.0 ship 0
620.0 812.0 611.0 803.0 641.0 772.0 651.0 781.0 ship 0
611.0 802.0 603.0 794.0 631.0 764.0 639.0 773.0 ship 0
613.0 327.0 605.0 321.0 631.0 294.0 640.0 302.0 ship 0
776.0 493.0 769.0 485.0 791.0 461.0 799.0 468.0 ship 0
767.0 485.0 760.0 478.0 780.0 455.0 788.0 463.0 ship 0
760.0 478.0 753.0 470.0 772.0 449.0 779.0 456.0 ship 0
753.0 469.0 745.0 462.0 766.0 439.0 774.0 446.0 ship 0
744.0 461.0 735.0 452.0 757.0 429.0 767.0 438.0 ship 0
728.0 446.0 720.0 438.0 743.0 413.0 752.0 420.0 ship 0
718.0 435.0 712.0 429.0 736.0 405.0 742.0 412.0 ship 0
725.0 395.0 735.0 402.0 712.0 428.0 703.0 419.0 ship 0
703.0 417.0 694.0 407.0 720.0 385.0 728.0 393.0 ship 0
697.0 362.0 704.0 371.0 677.0 396.0 668.0 388.0 ship 0
663.0 379.0 654.0 370.0 677.0 343.0 687.0 353.0 ship 0
653.0 370.0 646.0 362.0 665.0 342.0 672.0 349.0 ship 0
646.0 362.0 637.0 353.0 660.0 328.0 669.0 337.0 ship 0
638.0 304.0 647.0 312.0 622.0 335.0 614.0 327.0 ship 0
620.0 290.0 628.0 297.0 604.0 319.0 597.0 312.0 ship 0
639.0 161.0 634.0 153.0 660.0 135.0 666.0 144.0 ship 0
596.0 311.0 589.0 304.0 612.0 282.0 618.0 289.0 ship 0
588.0 300.0 582.0 293.0 607.0 270.0 614.0 277.0 ship 0
600.0 261.0 607.0 268.0 582.0 292.0 576.0 285.0 ship 0
558.0 150.0 550.0 143.0 576.0 117.0 583.0 125.0 ship 0
593.0 133.0 600.0 140.0 583.0 157.0 576.0 150.0 ship 0
600.0 143.0 607.0 149.0 587.0 169.0 580.0 162.0 ship 0
631.0 176.0 640.0 185.0 617.0 210.0 609.0 202.0 ship 0
641.0 186.0 649.0 194.0 627.0 219.0 618.0 211.0 ship 0
651.0 195.0 659.0 204.0 635.0 226.0 626.0 219.0 ship 0
665.0 211.0 672.0 218.0 648.0 240.0 641.0 234.0 ship 0
673.0 218.0 681.0 227.0 658.0 249.0 649.0 241.0 ship 0
688.0 234.0 699.0 244.0 673.0 274.0 662.0 264.0 ship 0
692.0 281.0 684.0 272.0 706.0 252.0 713.0 260.0 ship 0
714.0 261.0 721.0 269.0 699.0 290.0 692.0 282.0 ship 0
799.0 471.0 807.0 479.0 785.0 503.0 777.0 494.0 ship 0
796.0 510.0 787.0 501.0 810.0 476.0 819.0 486.0 ship 0
809.0 527.0 801.0 519.0 819.0 498.0 828.0 507.0 ship 0
831.0 504.0 840.0 512.0 820.0 535.0 810.0 526.0 ship 0
662.0 403.0 671.0 413.0 644.0 440.0 635.0 431.0 ship 0
662.0 460.0 653.0 448.0 681.0 423.0 691.0 433.0 ship 0
674.0 468.0 665.0 459.0 692.0 432.0 700.0 442.0 ship 0
680.0 486.0 671.0 476.0 700.0 444.0 709.0 452.0 ship 0
711.0 453.0 720.0 462.0 695.0 487.0 686.0 477.0 ship 0
715.0 464.0 726.0 472.0 701.0 506.0 690.0 496.0 ship 0
713.0 508.0 705.0 497.0 730.0 472.0 741.0 483.0 ship 0
740.0 482.0 749.0 492.0 721.0 519.0 711.0 510.0 ship 0
749.0 491.0 759.0 502.0 730.0 531.0 720.0 521.0 ship 0
742.0 535.0 732.0 524.0 759.0 501.0 767.0 512.0 ship 0
754.0 548.0 744.0 539.0 771.0 511.0 780.0 520.0 ship 0
779.0 522.0 788.0 531.0 763.0 557.0 753.0 548.0 ship 0
768.0 571.0 759.0 559.0 789.0 531.0 799.0 542.0 ship 0
777.0 581.0 769.0 570.0 799.0 542.0 808.0 551.0 ship 0
808.0 551.0 817.0 561.0 794.0 587.0 784.0 577.0 ship 0
798.0 599.0 790.0 589.0 818.0 561.0 827.0 571.0 ship 0
827.0 571.0 837.0 581.0 803.0 612.0 794.0 601.0 ship 0
823.0 611.0 817.0 604.0 840.0 584.0 846.0 591.0 ship 0
847.0 591.0 856.0 601.0 828.0 630.0 818.0 619.0 ship 0
866.0 611.0 876.0 621.0 846.0 650.0 837.0 640.0 ship 0
876.0 621.0 885.0 631.0 857.0 658.0 849.0 649.0 ship 0
914.0 587.0 923.0 593.0 902.0 619.0 894.0 610.0 ship 0
886.0 538.0 893.0 530.0 915.0 549.0 907.0 558.0 ship 0
877.0 595.0 867.0 587.0 891.0 560.0 901.0 569.0 ship 0
867.0 586.0 859.0 578.0 882.0 550.0 892.0 559.0 ship 0
858.0 578.0 850.0 569.0 869.0 548.0 878.0 555.0 ship 0
850.0 569.0 842.0 560.0 865.0 537.0 873.0 545.0 ship 0
834.0 552.0 826.0 545.0 846.0 525.0 853.0 533.0 ship 0
826.0 544.0 818.0 537.0 840.0 511.0 850.0 520.0 ship 0
630.0 152.0 626.0 144.0 650.0 128.0 655.0 136.0 ship 0
656.0 175.0 649.0 167.0 671.0 148.0 677.0 156.0 ship 0
643.0 383.0 651.0 391.0 623.0 419.0 616.0 410.0 ship 0
232.0 908.0 244.0 920.0 211.0 954.0 201.0 943.0 ship 0
51.0 716.0 73.0 737.0 31.0 777.0 11.0 755.0 ship 0
64.0 746.0 74.0 757.0 42.0 787.0 31.0 777.0 ship 0
78.0 756.0 89.0 768.0 54.0 801.0 43.0 788.0 ship 0
99.0 777.0 109.0 787.0 75.0 821.0 65.0 810.0 ship 0
114.0 786.0 124.0 796.0 86.0 833.0 78.0 823.0 ship 0
120.0 802.0 130.0 812.0 97.0 845.0 87.0 835.0 ship 0
136.0 808.0 147.0 820.0 109.0 856.0 99.0 846.0 ship 0
118.0 864.0 111.0 858.0 131.0 837.0 138.0 844.0 ship 0
163.0 842.0 175.0 851.0 139.0 889.0 128.0 878.0 ship 0
175.0 855.0 186.0 864.0 150.0 899.0 141.0 889.0 ship 0
182.0 870.0 192.0 880.0 162.0 911.0 152.0 900.0 ship 0
191.0 882.0 199.0 891.0 172.0 922.0 161.0 913.0 ship 0
206.0 886.0 219.0 898.0 188.0 932.0 175.0 920.0 ship 0
218.0 898.0 229.0 909.0 200.0 944.0 188.0 932.0 ship 0
243.0 922.0 252.0 930.0 217.0 968.0 206.0 958.0 ship 0
663.0 183.0 656.0 175.0 678.0 157.0 685.0 165.0 ship 0
226.0 980.0 215.0 971.0 244.0 940.0 254.0 951.0 ship 0
263.0 941.0 276.0 952.0 239.0 991.0 227.0 980.0 ship 0
280.0 950.0 292.0 962.0 250.0 1003.0 239.0 992.0 ship 0
286.0 970.0 297.0 983.0 261.0 1014.0 252.0 1003.0 ship 0
304.0 997.0 312.0 1006.0 290.0 1024.0 272.0 1024.0 ship 0
742.0 115.0 748.0 120.0 724.0 146.0 717.0 139.0 ship 0
750.0 122.0 756.0 129.0 731.0 151.0 726.0 144.0 ship 0
757.0 132.0 762.0 139.0 737.0 161.0 731.0 154.0 ship 0
762.0 140.0 770.0 147.0 748.0 171.0 740.0 165.0 ship 0
673.0 192.0 665.0 186.0 679.0 168.0 687.0 174.0 ship 0
687.0 207.0 680.0 198.0 701.0 179.0 709.0 187.0 ship 0
707.0 189.0 714.0 196.0 695.0 214.0 689.0 208.0 ship 0
710.0 229.0 703.0 221.0 722.0 202.0 730.0 210.0 ship 0
733.0 210.0 741.0 217.0 717.0 239.0 710.0 231.0 ship 0
743.0 217.0 750.0 224.0 727.0 245.0 719.0 238.0 ship 0
741.0 262.0 733.0 253.0 756.0 232.0 764.0 240.0 ship 0
748.0 267.0 741.0 261.0 764.0 241.0 769.0 247.0 ship 0
754.0 277.0 747.0 270.0 770.0 247.0 778.0 256.0 ship 0
762.0 283.0 755.0 276.0 777.0 257.0 782.0 264.0 ship 0
786.0 261.0 795.0 270.0 770.0 293.0 762.0 284.0 ship 0
777.0 301.0 770.0 293.0 793.0 272.0 800.0 281.0 ship 0
787.0 307.0 781.0 299.0 800.0 282.0 806.0 291.0 ship 0
722.0 268.0 730.0 276.0 709.0 298.0 700.0 290.0 ship 0
730.0 276.0 738.0 283.0 717.0 306.0 709.0 298.0 ship 0
740.0 284.0 747.0 293.0 726.0 313.0 717.0 305.0 ship 0
748.0 294.0 755.0 301.0 735.0 320.0 729.0 312.0 ship 0
755.0 301.0 763.0 309.0 742.0 333.0 732.0 324.0 ship 0
778.0 325.0 787.0 334.0 764.0 358.0 755.0 348.0 ship 0
787.0 337.0 795.0 345.0 776.0 364.0 769.0 357.0 ship 0
795.0 345.0 802.0 351.0 783.0 373.0 775.0 367.0 ship 0
802.0 352.0 811.0 359.0 792.0 382.0 783.0 375.0 ship 0
797.0 390.0 790.0 382.0 813.0 360.0 821.0 369.0 ship 0
821.0 370.0 828.0 377.0 806.0 397.0 799.0 390.0 ship 0
829.0 377.0 838.0 386.0 813.0 408.0 805.0 398.0 ship 0
845.0 391.0 852.0 399.0 828.0 420.0 822.0 412.0 ship 0
788.0 163.0 794.0 170.0 776.0 185.0 771.0 178.0 ship 0
766.0 184.0 759.0 177.0 778.0 154.0 786.0 161.0 ship 0
771.0 147.0 778.0 153.0 756.0 178.0 749.0 171.0 ship 0
650.0 394.0 659.0 402.0 633.0 430.0 624.0 422.0 ship 0
631.0 374.0 640.0 384.0 611.0 413.0 602.0 404.0 ship 0
602.0 793.0 592.0 783.0 623.0 752.0 633.0 761.0 ship 0
573.0 548.0 581.0 556.0 556.0 583.0 549.0 576.0 ship 0
417.0 391.0 426.0 400.0 394.0 427.0 386.0 416.0 ship 0
427.0 400.0 437.0 411.0 400.0 442.0 392.0 430.0 ship 0
437.0 412.0 446.0 421.0 416.0 450.0 407.0 441.0 ship 0
424.0 465.0 414.0 455.0 446.0 420.0 458.0 431.0 ship 0
458.0 430.0 465.0 438.0 439.0 466.0 432.0 458.0 ship 0
475.0 451.0 484.0 460.0 455.0 491.0 446.0 482.0 ship 0
489.0 459.0 500.0 471.0 465.0 505.0 455.0 495.0 ship 0
507.0 478.0 515.0 487.0 487.0 516.0 478.0 507.0 ship 0
497.0 528.0 488.0 518.0 515.0 489.0 525.0 499.0 ship 0
526.0 500.0 534.0 509.0 509.0 533.0 500.0 525.0 ship 0
535.0 509.0 544.0 518.0 513.0 549.0 504.0 540.0 ship 0
545.0 521.0 553.0 531.0 523.0 559.0 515.0 549.0 ship 0
553.0 532.0 561.0 540.0 537.0 566.0 528.0 558.0 ship 0
563.0 539.0 572.0 548.0 548.0 574.0 539.0 567.0 ship 0
562.0 598.0 553.0 588.0 584.0 558.0 593.0 569.0 ship 0
748.0 726.0 757.0 734.0 725.0 768.0 717.0 758.0 ship 0
574.0 606.0 566.0 597.0 593.0 570.0 602.0 579.0 ship 0
602.0 579.0 611.0 588.0 585.0 616.0 576.0 607.0 ship 0
614.0 589.0 622.0 595.0 608.0 612.0 601.0 606.0 ship 0
623.0 598.0 632.0 607.0 603.0 633.0 595.0 623.0 ship 0
636.0 608.0 643.0 618.0 610.0 644.0 603.0 634.0 ship 0
642.0 618.0 649.0 626.0 625.0 652.0 617.0 643.0 ship 0
651.0 627.0 659.0 636.0 631.0 663.0 623.0 653.0 ship 0
644.0 669.0 636.0 664.0 659.0 637.0 666.0 644.0 ship 0
672.0 648.0 681.0 659.0 650.0 683.0 641.0 671.0 ship 0
686.0 658.0 692.0 666.0 660.0 693.0 653.0 685.0 ship 0
670.0 709.0 660.0 698.0 689.0 670.0 699.0 679.0 ship 0
710.0 687.0 719.0 695.0 692.0 721.0 684.0 712.0 ship 0
721.0 698.0 729.0 706.0 700.0 735.0 692.0 728.0 ship 0
731.0 708.0 740.0 716.0 711.0 747.0 701.0 738.0 ship 0
408.0 380.0 417.0 389.0 391.0 413.0 383.0 404.0 ship 0
400.0 369.0 408.0 378.0 379.0 407.0 371.0 398.0 ship 0
390.0 359.0 399.0 367.0 369.0 398.0 360.0 389.0 ship 0
380.0 350.0 389.0 359.0 355.0 391.0 347.0 382.0 ship 0
593.0 782.0 584.0 774.0 613.0 744.0 621.0 752.0 ship 0
583.0 773.0 573.0 763.0 599.0 736.0 611.0 747.0 ship 0
572.0 762.0 564.0 754.0 588.0 728.0 596.0 735.0 ship 0
589.0 709.0 597.0 719.0 564.0 750.0 555.0 740.0 ship 0
545.0 734.0 534.0 724.0 564.0 693.0 575.0 704.0 ship 0
534.0 723.0 525.0 715.0 552.0 686.0 562.0 697.0 ship 0
525.0 712.0 516.0 702.0 546.0 674.0 555.0 684.0 ship 0
516.0 702.0 506.0 692.0 538.0 661.0 548.0 670.0 ship 0
506.0 692.0 496.0 683.0 526.0 651.0 536.0 662.0 ship 0
495.0 682.0 485.0 670.0 512.0 645.0 521.0 656.0 ship 0
476.0 663.0 468.0 655.0 495.0 624.0 505.0 634.0 ship 0
482.0 619.0 492.0 627.0 467.0 655.0 459.0 646.0 ship 0
455.0 642.0 447.0 633.0 475.0 606.0 484.0 614.0 ship 0
470.0 592.0 479.0 601.0 447.0 633.0 438.0 622.0 ship 0
437.0 622.0 429.0 613.0 454.0 588.0 463.0 598.0 ship 0
417.0 602.0 409.0 595.0 430.0 573.0 438.0 581.0 ship 0
410.0 592.0 401.0 583.0 430.0 556.0 440.0 565.0 ship 0
399.0 585.0 389.0 575.0 417.0 548.0 427.0 558.0 ship 0
389.0 575.0 379.0 565.0 413.0 529.0 424.0 539.0 ship 0
380.0 564.0 370.0 555.0 396.0 525.0 407.0 535.0 ship 0
361.0 545.0 351.0 536.0 378.0 506.0 389.0 516.0 ship 0
350.0 534.0 340.0 524.0 367.0 500.0 376.0 509.0 ship 0
331.0 515.0 322.0 505.0 351.0 474.0 363.0 484.0 ship 0
320.0 503.0 313.0 496.0 341.0 468.0 348.0 475.0 ship 0
330.0 458.0 339.0 468.0 312.0 495.0 302.0 485.0 ship 0
300.0 484.0 292.0 474.0 320.0 442.0 332.0 453.0 ship 0
284.0 466.0 274.0 456.0 300.0 427.0 310.0 439.0 ship 0
364.0 331.0 371.0 340.0 348.0 356.0 341.0 348.0 ship 0
371.0 338.0 380.0 349.0 349.0 377.0 341.0 368.0 ship 0
740.0 717.0 748.0 726.0 718.0 755.0 711.0 747.0 ship 0
736.0 769.0 730.0 760.0 759.0 736.0 766.0 746.0 ship 0
613.0 352.0 623.0 362.0 590.0 394.0 581.0 384.0 ship 0
548.0 261.0 539.0 253.0 559.0 228.0 569.0 236.0 ship 0
449.0 398.0 440.0 390.0 464.0 358.0 475.0 365.0 ship 0
461.0 344.0 471.0 352.0 441.0 385.0 431.0 375.0 ship 0
430.0 376.0 422.0 368.0 446.0 343.0 455.0 351.0 ship 0
422.0 367.0 412.0 358.0 439.0 331.0 449.0 339.0 ship 0
411.0 358.0 402.0 349.0 430.0 319.0 440.0 328.0 ship 0
402.0 347.0 393.0 338.0 423.0 308.0 432.0 316.0 ship 0
394.0 335.0 385.0 327.0 409.0 298.0 420.0 308.0 ship 0
400.0 289.0 410.0 298.0 382.0 328.0 371.0 318.0 ship 0
477.0 215.0 486.0 225.0 457.0 251.0 450.0 241.0 ship 0
498.0 210.0 491.0 202.0 516.0 177.0 524.0 185.0 ship 0
506.0 216.0 499.0 208.0 526.0 185.0 532.0 193.0 ship 0
528.0 192.0 537.0 199.0 514.0 227.0 505.0 220.0 ship 0
520.0 235.0 514.0 228.0 531.0 211.0 538.0 220.0 ship 0
532.0 241.0 524.0 233.0 547.0 210.0 555.0 217.0 ship 0
557.0 267.0 549.0 259.0 572.0 234.0 581.0 242.0 ship 0
744.0 788.0 732.0 776.0 765.0 744.0 777.0 756.0 ship 0
507.0 244.0 515.0 252.0 486.0 280.0 479.0 272.0 ship 0
498.0 290.0 489.0 282.0 514.0 255.0 522.0 264.0 ship 0
525.0 264.0 534.0 274.0 507.0 302.0 497.0 293.0 ship 0
535.0 274.0 544.0 283.0 516.0 313.0 508.0 304.0 ship 0
543.0 286.0 551.0 294.0 527.0 322.0 518.0 314.0 ship 0
554.0 293.0 563.0 303.0 535.0 332.0 526.0 323.0 ship 0
564.0 277.0 557.0 270.0 578.0 246.0 587.0 254.0 ship 0
572.0 286.0 564.0 278.0 585.0 257.0 593.0 266.0 ship 0
540.0 347.0 530.0 336.0 564.0 303.0 574.0 313.0 ship 0
575.0 314.0 584.0 324.0 556.0 349.0 548.0 339.0 ship 0
584.0 325.0 592.0 334.0 563.0 359.0 556.0 350.0 ship 0
594.0 333.0 601.0 343.0 574.0 367.0 567.0 357.0 ship 0
586.0 378.0 576.0 367.0 605.0 342.0 613.0 352.0 ship 0
622.0 363.0 630.0 373.0 601.0 403.0 592.0 393.0 ship 0
458.0 409.0 450.0 400.0 478.0 373.0 486.0 381.0 ship 0
468.0 418.0 459.0 410.0 489.0 378.0 500.0 387.0 ship 0
490.0 397.0 498.0 403.0 480.0 423.0 473.0 416.0 ship 0
488.0 437.0 479.0 427.0 509.0 398.0 517.0 408.0 ship 0
810.0 702.0 819.0 711.0 791.0 743.0 781.0 735.0 ship 0
799.0 694.0 809.0 704.0 779.0 734.0 770.0 725.0 ship 0
788.0 685.0 798.0 694.0 770.0 724.0 761.0 716.0 ship 0
778.0 673.0 789.0 682.0 761.0 715.0 750.0 705.0 ship 0
772.0 660.0 782.0 668.0 750.0 703.0 740.0 693.0 ship 0
741.0 692.0 733.0 685.0 761.0 654.0 770.0 662.0 ship 0
751.0 645.0 761.0 653.0 734.0 681.0 725.0 672.0 ship 0
738.0 640.0 746.0 648.0 721.0 673.0 714.0 665.0 ship 0
727.0 631.0 736.0 640.0 714.0 664.0 704.0 655.0 ship 0
715.0 604.0 725.0 613.0 694.0 645.0 684.0 635.0 ship 0
683.0 636.0 674.0 626.0 700.0 599.0 711.0 609.0 ship 0
674.0 624.0 665.0 613.0 693.0 585.0 703.0 596.0 ship 0
684.0 576.0 692.0 586.0 662.0 616.0 653.0 606.0 ship 0
654.0 604.0 644.0 595.0 670.0 568.0 680.0 576.0 ship 0
645.0 594.0 636.0 585.0 662.0 555.0 672.0 565.0 ship 0
635.0 586.0 627.0 579.0 651.0 547.0 659.0 554.0 ship 0
642.0 541.0 650.0 549.0 624.0 577.0 615.0 567.0 ship 0
631.0 516.0 649.0 534.0 614.0 566.0 597.0 547.0 ship 0
600.0 539.0 594.0 532.0 616.0 511.0 622.0 518.0 ship 0
586.0 536.0 577.0 526.0 603.0 500.0 613.0 510.0 ship 0
595.0 485.0 605.0 494.0 577.0 525.0 567.0 517.0 ship 0
567.0 515.0 558.0 505.0 584.0 479.0 592.0 487.0 ship 0
574.0 467.0 585.0 476.0 556.0 507.0 546.0 497.0 ship 0
563.0 459.0 573.0 467.0 546.0 497.0 537.0 487.0 ship 0
537.0 486.0 530.0 477.0 560.0 448.0 567.0 456.0 ship 0
548.0 437.0 558.0 445.0 529.0 478.0 519.0 467.0 ship 0
533.0 435.0 540.0 444.0 520.0 465.0 511.0 456.0 ship 0
525.0 417.0 536.0 426.0 510.0 456.0 499.0 446.0 ship 0
518.0 407.0 526.0 415.0 499.0 444.0 491.0 436.0 ship 0
573.0 117.0 585.0 107.0 1003.0 530.0 993.0 540.0 harbor 0

利用程序将标注文件的坐标读入(给出代码块仅供参考):

filelist = glob.glob('./*.txt')
    for filename in filelist:
        # basename = osp.basename(filename)
        with open(filename, 'r') as fread:
            lines = fread.readlines()
            nplines = []
            # read lines
            for line in lines:
                line = line.split()
                npline = np.array(line[:8], dtype=np.float32).astype(np.int32)
                nplines.append(npline[np.newaxis])
            nplines = np.concatenate(nplines, 0).reshape(-1, 4, 2)

此时读入的nplines结果为:

array([[[ 807,  331],
        [ 800,  324],
        [ 817,  309],
        [ 823,  316]],

       [[ 879,  366],
        [ 888,  373],
        [ 870,  393],
        [ 861,  386]],

       [[ 862,  384],
        [ 855,  377],
        [ 873,  356],
        [ 882,  363]],

       ...,

       [[ 525,  417],
        [ 536,  426],
        [ 510,  456],
        [ 499,  446]],

       [[ 518,  407],
        [ 526,  415],
        [ 499,  444],
        [ 491,  436]],

       [[ 573,  117],
        [ 585,  107],
        [1003,  530],
        [ 993,  540]]])

接下来的核心代码为:

    imgori1 = imgori.copy()
    img = cv.polylines(imgori1, nplines, isClosed=True, color=(255, 125, 125), thickness=1)

最后的img结果为:

注意!!!:这里其实有一个坑,polylines函数其实可以不需要将返回值赋给新的变量,它是直接将输入变量上进行操作,所以上面两行代码,我特意进行了一次copy操作,以防将最初的图片覆盖掉。

结束

以上便是对于该函数的介绍,如有疏漏欢迎指正!!!!

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐