-
Notifications
You must be signed in to change notification settings - Fork 209
/
vnn_helper.cpp
1353 lines (1301 loc) · 47 KB
/
vnn_helper.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//-------------------------------------------------------------------------------------------------------
// Copyright (c) 2021 Guangzhou Joyy Information Technology Co., Ltd. All rights reserved.
// Licensed under the MIT license. See license.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
#include "vnn_helper.h"
#include <string>
#include "vnn_face.h"
#include "vnn_faceparser.h"
#include "vnn_stylizing.h"
#include "vnn_face_reenactment.h"
#include "vnn_gesture.h"
#include "vnn_objtracking.h"
#include "vnn_objcount.h"
#include "vnn_general.h"
#include "vnn_classifying.h"
#include "vnn_pose.h"
using namespace std;
static cv::Mat trackingImg;
static CvPoint prePoint = { -1,-1 };
static CvPoint curPoint = { -1,-1 };
static bool getBox = false;
static VNN_Rect2D objBox;
static bool readyTrack = false;
void drawFaceResult(cv::Mat used_img, VNN_FaceFrameDataArr faceDetectionFrameData);
void drawMaskArr(cv::Mat used_img, VNN_ImageArr mask_arr);
void drawBlendMaskArrImageArr(cv::Mat used_img, VNN_ImageArr mask_arr, VNN_ImageArr img_arr);
void drawGestureResult(cv::Mat used_img, VNN_GestureFrameDataArr gestureFrameData);
void on_mouse(int event, int x, int y, int flags, void* param);//mouse event
void drawObjCountResult(cv::Mat used_img, VNN_ObjCountDataArr objCountDataArr);
void drawMaskArrSimple(VNN_ImageArr mask_arr);
void drawRGBImage(VNN_Image rgb_img);
void drawClassificationResult(cv::Mat used_img, VNN_MultiClsTopNAccArr cls_result);
void drawPoseResult(cv::Mat used_img, VNN_BodyFrameDataArr pose_result);
int VNNHelper::createVNN(VNN_EFFECT_MODE effectMode) {
int ret;
string folder_path = "./vnn_models/";
switch (effectMode) {
case VNN_FACE_KEYPOINTS: {
string model_path = folder_path + "vnn_face278_data/face_pc[1.0.0].vnnmodel";
const char* arg_model[] = {
model_path.c_str()
};
const int argc = 1;
VNN_Result creat_ret = VNN_Create_Face(&mVnnID, argc, (const void**)arg_model);
if (VNN_Result_Success != creat_ret || 0 == mVnnID) {
return -1;
}
//cout << "mVnnID:" << mVnnID << endl;
return 0;
break;
}
case VNN_FACE_MASK: {
string model_path = folder_path + "vnn_face278_data/face_pc[1.0.0].vnnmodel";
const char* arg_model[] = {
model_path.c_str()
};
const int argc = 1;
VNN_Result creat_ret = VNN_Create_Face(&mVnnID, argc, (const void**)arg_model);
if (VNN_Result_Success != creat_ret || 0 == mVnnID) {
return -1;
}
string mask_model_path = folder_path + "vnn_face_mask_data/face_mask[1.0.0].vnnmodel";
const char* arg_mask_model[] = {
mask_model_path.c_str()
};
const int argc_mask = 1;
VNN_Result creat_mask_ret = VNN_Create_FaceParser(&mVnnMaskID, argc_mask, (const void**)arg_mask_model);
if (VNN_Result_Success != creat_mask_ret || 0 == mVnnMaskID) {
return -1;
}
mOutImgWidth = 128;
mOutImgHeight = 128;
mOutPixelNum = mOutImgWidth * mOutImgHeight;
mMaskMemory = new unsigned char[mOutPixelNum * VNN_FRAMEDATAARR_MAX_FACES_NUM];
for (int i = 0; i < VNN_FRAMEDATAARR_MAX_FACES_NUM; i++) {
mImageArr.imgsArr[i].width = mOutImgWidth;
mImageArr.imgsArr[i].height = mOutImgHeight;
mImageArr.imgsArr[i].pix_fmt = VNN_PIX_FMT_GRAY8;
mImageArr.imgsArr[i].data = mMaskMemory + i * mOutPixelNum;
}
return 0;
break;
}
case VNN_DISNEY_FACE: {
string model_path = folder_path + "vnn_face278_data/face_pc[1.0.0].vnnmodel";
const char* arg_model[] = {
model_path.c_str()
};
const int argc = 1;
VNN_Result creat_ret = VNN_Create_Face(&mVnnID, argc, (const void**)arg_model);
if (VNN_Result_Success != creat_ret || 0 == mVnnID) {
return -1;
}
string mask_model_path = folder_path + "vnn_face_mask_data/face_mask[1.0.0].vnnmodel";
const char* arg_mask_model[] = {
mask_model_path.c_str()
};
const int argc_mask = 1;
VNN_Result creat_mask_ret = VNN_Create_FaceParser(&mVnnMaskID, argc_mask, (const void**)arg_mask_model);
if (VNN_Result_Success != creat_mask_ret || 0 == mVnnMaskID) {
return -1;
}
mOutImgWidth = 128;
mOutImgHeight = 128;
mOutPixelNum = mOutImgWidth * mOutImgHeight;
mMaskMemory = new unsigned char[mOutPixelNum * VNN_FRAMEDATAARR_MAX_FACES_NUM];
for (int i = 0; i < VNN_FRAMEDATAARR_MAX_FACES_NUM; i++) {
mImageArr.imgsArr[i].width = mOutImgWidth;
mImageArr.imgsArr[i].height = mOutImgHeight;
mImageArr.imgsArr[i].pix_fmt = VNN_PIX_FMT_GRAY8;
mImageArr.imgsArr[i].data = mMaskMemory + i * mOutPixelNum;
}
string disney_model_path = folder_path + "vnn_disney_data/face_disney[1.0.0].vnnmodel";
const char* arg_disney_model[] = {
disney_model_path.c_str()
};
const int argc_disney = 1;
VNN_Result creat_disney_ret = VNN_Create_FaceParser(&mVnnDisneyID, argc_disney, (const void**)arg_disney_model);
if (VNN_Result_Success != creat_disney_ret || 0 == mVnnDisneyID) {
return -1;
}
mDisneyImgWidth = 512;
mDisneyImgHeight = 512;
mDisneyImgChannel = 3;
mDisneyMemory = new unsigned char[mDisneyImgChannel * mDisneyImgWidth * mDisneyImgHeight * VNN_FRAMEDATAARR_MAX_FACES_NUM];
for (int i = 0; i < VNN_FRAMEDATAARR_MAX_FACES_NUM; i++) {
mDisneyDataArr.imgsArr[i].width = mDisneyImgWidth;
mDisneyDataArr.imgsArr[i].height = mDisneyImgHeight;
mDisneyDataArr.imgsArr[i].channels = mDisneyImgChannel;
mDisneyDataArr.imgsArr[i].data = mDisneyMemory + i * mDisneyImgChannel * mDisneyImgWidth * mDisneyImgHeight;
}
return 0;
break;
}
case VNN_3DGAME_FACE: {
string model_path = folder_path + "vnn_face278_data/face_pc[1.0.0].vnnmodel";
const char* arg_model[] = {
model_path.c_str()
};
const int argc = 1;
VNN_Result creat_ret = VNN_Create_Face(&mVnnID, argc, (const void**)arg_model);
if (VNN_Result_Success != creat_ret || 0 == mVnnID) {
return -1;
}
string game_model_path = folder_path + "vnn_3dgame_data/face_3dgame[1.0.0].vnnmodel";
const char* arg_game_model[] = {
game_model_path.c_str()
};
const int argc_game = 1;
VNN_Result creat_game_ret = VNN_Create_Stylizing(&mVnn3DGameID, argc_game, (const void**)arg_game_model);
if (VNN_Result_Success != creat_game_ret || 0 == mVnn3DGameID) {
return -1;
}
mOutImgWidth = 512;
mOutImgHeight = 512;
mOutPixelNum = mOutImgWidth * mOutImgHeight;
mMaskMemory = new unsigned char[mOutPixelNum * VNN_FRAMEDATAARR_MAX_FACES_NUM];
for (int i = 0; i < VNN_FRAMEDATAARR_MAX_FACES_NUM; i++) {
mImageArr.imgsArr[i].width = mOutImgWidth;
mImageArr.imgsArr[i].height = mOutImgHeight;
mImageArr.imgsArr[i].data = mMaskMemory + i * mOutPixelNum;
mImageArr.imgsArr[i].pix_fmt = VNN_PIX_FMT_GRAY8;
}
m3dGameImgChannel = 3;
m3dGameMemory = new unsigned char[m3dGameImgChannel * mOutPixelNum * VNN_FRAMEDATAARR_MAX_FACES_NUM];
for (int i = 0; i < VNN_FRAMEDATAARR_MAX_FACES_NUM; i++) {
mGame3dDataArr.imgsArr[i].width = mOutImgWidth;
mGame3dDataArr.imgsArr[i].height = mOutImgHeight;
mGame3dDataArr.imgsArr[i].channels = m3dGameImgChannel;
mGame3dDataArr.imgsArr[i].data = m3dGameMemory + i * m3dGameImgChannel * mOutPixelNum;
}
return 0;
break;
}
case VNN_FACE_REENACT: {
string model_path = folder_path + "vnn_face278_data/face_pc[1.0.0].vnnmodel";
const char* arg_model[] = {
model_path.c_str()
};
const int argc = 1;
VNN_Result creat_ret = VNN_Create_Face(&mVnnID, argc, (const void**)arg_model);
if (VNN_Result_Success != creat_ret || 0 == mVnnID) {
return -1;
}
string reenact_model_path = folder_path + "vnn_face_reenactment_data/face_reenactment[1.0.0].vnnmodel";
const char* arg_reenact_model[] = {
reenact_model_path.c_str()
};
const int argc_reenact = 1;
VNN_Result creat_reenact_ret = VNN_Create_FaceReenactment(&mVnnReenactID, argc_reenact, (const void**)arg_reenact_model);
if (VNN_Result_Success != creat_reenact_ret || 0 == mVnnReenactID) {
return -1;
}
mOutImgWidth = 256;
mOutImgHeight = 256;
break;
}
case VNN_GESTURE: {
string model_path = folder_path + "vnn_gesture_data/gesture[1.0.0].vnnmodel";
const char* arg_model[] = {
model_path.c_str()
};
const int argc = 1;
VNN_Result creat_ret = VNN_Create_Gesture(&mVnnID, argc, (const void**)arg_model);
if (VNN_Result_Success != creat_ret || 0 == mVnnID) {
return -1;
}
break;
}
case VNN_OBJECT_TRACKING: {
string model_path = folder_path + "vnn_objtracking_data/object_tracking[1.0.0].vnnmodel";
const char* arg_model[] = {
model_path.c_str()
};
const int argc = 1;
VNN_Result creat_ret = VNN_Create_ObjTracking(&mVnnID, argc, (const void**)arg_model);
if (VNN_Result_Success != creat_ret || 0 == mVnnID) {
return -1;
}
mOutImgWidth = 289;
mOutImgHeight = 289;
break;
}
case VNN_FACE_COUNT: {
string model_path = folder_path + "vnn_face_count_data/face_count[1.0.0].vnnmodel";
const char* arg_model[] = {
model_path.c_str()
};
const int argc = 1;
VNN_Result creat_ret = VNN_Create_ObjCount(&mVnnID, argc, (const void**)arg_model);
if (VNN_Result_Success != creat_ret || 0 == mVnnID) {
return -1;
}
break;
}
case VNN_QR_CODE: {
string model_path = folder_path + "vnn_qrcode_detection_data/qrcode_detection[1.0.0].vnnmodel";
const char* arg_model[] = {
model_path.c_str()
};
const int argc = 1;
VNN_Result creat_ret = VNN_Create_ObjCount(&mVnnID, argc, (const void**)arg_model);
if (VNN_Result_Success != creat_ret || 0 == mVnnID) {
return -1;
}
break;
}
case VNN_PORTRAIT_SEG: {
string model_path = folder_path + "vnn_portraitseg_data/seg_portrait_picture[1.0.0].vnnmodel";
string process_path = folder_path + "vnn_portraitseg_data/seg_portrait_picture[1.0.0]_process_config.json";
const char* arg_model[] = {
model_path.c_str(),
process_path.c_str()
};
const int argc = 2;
VNN_Result creat_ret = VNN_Create_General(&mVnnID, argc, (const void**)arg_model);
if (VNN_Result_Success != creat_ret || 0 == mVnnID) {
return -1;
}
mOutImgWidth = 384;
mOutImgHeight = 512;
mOutChannel = 1;
mOutPixelNum = mOutImgWidth * mOutImgHeight;
mMaskMemory = new unsigned char[mOutPixelNum];
mImageArr.imgsNum = 1;
mImageArr.imgsArr[0].width = mOutImgWidth;
mImageArr.imgsArr[0].height = mOutImgHeight;
mImageArr.imgsArr[0].data = mMaskMemory;
mImageArr.imgsArr[0].pix_fmt = VNN_PIX_FMT_GRAY8;
break;
}
case VNN_VIDEO_PORTRAIT_SEG: {
string model_path = folder_path + "vnn_portraitseg_data/seg_portrait_video[1.0.0].vnnmodel";
string process_path = folder_path + "vnn_portraitseg_data/seg_portrait_video[1.0.0]_process_config.json";
const char* arg_model[] = {
model_path.c_str(),
process_path.c_str()
};
const int argc = 2;
VNN_Result creat_ret = VNN_Create_General(&mVnnID, argc, (const void**)arg_model);
if (VNN_Result_Success != creat_ret || 0 == mVnnID) {
return -1;
}
mOutImgWidth = 128;
mOutImgHeight = 128;
mOutChannel = 1;
mOutPixelNum = mOutImgWidth * mOutImgHeight;
mMaskMemory = new unsigned char[mOutPixelNum];
mImageArr.imgsNum = 1;
mImageArr.imgsArr[0].width = mOutImgWidth;
mImageArr.imgsArr[0].height = mOutImgHeight;
mImageArr.imgsArr[0].data = mMaskMemory;
mImageArr.imgsArr[0].pix_fmt = VNN_PIX_FMT_GRAY8;
break;
}
case VNN_SKY_SEG: {
string model_path = folder_path + "vnn_skyseg_data/sky_segment[1.0.0].vnnmodel";
string process_path = folder_path + "vnn_skyseg_data/sky_segment[1.0.0]_process_config.json";
const char* arg_model[] = {
model_path.c_str(),
process_path.c_str()
};
const int argc = 2;
VNN_Result creat_ret = VNN_Create_General(&mVnnID, argc, (const void**)arg_model);
if (VNN_Result_Success != creat_ret || 0 == mVnnID) {
return -1;
}
mOutImgWidth = 512;
mOutImgHeight = 512;
mOutChannel = 1;
mOutPixelNum = mOutImgWidth * mOutImgHeight;
mMaskMemory = new unsigned char[mOutPixelNum];
mImageArr.imgsNum = 1;
mImageArr.imgsArr[0].width = mOutImgWidth;
mImageArr.imgsArr[0].height = mOutImgHeight;
mImageArr.imgsArr[0].data = mMaskMemory;
mImageArr.imgsArr[0].pix_fmt = VNN_PIX_FMT_GRAY8;
break;
}
case VNN_CLOTHES_SEG: {
string model_path = folder_path + "vnn_clothesseg_data/clothes_segment[1.0.0].vnnmodel";
string process_path = folder_path + "vnn_clothesseg_data/clothes_segment[1.0.0]_process_config.json";
const char* arg_model[] = {
model_path.c_str(),
process_path.c_str()
};
const int argc = 2;
VNN_Result creat_ret = VNN_Create_General(&mVnnID, argc, (const void**)arg_model);
if (VNN_Result_Success != creat_ret || 0 == mVnnID) {
return -1;
}
mOutImgWidth = 384;
mOutImgHeight = 512;
mOutChannel = 1;
mOutPixelNum = mOutImgWidth * mOutImgHeight;
mMaskMemory = new unsigned char[mOutPixelNum];
mImageArr.imgsNum = 1;
mImageArr.imgsArr[0].width = mOutImgWidth;
mImageArr.imgsArr[0].height = mOutImgHeight;
mImageArr.imgsArr[0].data = mMaskMemory;
mImageArr.imgsArr[0].pix_fmt = VNN_PIX_FMT_GRAY8;
break;
}
case VNN_ANIMAL_SEG: {
string model_path = folder_path + "vnn_animalseg_data/animal_segment[1.0.0].vnnmodel";
string process_path = folder_path + "vnn_animalseg_data/animal_segment[1.0.0]_process_config.json";
const char* arg_model[] = {
model_path.c_str(),
process_path.c_str()
};
const int argc = 2;
VNN_Result creat_ret = VNN_Create_General(&mVnnID, argc, (const void**)arg_model);
if (VNN_Result_Success != creat_ret || 0 == mVnnID) {
return -1;
}
mOutImgWidth = 384;
mOutImgHeight = 512;
mOutChannel = 1;
mOutPixelNum = mOutImgWidth * mOutImgHeight;
mMaskMemory = new unsigned char[mOutPixelNum];
mImageArr.imgsNum = 1;
mImageArr.imgsArr[0].width = mOutImgWidth;
mImageArr.imgsArr[0].height = mOutImgHeight;
mImageArr.imgsArr[0].data = mMaskMemory;
mImageArr.imgsArr[0].pix_fmt = VNN_PIX_FMT_GRAY8;
break;
}
case VNN_HAIR_SEG: {
string model_path = folder_path + "vnn_hairseg_data/hair_segment[1.0.0].vnnmodel";
string process_path = folder_path + "vnn_hairseg_data/hair_segment[1.0.0]_process_config.json";
const char* arg_model[] = {
model_path.c_str(),
process_path.c_str()
};
const int argc = 2;
VNN_Result creat_ret = VNN_Create_General(&mVnnID, argc, (const void**)arg_model);
if (VNN_Result_Success != creat_ret || 0 == mVnnID) {
return -1;
}
mOutImgWidth = 256;
mOutImgHeight = 384;
mOutChannel = 1;
mOutPixelNum = mOutImgWidth * mOutImgHeight;
mMaskMemory = new unsigned char[mOutPixelNum];
mImageArr.imgsNum = 1;
mImageArr.imgsArr[0].width = mOutImgWidth;
mImageArr.imgsArr[0].height = mOutImgHeight;
mImageArr.imgsArr[0].data = mMaskMemory;
mImageArr.imgsArr[0].pix_fmt = VNN_PIX_FMT_GRAY8;
break;
}
case VNN_HEAD_SEG: {
string model_path = folder_path + "vnn_face278_data/face_pc[1.0.0].vnnmodel";
const char* arg_model[] = {
model_path.c_str()
};
const int argc = 1;
VNN_Result creat_ret = VNN_Create_Face(&mVnnID, argc, (const void**)arg_model);
if (VNN_Result_Success != creat_ret || 0 == mVnnID) {
return -1;
}
string head_model_path = folder_path + "vnn_headseg_data/head_segment[1.0.0].vnnmodel";
string process_path = folder_path + "vnn_headseg_data/head_segment[1.0.0]_process_config.json";
const char* arg_head_model[] = {
head_model_path.c_str(),
process_path.c_str()
};
const int argc_head = 2;
VNN_Result creat_head_ret = VNN_Create_General(&mVnnHeadSegID, argc_head, (const void**)arg_head_model);
if (VNN_Result_Success != creat_head_ret || 0 == mVnnHeadSegID) {
return -1;
}
mOutImgWidth = 256;
mOutImgHeight = 256;
mOutChannel = 1;
mOutPixelNum = mOutImgWidth * mOutImgHeight;
mMaskMemory = new unsigned char[mOutPixelNum * VNN_FRAMEDATAARR_MAX_FACES_NUM];
for (int i = 0; i < VNN_FRAMEDATAARR_MAX_FACES_NUM; i++) {
mImageArr.imgsArr[i].width = mOutImgWidth;
mImageArr.imgsArr[i].height = mOutImgHeight;
mImageArr.imgsArr[i].data = mMaskMemory + i * mOutPixelNum;
mImageArr.imgsArr[i].pix_fmt = VNN_PIX_FMT_GRAY8;
}
break;
}
case VNN_COMIC: {
string model_path = folder_path + "vnn_comic_data/stylize_comic[1.0.0].vnnmodel";
string process_path = folder_path + "vnn_comic_data/stylize_comic[1.0.0]_proceess_config.json";
const char* arg_model[] = {
model_path.c_str(),
process_path.c_str()
};
const int argc = 2;
VNN_Result creat_ret = VNN_Create_General(&mVnnID, argc, (const void**)arg_model);
if (VNN_Result_Success != creat_ret || 0 == mVnnID) {
return -1;
}
mOutImgWidth = 384;
mOutImgHeight = 512;
mOutChannel = 3;
mOutPixelNum = mOutImgWidth * mOutImgHeight;
mMaskMemory = new unsigned char[mOutPixelNum * mOutChannel];
memset(&mImageArr, 0x00, sizeof(VNN_ImageArr));
mImageArr.imgsNum = 1;
mImageArr.imgsArr[0].width = mOutImgWidth;
mImageArr.imgsArr[0].height = mOutImgHeight;
mImageArr.imgsArr[0].channels = mOutChannel;
mImageArr.imgsArr[0].data = mMaskMemory;
mImageArr.imgsArr[0].pix_fmt = VNN_PIX_FMT_RGB888;
break;
}
case VNN_CARTOON: {
string model_path = folder_path + "vnn_cartoon_data/stylize_cartoon[1.0.0].vnnmodel";
string process_path = folder_path + "vnn_cartoon_data/stylize_cartoon[1.0.0]_proceess_config.json";
const char* arg_model[] = {
model_path.c_str(),
process_path.c_str()
};
const int argc = 2;
VNN_Result creat_ret = VNN_Create_General(&mVnnID, argc, (const void**)arg_model);
if (VNN_Result_Success != creat_ret || 0 == mVnnID) {
return -1;
}
mOutImgWidth = 512;
mOutImgHeight = 512;
mOutChannel = 3;
mOutPixelNum = mOutImgWidth * mOutImgHeight;
mMaskMemory = new unsigned char[mOutPixelNum * mOutChannel];
memset(&mImageArr, 0x00, sizeof(VNN_ImageArr));
mImageArr.imgsNum = 1;
mImageArr.imgsArr[0].width = mOutImgWidth;
mImageArr.imgsArr[0].height = mOutImgHeight;
mImageArr.imgsArr[0].data = mMaskMemory;
mImageArr.imgsArr[0].pix_fmt = VNN_PIX_FMT_RGB888;
break;
}
case VNN_OBJECT_CLASSIFICATION: {
string model_path = folder_path + "vnn_classification_data/object_classification[1.0.0].vnnmodel";
string label_path = folder_path + "vnn_classification_data/object_classification[1.0.0]_label.json";
const char* arg_model[] = {
model_path.c_str()
};
const int argc = 1;
VNN_Result creat_ret = VNN_Create_Classifying(&mVnnID, argc, (const void**)arg_model);
if (VNN_Result_Success != creat_ret || 0 == mVnnID) {
return -1;
}
VNN_Set_Classifying_Attr(mVnnID, "_classLabelPath", label_path.c_str());
break;
}
case VNN_SCENE_WEATHER: {
string model_path = folder_path + "vnn_classification_data/scene_weather[1.0.0].vnnmodel";
string label_path = folder_path + "vnn_classification_data/scene_weather[1.0.0]_label.json";
const char* arg_model[] = {
model_path.c_str()
};
const int argc = 1;
VNN_Result creat_ret = VNN_Create_Classifying(&mVnnID, argc, (const void**)arg_model);
if (VNN_Result_Success != creat_ret || 0 == mVnnID) {
return -1;
}
VNN_Set_Classifying_Attr(mVnnID, "_classLabelPath", label_path.c_str());
break;
}
case VNN_PERSON_ATTRIBUTE: {
string model_path = folder_path + "vnn_face278_data/face_pc[1.0.0].vnnmodel";
const char* arg_model[] = {
model_path.c_str()
};
const int argc = 1;
VNN_Result creat_ret = VNN_Create_Face(&mVnnID, argc, (const void**)arg_model);
if (VNN_Result_Success != creat_ret || 0 == mVnnID) {
return -1;
}
string attrib_model_path = folder_path + "vnn_classification_data/person_attribute[1.0.0].vnnmodel";
string label_path = folder_path + "vnn_classification_data/person_attribute[1.0.0]_label.json";
const char* arg_attrib_model[] = {
attrib_model_path.c_str()
};
const int argc_attrib = 1;
VNN_Result creat_attrib_ret = VNN_Create_Classifying(&mVnnPersonAttribID, argc_attrib, (const void**)arg_attrib_model);
if (VNN_Result_Success != creat_attrib_ret || 0 == mVnnPersonAttribID) {
return -1;
}
VNN_Set_Classifying_Attr(mVnnID, "_classLabelPath", label_path.c_str());
break;
}
case VNN_POSE_LANDMARKS: {
string model_path = folder_path + "vnn_pose_data/pose_landmarks[1.0.0].vnnmodel";
const char* arg_model[] = {
model_path.c_str()
};
const int argc = 1;
VNN_Result creat_ret = VNN_Create_Pose(&mVnnID, argc, (const void**)arg_model);
if (VNN_Result_Success != creat_ret || 0 == mVnnID) {
return -1;
}
break;
}
}
return 0;
}
int VNNHelper::destroyVNN(VNN_EFFECT_MODE effectMode) {
VNN_Result ret = VNN_Result_Success;
switch (effectMode) {
case VNN_FACE_KEYPOINTS: {
ret = VNN_Destroy_Face(&mVnnID);
break;
}
case VNN_FACE_MASK: {
ret = VNN_Destroy_Face(&mVnnID);
if (VNN_Result_Success != ret) {
return -1;
}
ret = VNN_Destroy_FaceParser(&mVnnMaskID);
if (mMaskMemory != nullptr) {
delete[]mMaskMemory;
}
mMaskMemory = nullptr;
break;
}
case VNN_DISNEY_FACE: {
ret = VNN_Destroy_Face(&mVnnID);
if (VNN_Result_Success != ret) {
return -1;
}
ret = VNN_Destroy_FaceParser(&mVnnMaskID);
if (VNN_Result_Success != ret) {
return -1;
}
ret = VNN_Destroy_FaceParser(&mVnnDisneyID);
if (mMaskMemory != nullptr) {
delete[]mMaskMemory;
}
mMaskMemory = nullptr;
if (mDisneyMemory != nullptr) {
delete[]mDisneyMemory;
}
mDisneyMemory = nullptr;
break;
}
case VNN_3DGAME_FACE: {
ret = VNN_Destroy_Face(&mVnnID);
if (VNN_Result_Success != ret) {
return -1;
}
ret = VNN_Destroy_Stylizing(&mVnn3DGameID);
if (mMaskMemory != nullptr) {
delete[]mMaskMemory;
}
mMaskMemory = nullptr;
if (m3dGameMemory != nullptr) {
delete[]m3dGameMemory;
}
m3dGameMemory = nullptr;
break;
}
case VNN_FACE_REENACT: {
ret = VNN_Destroy_Face(&mVnnID);
if (VNN_Result_Success != ret) {
return -1;
}
ret = VNN_Destroy_FaceReenactment(&mVnnReenactID);
break;
}
case VNN_GESTURE: {
ret = VNN_Destroy_Gesture(&mVnnID);
break;
}
case VNN_OBJECT_TRACKING: {
ret = VNN_Destroy_ObjTracking(&mVnnID);
break;
}
case VNN_FACE_COUNT: {
ret = VNN_Destroy_ObjCount(&mVnnID);
break;
}
case VNN_QR_CODE: {
ret = VNN_Destroy_ObjCount(&mVnnID);
break;
}
case VNN_PORTRAIT_SEG:
case VNN_VIDEO_PORTRAIT_SEG:
case VNN_SKY_SEG:
case VNN_CLOTHES_SEG:
case VNN_ANIMAL_SEG:
case VNN_HAIR_SEG:
case VNN_COMIC:
case VNN_CARTOON: {
ret = VNN_Destroy_General(&mVnnID);
if (mMaskMemory != nullptr) {
delete[]mMaskMemory;
}
mMaskMemory = nullptr;
break;
}
case VNN_HEAD_SEG: {
ret = VNN_Destroy_Face(&mVnnID);
if (VNN_Result_Success != ret) {
return -1;
}
ret = VNN_Destroy_General(&mVnnHeadSegID);
if (mMaskMemory != nullptr) {
delete[]mMaskMemory;
}
mMaskMemory = nullptr;
break;
}
case VNN_OBJECT_CLASSIFICATION: {
ret = VNN_Destroy_Classifying(&mVnnID);
break;
}
case VNN_SCENE_WEATHER: {
ret = VNN_Destroy_Classifying(&mVnnID);
break;
}
case VNN_PERSON_ATTRIBUTE: {
ret = VNN_Destroy_Face(&mVnnID);
if (VNN_Result_Success != ret) {
return -1;
}
ret = VNN_Destroy_Classifying(&mVnnPersonAttribID);
break;
}
case VNN_POSE_LANDMARKS: {
ret = VNN_Destroy_Pose(&mVnnID);
break;
}
}
if (VNN_Result_Success != ret) {
return -1;
}
return 0;
}
int VNNHelper::applyVNN(VNN_EFFECT_MODE effectMode, cv::Mat used_img, int mode) {
cv::Mat rgba_image;
cv::cvtColor(used_img, rgba_image, cv::COLOR_BGR2RGBA);
VNN_Image in_image;
in_image.height = used_img.rows;
in_image.width = used_img.cols;
in_image.data = (void*)rgba_image.data;
in_image.pix_fmt = VNN_PIX_FMT_RGBA8888;
in_image.ori_fmt = VNN_ORIENT_FMT::VNN_ORIENT_FMT_DEFAULT;
in_image.channels = in_image.pix_fmt == VNN_PIX_FMT_RGB888 || in_image.pix_fmt == VNN_PIX_FMT_BGR888 ? 3 : 4;
in_image.mode_fmt = (mode == 0 ? VNN_MODE_FMT_VIDEO : VNN_MODE_FMT_PICTURE);
VNN_Result ret;
switch (effectMode)
{
case VNN_FACE_KEYPOINTS: {
if (mVnnID != 0) {
mFaceDetectionFrameData.facesNum = 0;
int _use_278pts = 1;
VNN_Set_Face_Attr(mVnnID, "_use_278pts", &_use_278pts);
ret = VNN_Apply_Face_CPU(mVnnID, &in_image, &mFaceDetectionFrameData);
//cout << "face count ��" << mFaceDetectionFrameData.facesNum << endl;
drawFaceResult(used_img, mFaceDetectionFrameData);
}
return ret;
break;
}
case VNN_FACE_MASK: {
if (mVnnID != 0 && mVnnMaskID != 0) {
mFaceDetectionFrameData.facesNum = 0;
int _use_278pts = 1;
VNN_Set_Face_Attr(mVnnID, "_use_278pts", &_use_278pts);
ret = VNN_Apply_Face_CPU(mVnnID, &in_image, &mFaceDetectionFrameData);
if (mFaceDetectionFrameData.facesNum > 0 && VNN_Result_Success == ret) {
ret = VNN_Apply_FaceParser_CPU(mVnnMaskID, &in_image, &mFaceDetectionFrameData, &mImageArr);
}
if (VNN_Result_Success == ret) {
drawMaskArr(used_img, mImageArr);
}
}
break;
}
case VNN_DISNEY_FACE: {
mFaceDetectionFrameData.facesNum = 0;
int _use_278pts = 1;
VNN_Set_Face_Attr(mVnnID, "_use_278pts", &_use_278pts);
ret = VNN_Apply_Face_CPU(mVnnID, &in_image, &mFaceDetectionFrameData);
if (mFaceDetectionFrameData.facesNum > 0 && VNN_Result_Success == ret) {
ret = VNN_Apply_FaceParser_CPU(mVnnMaskID, &in_image, &mFaceDetectionFrameData, &mImageArr);
if (VNN_Result_Success == ret) {
ret = VNN_Apply_FaceParser_CPU(mVnnDisneyID, &in_image, &mFaceDetectionFrameData, &mDisneyDataArr);
}
}
if (VNN_Result_Success == ret) {
drawBlendMaskArrImageArr(used_img, mImageArr, mDisneyDataArr);
}
break;
}
case VNN_3DGAME_FACE: {
mFaceDetectionFrameData.facesNum = 0;
int _use_278pts = 1;
VNN_Set_Face_Attr(mVnnID, "_use_278pts", &_use_278pts);
ret = VNN_Apply_Face_CPU(mVnnID, &in_image, &mFaceDetectionFrameData);
if (mFaceDetectionFrameData.facesNum > 0 && VNN_Result_Success == ret) {
ret = VNN_Apply_Stylizing_CPU(mVnn3DGameID, &in_image, &mFaceDetectionFrameData, &mGame3dDataArr);
if (VNN_Result_Success == ret) {
VNN_Get_Stylizing_Attr(mVnn3DGameID, "_Mask", &mImageArr);
}
}
if (VNN_Result_Success == ret) {
drawBlendMaskArrImageArr(used_img, mImageArr, mGame3dDataArr);
}
break;
}
case VNN_FACE_REENACT: {
if (mVnnID != 0 && mVnnReenactID != 0) {
int _use_278pts = 1;
VNN_Set_Face_Attr(mVnnID, "_use_278pts", &_use_278pts);
ret = VNN_Apply_Face_CPU(mVnnID, &in_image, &mFaceDetectionFrameData);
VNN_Get_Face_Attr(mVnnID, "_detection_data", &mFaceDetectionRect);
VNN_Set_FaceReenactment_Attr(mVnnReenactID, "_kpJsonsPath", "./vnn_models/vnn_face_reenactment_data/driving.kps.json");
VNN_Set_FaceReenactment_Attr(mVnnReenactID, "_faceRect", &(mFaceDetectionRect.facesArr[0].faceRect));//only procees the first detected face
VNN_Set_FaceReenactment_Attr(mVnnReenactID, "_targetImage", &in_image);
int frame_count = 0;
VNN_Get_FaceReenactment_Attr(mVnnReenactID, "_frameCount", &frame_count);
int pixel_num = mOutImgHeight * mOutImgWidth;
cv::Mat rgb_img = cv::Mat(mOutImgHeight, mOutImgWidth, CV_8UC3);
cv::Mat show_img;
VNN_Image* result_imgs = new VNN_Image[frame_count];
for (int i = 1; i <= frame_count; i++) { // start from 1
result_imgs[i - 1].data = new unsigned char[pixel_num * 3];
result_imgs[i - 1].width = mOutImgWidth;
result_imgs[i - 1].height = mOutImgHeight;
result_imgs[i - 1].pix_fmt = VNN_PIX_FMT_RGB888;
VNN_Apply_FaceReenactment_CPU(mVnnReenactID, &i, &(result_imgs[i - 1]));
memcpy(rgb_img.data, result_imgs[i - 1].data, pixel_num * 3);
cv::cvtColor(rgb_img, show_img, cv::COLOR_RGB2BGR);
cv::Point text_pos(5, mOutImgHeight - 5);
char text[100];
sprintf(text, "progress: %d\%%", i * 100 / frame_count);
cv::putText(show_img, text, text_pos, cv::FONT_HERSHEY_COMPLEX_SMALL, 1.0, cv::Scalar(50, 50, 255), 1, 8, 0);
cv::imshow("Show", show_img);
if (cv::waitKey(1) == 27) {
cvDestroyWindow("Show");
break;
}
}
bool go_out = false;
while (1) {
for (int i = 0; i < frame_count; i++) {
memcpy(rgb_img.data, result_imgs[i].data, pixel_num * 3);
cv::cvtColor(rgb_img, show_img, cv::COLOR_RGB2BGR);
cv::Point text_pos(5, mOutImgHeight - 5);
cv::putText(show_img, "Press Esc to exit", text_pos, cv::FONT_HERSHEY_COMPLEX_SMALL, 1.0, cv::Scalar(50, 50, 255), 1, 8, 0);
cv::imshow("Show", show_img);
_sleep(30);
if (cv::waitKey(1) == 27) {
go_out = true;
cvDestroyWindow("Show");
break;
}
}
if (go_out) {
break;
}
}
for (int i = 0; i < frame_count; i++) {
delete[] result_imgs[i].data;
}
delete[] result_imgs;
}
break;
}
case VNN_GESTURE: {
mGestureFrameData.gestureNum = 0; //memset(&mGestureFrameData, 0x00, sizeof(VNN_GestureFrameDataArr));
ret = VNN_Apply_Gesture_CPU(mVnnID, &in_image, &mGestureFrameData);
if (VNN_Result_Success == ret) {
drawGestureResult(used_img, mGestureFrameData);
}
break;
}
case VNN_OBJECT_TRACKING: {
trackingImg = used_img;
if (mVnnID != 0) {
int pixel_num = mOutImgHeight * mOutImgWidth;
if (getBox) {
getBox = false;
readyTrack = true;
bool clean = true;
VNN_Set_ObjTracking_Attr(mVnnID, "_clearImage", &clean);
VNN_Set_ObjTracking_Attr(mVnnID, "_targetImage", &in_image);
VNN_Set_ObjTracking_Attr(mVnnID, "_objRect", &objBox);
}
else if (readyTrack) {
ret = VNN_Apply_ObjTracking_CPU(mVnnID, &in_image, &mTrackingDataArr);
auto left = mTrackingDataArr.objRectArr[0].x0 * used_img.cols;
auto right = mTrackingDataArr.objRectArr[0].x1 * used_img.cols;
auto bottom = mTrackingDataArr.objRectArr[0].y0 * used_img.rows;
auto top = mTrackingDataArr.objRectArr[0].y1 * used_img.rows;
cv::rectangle(used_img, cvPoint(left, top), cvPoint(right, bottom), CV_RGB(0, 0, 255), 3, 8, 0);
VNN_ObjCountDataArr_Free(&mTrackingDataArr);
}
}
cv::Point text_pos(5, used_img.rows - 5);
cv::putText(used_img, "Slide over the screen to select the target", text_pos, cv::FONT_HERSHEY_COMPLEX_SMALL, 1.0, cv::Scalar(50, 50, 255), 1, 8, 0);
cv::imshow("Show", used_img);
cvSetMouseCallback("Show", on_mouse, 0);
break;
}
case VNN_FACE_COUNT:
case VNN_QR_CODE: {
memset(&mObjCountDataArr, 0x00, sizeof(VNN_ObjCountDataArr));
ret = VNN_Apply_ObjCount_CPU(mVnnID, &in_image, &mObjCountDataArr);
drawObjCountResult(used_img, mObjCountDataArr);
VNN_ObjCountDataArr_Free(&mObjCountDataArr);
break;
}
case VNN_PORTRAIT_SEG:
case VNN_VIDEO_PORTRAIT_SEG:
case VNN_SKY_SEG:
case VNN_CLOTHES_SEG:
case VNN_ANIMAL_SEG:
case VNN_HAIR_SEG: {
if (mVnnID != 0) {
ret = VNN_Apply_General_CPU(mVnnID, &in_image, nullptr, &mImageArr);
drawMaskArr(used_img, mImageArr);
//drawMaskArrSimple(mImageArr);
}
cv::imshow("Origin", used_img);
break;
}
case VNN_HEAD_SEG: {
if (mVnnID != 0 && mVnnHeadSegID != 0) {
int _use_278pts = 1;
VNN_Set_Face_Attr(mVnnID, "_use_278pts", &_use_278pts);
ret = VNN_Apply_Face_CPU(mVnnID, &in_image, &mFaceDetectionFrameData);
VNN_Get_Face_Attr(mVnnID, "_detection_data", &mFaceDetectionRect);
if (VNN_Result_Success == ret) {
ret = VNN_Apply_General_CPU(mVnnID, &in_image, &mFaceDetectionRect, &mImageArr);
drawMaskArr(used_img, mImageArr);
cv::imshow("Origin", used_img);
}
}
break;
}
case VNN_COMIC:
case VNN_CARTOON: {
if (mVnnID != 0) {
VNN_ImageArr out_img;
out_img.imgsNum = 1;
out_img.imgsArr[0].width = mOutImgWidth;
out_img.imgsArr[0].height = mOutImgHeight;
out_img.imgsArr[0].channels = 3;
out_img.imgsArr[0].pix_fmt = VNN_PIX_FMT_RGB888;
out_img.imgsArr[0].data = new unsigned char[mOutImgWidth * mOutImgHeight * 3];
ret = VNN_Apply_General_CPU(mVnnID, &in_image, nullptr, &out_img);
drawRGBImage(out_img.imgsArr[0]);
delete[]out_img.imgsArr[0].data;
}
cv::imshow("Origin", used_img);
break;
}
case VNN_OBJECT_CLASSIFICATION:
case VNN_SCENE_WEATHER: {
if (mVnnID != 0) {
ret = VNN_Apply_Classifying_CPU(mVnnID, &in_image, NULL, &mMultiClsDataArr);
drawClassificationResult(used_img, mMultiClsDataArr);
}
break;
}
case VNN_PERSON_ATTRIBUTE: {
if (mVnnID != 0 || mVnnPersonAttribID != 0) {
int _use_278pts = 1;
VNN_Set_Face_Attr(mVnnID, "_use_278pts", &_use_278pts);
ret = VNN_Apply_Face_CPU(mVnnID, &in_image, &mFaceDetectionFrameData);
VNN_Get_Face_Attr(mVnnID, "_detection_data", &mFaceDetectionRect);
ret = VNN_Apply_Classifying_CPU(mVnnID, &in_image, &mFaceDetectionRect, &mMultiClsDataArr);
drawClassificationResult(used_img, mMultiClsDataArr);
}
break;
}
case VNN_POSE_LANDMARKS: {
if (mVnnID != 0) {
mPoseDataArr.bodiesNum = 0;
ret = VNN_Apply_Pose_CPU(mVnnID, &in_image, &mPoseDataArr);
drawPoseResult(used_img, mPoseDataArr);
}
break;
}
default:
break;
}
return 0;
}
void drawFaceResult(cv::Mat used_img, VNN_FaceFrameDataArr faceDetectionFrameData) {
for (int faceIndex = 0; faceIndex < faceDetectionFrameData.facesNum; faceIndex++) {
auto left = faceDetectionFrameData.facesArr[faceIndex].faceRect.x0 * used_img.cols;
auto right = faceDetectionFrameData.facesArr[faceIndex].faceRect.x1 * used_img.cols;
auto bottom = faceDetectionFrameData.facesArr[faceIndex].faceRect.y0 * used_img.rows;
auto top = faceDetectionFrameData.facesArr[faceIndex].faceRect.y1 * used_img.rows;
//cv::rectangle(used_img, cvPoint(left, top), cvPoint(right, bottom), CV_RGB(10, 141, 255), 3, 8, 0);
cv::Point face_point;
for (int point_index = 0; point_index < faceDetectionFrameData.facesArr[faceIndex].faceLandmarksNum; point_index++) {
face_point.x = faceDetectionFrameData.facesArr[faceIndex].faceLandmarks[point_index].x * used_img.cols;
face_point.y = faceDetectionFrameData.facesArr[faceIndex].faceLandmarks[point_index].y * used_img.rows;
if (point_index < 104) {
cv::circle(used_img, face_point, 1, cv::Scalar(255, 0, 0), -1, cv::LINE_AA);
continue;
}
if (point_index < 238) {
cv::circle(used_img, face_point, 1, cv::Scalar(0, 255, 255), -1, cv::LINE_AA);
continue;
}
if (point_index < 278) {
cv::circle(used_img, face_point, 1, cv::Scalar(0, 255, 0), -1, cv::LINE_AA);
}
}
}
cv::imshow("Show", used_img);
//cv::imwrite("E:/face_keypoints.jpg", used_img);
}
void drawMaskArr(cv::Mat used_img, VNN_ImageArr mask_arr) {
uint32_t frame_width = used_img.cols;
uint32_t frame_height = used_img.rows;
cv::Mat show_img = cv::Mat(frame_height, frame_width, CV_8UC1);
memset(show_img.data, 0, frame_width * frame_height);
for (int i = 0; i < mask_arr.imgsNum; i++) {
float crop_left_f = mask_arr.imgsArr[i].rect.x0;
float crop_top_f = mask_arr.imgsArr[i].rect.y0;
float crop_right_f = mask_arr.imgsArr[i].rect.x1;
float crop_bottom_f = mask_arr.imgsArr[i].rect.y1;
int crop_left_int = int(crop_left_f * (frame_width - 1));
int crop_top_int = int(crop_top_f * (frame_height - 1));
int crop_right_int = int(crop_right_f * (frame_width - 1));
int crop_bottom_int = int(crop_bottom_f * (frame_height - 1));
int crop_width = crop_right_int - crop_left_int + 1;
int crop_height = crop_bottom_int - crop_top_int + 1;
cv::Mat out_mask_mat = cv::Mat(mask_arr.imgsArr[i].height, mask_arr.imgsArr[i].width, CV_8UC1);
cv::Mat crop_mask_mat = cv::Mat(crop_height, crop_width, CV_8UC1);
memcpy(out_mask_mat.data, mask_arr.imgsArr[i].data, mask_arr.imgsArr[i].height * mask_arr.imgsArr[i].width * sizeof(unsigned char));
cv::resize(out_mask_mat, crop_mask_mat, crop_mask_mat.size(), 0, 0);
unsigned char* used_mask = crop_mask_mat.data;
unsigned char* show_data = show_img.data;
for (int h = 0; h < crop_height; ++h) {
int start_ori_h = crop_top_int + h;
if (start_ori_h < 0) {