-
-
Notifications
You must be signed in to change notification settings - Fork 50
/
nvidia-move-filter.c
3219 lines (2951 loc) · 131 KB
/
nvidia-move-filter.c
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
#include "nvar-load.h"
#include <obs-module.h>
#include <util/threading.h>
#include <util/dstr.h>
#include "easing.h"
#include "move-transition.h"
#define BBOXES_COUNT 25
#define MAX_ACTIONS 40
#define ACTION_MOVE_SOURCE 0
#define ACTION_MOVE_VALUE 1
#define ACTION_ENABLE_FILTER 2
#define ACTION_SOURCE_VISIBILITY 3
#define ACTION_ATTACH_SOURCE 4
#define ATTACH_EYES 0
#define ATTACH_LEFT_EYE 1
#define ATTACH_RIGHT_EYE 2
#define ATTACH_EYEBROWS 3
#define ATTACH_LEFT_EYEBROW 4
#define ATTACH_RIGHT_EYEBROW 5
#define ATTACH_EARS 6
#define ATTACH_LEFT_EAR 7
#define ATTACH_RIGHT_EAR 8
#define ATTACH_NOSE 9
#define ATTACH_MOUTH 10
#define ATTACH_UPPER_LIP 11
#define ATTACH_LOWER_LIP 12
#define ATTACH_CHIN 13
#define ATTACH_JAW 14
#define ATTACH_FOREHEAD 15
#define SCENEITEM_PROPERTY_ALL 0
#define SCENEITEM_PROPERTY_POS 1
#define SCENEITEM_PROPERTY_POSX 2
#define SCENEITEM_PROPERTY_POSY 3
#define SCENEITEM_PROPERTY_SCALE 4
#define SCENEITEM_PROPERTY_SCALEX 5
#define SCENEITEM_PROPERTY_SCALEY 6
#define SCENEITEM_PROPERTY_ROT 7
#define SCENEITEM_PROPERTY_CROP_LEFT 8
#define SCENEITEM_PROPERTY_CROP_RIGHT 9
#define SCENEITEM_PROPERTY_CROP_TOP 11
#define SCENEITEM_PROPERTY_CROP_BOTTOM 10
#define FEATURE_BOUNDINGBOX 0
#define FEATURE_LANDMARK 1
#define FEATURE_POSE 2
#define FEATURE_EXPRESSION 3
#define FEATURE_GAZE 4
#define FEATURE_BODY 5
#define FEATURE_BOUNDINGBOX_LEFT 0
#define FEATURE_BOUNDINGBOX_HORIZONTAL_CENTER 1
#define FEATURE_BOUNDINGBOX_RIGHT 2
#define FEATURE_BOUNDINGBOX_WIDTH 3
#define FEATURE_BOUNDINGBOX_TOP 4
#define FEATURE_BOUNDINGBOX_VERTICAL_CENTER 5
#define FEATURE_BOUNDINGBOX_BOTOM 6
#define FEATURE_BOUNDINGBOX_HEIGHT 7
#define FEATURE_BOUNDINGBOX_TOP_LEFT 8
#define FEATURE_BOUNDINGBOX_TOP_CENTER 9
#define FEATURE_BOUNDINGBOX_TOP_RIGHT 10
#define FEATURE_BOUNDINGBOX_CENTER_RIGHT 11
#define FEATURE_BOUNDINGBOX_BOTTOM_RIGHT 12
#define FEATURE_BOUNDINGBOX_BOTTOM_CENTER 13
#define FEATURE_BOUNDINGBOX_BOTTOM_LEFT 14
#define FEATURE_BOUNDINGBOX_CENTER_LEFT 15
#define FEATURE_BOUNDINGBOX_CENTER 16
#define FEATURE_BOUNDINGBOX_SIZE 17
#define FEATURE_LANDMARK_X 0
#define FEATURE_LANDMARK_Y 1
#define FEATURE_LANDMARK_CONFIDENCE 2
#define FEATURE_LANDMARK_DISTANCE 3
#define FEATURE_LANDMARK_DIFF_X 4
#define FEATURE_LANDMARK_DIFF_Y 5
#define FEATURE_LANDMARK_ROT 6
#define FEATURE_LANDMARK_DIFF 7
#define FEATURE_LANDMARK_POS 8
#define FEATURE_THRESHOLD_NONE 0
#define FEATURE_THRESHOLD_ENABLE_OVER 1
#define FEATURE_THRESHOLD_ENABLE_UNDER 2
#define FEATURE_THRESHOLD_DISABLE_OVER 3
#define FEATURE_THRESHOLD_DISABLE_UNDER 4
#define FEATURE_THRESHOLD_ENABLE_OVER_DISABLE_UNDER 5
#define FEATURE_THRESHOLD_ENABLE_UNDER_DISABLE_OVER 6
#define FEATURE_POSE_X 0
#define FEATURE_POSE_Y 1
#define FEATURE_POSE_Z 2
#define FEATURE_POSE_W 3
#define FEATURE_GAZE_VECTOR 0
#define FEATURE_GAZE_VECTOR_PITCH 1
#define FEATURE_GAZE_VECTOR_YAW 2
#define FEATURE_GAZE_HEADTRANSLATION 3
#define FEATURE_GAZE_HEADTRANSLATION_X 4
#define FEATURE_GAZE_HEADTRANSLATION_Y 5
#define FEATURE_GAZE_HEADTRANSLATION_Z 6
#define FEATURE_GAZE_DIRECTION_CENTER_POINT 7
#define FEATURE_GAZE_DIRECTION_CENTER_POINT_X 8
#define FEATURE_GAZE_DIRECTION_CENTER_POINT_Y 9
#define FEATURE_GAZE_DIRECTION_CENTER_POINT_Z 10
#define FEATURE_GAZE_DIRECTION_VECTOR 11
#define FEATURE_GAZE_DIRECTION_VECTOR_X 12
#define FEATURE_GAZE_DIRECTION_VECTOR_Y 13
#define FEATURE_GAZE_DIRECTION_VECTOR_Z 14
#define FEATURE_EXPRESSION_SINGLE 0
#define FEATURE_EXPRESSION_VECTOR 1
#define FEATURE_EXPRESSION_ADD 2
#define FEATURE_EXPRESSION_SUBSTRACT 3
#define FEATURE_EXPRESSION_DISTANCE 4
#define FEATURE_EXPRESSION_AVG 5
#define BODY_CONFIDENCE 0
#define BODY_2D_POSX 1
#define BODY_2D_POSY 2
#define BODY_2D_DISTANCE 3
#define BODY_2D_ROT 4
#define BODY_2D_DIFF_X 5
#define BODY_2D_DIFF_Y 6
#define BODY_2D_DIFF 7
#define BODY_2D_POS 8
#define BODY_3D_POSX 9
#define BODY_3D_POSY 10
#define BODY_3D_POSZ 11
#define BODY_3D_DISTANCE 12
#define BODY_3D_DIFF_X 13
#define BODY_3D_DIFF_Y 14
#define BODY_3D_DIFF_Z 15
#define BODY_3D_POS 16
#define BODY_3D_DIFF 17
#define BODY_ANGLE_X 18
#define BODY_ANGLE_Y 19
#define BODY_ANGLE_Z 20
#define BODY_ANGLE 21
bool nvar_loaded = false;
bool nvar_new_sdk = false;
struct nvidia_move_action {
uint32_t action;
obs_weak_source_t *target;
char *name; //scene item name or setting name
bool is_int;
uint32_t property;
float diff;
float diff2;
float factor;
float factor2;
uint32_t feature;
uint32_t feature_property;
int32_t feature_number[4];
float threshold;
float required_confidence;
float easing;
float previous_float;
struct vec2 previous_vec2;
bool disabled;
};
struct nvidia_move_info {
obs_source_t *source;
DARRAY(struct nvidia_move_action) actions;
NvAR_FeatureHandle faceDetectHandle;
NvAR_FeatureHandle landmarkHandle;
NvAR_FeatureHandle expressionHandle;
NvAR_FeatureHandle gazeHandle;
NvAR_FeatureHandle bodyHandle;
CUstream stream; // CUDA stream
char *last_error;
bool got_new_frame;
bool processing_stop;
bool target_valid;
bool images_allocated;
bool initial_render;
bool processed_frame;
uint32_t width;
uint32_t height;
NvCVImage *src_img; // src img in obs format (RGBA ?) on GPU
NvCVImage *BGR_src_img; // src img in BGR on GPU
NvCVImage *stage; // planar stage img used for transfer to texture
DARRAY(float) landmarks_confidence;
DARRAY(NvAR_Point2f) landmarks;
DARRAY(NvAR_Point2f) gaze_output_landmarks;
DARRAY(float) bboxes_confidence;
NvAR_BBoxes bboxes;
NvAR_Quaternion pose;
DARRAY(float) expressions;
float gaze_angles_vector[2];
float head_translation[3];
NvAR_Point3f gaze_direction[2];
DARRAY(float) keypoints_confidence;
DARRAY(NvAR_Point2f) keypoints;
DARRAY(NvAR_Point3f) keypoints3D;
DARRAY(NvAR_Quaternion) joint_angles;
gs_texrender_t *render;
gs_texrender_t *render_unorm;
enum gs_color_space space;
gs_effect_t *effect;
gs_eparam_t *image_param;
gs_eparam_t *multiplier_param;
};
static const char *nv_move_name(void *unused)
{
UNUSED_PARAMETER(unused);
return obs_module_text("NvidiaMoveFilter");
}
static bool nv_move_log_error(struct nvidia_move_info *filter, NvCV_Status nvErr, const char *function)
{
if (nvErr == NVCV_SUCCESS)
return false;
const char *errString = NvCV_GetErrorStringFromCode(nvErr);
if (filter->last_error && strcmp(errString, filter->last_error) == 0)
return true;
blog(LOG_ERROR, "[Move Transition] Error in %s; error %i: %s", function, nvErr, errString);
bfree(filter->last_error);
filter->last_error = bstrdup(errString);
return true;
}
static void nv_move_feature_handle(struct nvidia_move_info *filter, NvAR_FeatureHandle handle)
{
if (nv_move_log_error(filter, NvAR_SetString(handle, NvAR_Parameter_Config(ModelDir), ""), "Set ModelDir"))
return;
if (nv_move_log_error(filter, NvAR_SetCudaStream(handle, NvAR_Parameter_Config(CUDAStream), filter->stream),
"Set CUDAStream"))
return;
if (filter->BGR_src_img) {
if (nv_move_log_error(filter,
NvAR_SetObject(handle, NvAR_Parameter_Input(Image), filter->BGR_src_img, sizeof(NvCVImage)),
"Set Image"))
return;
}
if (!filter->bboxes.max_boxes) {
filter->bboxes.boxes = (struct NvAR_Rect *)bzalloc(sizeof(struct NvAR_Rect) * BBOXES_COUNT);
filter->bboxes.max_boxes = BBOXES_COUNT;
filter->bboxes.num_boxes = 0;
}
NvAR_SetObject(handle, NvAR_Parameter_Output(BoundingBoxes), &filter->bboxes, sizeof(NvAR_BBoxes));
}
static void nv_move_landmarks(struct nvidia_move_info *filter, NvAR_FeatureHandle handle)
{
unsigned int OUTPUT_SIZE_KPTS = 0;
NvCV_Status nvErr = NvAR_GetU32(handle, NvAR_Parameter_Config(Landmarks_Size), &OUTPUT_SIZE_KPTS);
if (nvErr != NVCV_SUCCESS)
return;
da_resize(filter->landmarks, OUTPUT_SIZE_KPTS);
nvErr = NvAR_SetObject(handle, NvAR_Parameter_Output(Landmarks), filter->landmarks.array, sizeof(NvAR_Point2f));
unsigned int OUTPUT_SIZE_KPTS_CONF = 0;
nvErr = NvAR_GetU32(handle, NvAR_Parameter_Config(LandmarksConfidence_Size), &OUTPUT_SIZE_KPTS_CONF);
if (nvErr == NVCV_SUCCESS)
da_resize(filter->landmarks_confidence, OUTPUT_SIZE_KPTS_CONF);
else
da_resize(filter->landmarks_confidence, OUTPUT_SIZE_KPTS);
nvErr = NvAR_SetF32Array(handle, NvAR_Parameter_Output(LandmarksConfidence), filter->landmarks_confidence.array,
(int)filter->landmarks_confidence.num);
}
static bool get_expression_value(struct nvidia_move_info *filter, int32_t expression, float *value)
{
if (expression >= 0) {
*value = filter->expressions.array[expression];
} else if (expression == -1) {
return false;
} else if (expression > -14) {
int p = expression * -2 - 4;
*value = (filter->expressions.array[p] + filter->expressions.array[p + 1]) / 2.0f;
} else if (expression == -14) { // jawSideways
*value = filter->expressions.array[25] - filter->expressions.array[27];
} else if (expression == -15) { // mouthSideways
*value = filter->expressions.array[34] - filter->expressions.array[40];
} else if (expression == -18) { // eyeLookLeft
*value = filter->expressions.array[16] + // eyeLookOut_L
filter->expressions.array[15]; // eyeLookIn_R
} else if (expression == -21) { // eyeLookRight
*value = filter->expressions.array[17] + // eyeLookOut_R
filter->expressions.array[14]; // eyeLookIn_L
} else if (expression > -28) {
int p = expression * -2 - 3;
*value = (filter->expressions.array[p] + filter->expressions.array[p + 1]) / 2.0f;
} else if (expression == -28) { // eyeLookSideways
*value = (filter->expressions.array[16] + // eyeLookOut_L
filter->expressions.array[15]) - // eyeLookIn_R
(filter->expressions.array[17] + // eyeLookOut_R
filter->expressions.array[14]); // eyeLookIn_L
} else if (expression == -29) { // eyeLookUpDown
*value = (filter->expressions.array[18] + // eyeLookUp_L
filter->expressions.array[19]) - // eyeLookUp_R
(filter->expressions.array[12] + // eyeLookDown_L
filter->expressions.array[13]); // eyeLookDown_R
} else if (expression == -30) { // eyeLookSideways_L
*value = filter->expressions.array[16] - // eyeLookOut_L
filter->expressions.array[14]; // eyeLookIn_L
} else if (expression == -31) { // eyeLookSideways_R
*value = filter->expressions.array[17] - // eyeLookOut_R
filter->expressions.array[15]; // eyeLookIn_R
} else if (expression == -32) { //eyeLookUpDown_L
*value = filter->expressions.array[18] - // eyeLookUp_L
filter->expressions.array[12]; // eyeLookDown_L
} else if (expression == -33) { // eyeLookUpDown_R
*value = filter->expressions.array[19] - // eyeLookUp_R
filter->expressions.array[13]; // eyeLookDown_R
} else {
return false;
}
return true;
}
static bool nv_move_action_get_float(struct nvidia_move_info *filter, struct nvidia_move_action *action, bool easing, float *v)
{
float value = 0.0f;
bool success = false;
if (action->feature == FEATURE_BOUNDINGBOX && filter->bboxes.max_boxes && filter->bboxes.num_boxes) {
if (filter->bboxes_confidence.array && filter->bboxes_confidence.array[0] < action->required_confidence) {
} else if (action->feature_property == FEATURE_BOUNDINGBOX_LEFT) {
value = filter->bboxes.boxes[0].x;
success = true;
} else if (action->feature_property == FEATURE_BOUNDINGBOX_HORIZONTAL_CENTER) {
value = filter->bboxes.boxes[0].x + filter->bboxes.boxes[0].width / 2.0f;
success = true;
} else if (action->feature_property == FEATURE_BOUNDINGBOX_RIGHT) {
value = filter->bboxes.boxes[0].x + filter->bboxes.boxes[0].width;
success = true;
} else if (action->feature_property == FEATURE_BOUNDINGBOX_WIDTH) {
value = filter->bboxes.boxes[0].width;
success = true;
} else if (action->feature_property == FEATURE_BOUNDINGBOX_TOP) {
value = filter->bboxes.boxes[0].y;
success = true;
} else if (action->feature_property == FEATURE_BOUNDINGBOX_VERTICAL_CENTER) {
value = filter->bboxes.boxes[0].y + filter->bboxes.boxes[0].height / 2.0f;
success = true;
} else if (action->feature_property == FEATURE_BOUNDINGBOX_BOTOM) {
value = filter->bboxes.boxes[0].y + filter->bboxes.boxes[0].height;
success = true;
} else if (action->feature_property == FEATURE_BOUNDINGBOX_HEIGHT) {
value = filter->bboxes.boxes[0].height;
success = true;
} else {
success = false;
}
} else if (action->feature == FEATURE_LANDMARK && filter->landmarks.num) {
if (action->feature_number[0] >= (int32_t)filter->landmarks.num) {
} else if (filter->landmarks_confidence.array[action->feature_number[0]] < action->required_confidence) {
} else if (action->feature_property == FEATURE_LANDMARK_X) {
value = filter->landmarks.array[action->feature_number[0]].x;
success = true;
} else if (action->feature_property == FEATURE_LANDMARK_Y) {
value = filter->landmarks.array[action->feature_number[0]].y;
success = true;
} else if (action->feature_property == FEATURE_LANDMARK_CONFIDENCE) {
value = filter->landmarks_confidence.array[action->feature_number[0]];
success = true;
} else if (action->feature_number[1] >= (int32_t)filter->landmarks.num) {
} else if (action->feature_property == FEATURE_LANDMARK_DISTANCE) {
float x = filter->landmarks.array[action->feature_number[0]].x -
filter->landmarks.array[action->feature_number[1]].x;
float y = filter->landmarks.array[action->feature_number[0]].y -
filter->landmarks.array[action->feature_number[1]].y;
value = sqrtf(x * x + y * y);
success = true;
} else if (action->feature_property == FEATURE_LANDMARK_DIFF_X) {
value = filter->landmarks.array[action->feature_number[1]].x -
filter->landmarks.array[action->feature_number[0]].x;
success = true;
} else if (action->feature_property == FEATURE_LANDMARK_DIFF_Y) {
value = filter->landmarks.array[action->feature_number[1]].y -
filter->landmarks.array[action->feature_number[0]].y;
success = true;
} else if (action->feature_property == FEATURE_LANDMARK_ROT) {
value = DEG(atan2f((filter->landmarks.array[action->feature_number[1]].y -
filter->landmarks.array[action->feature_number[0]].y),
(filter->landmarks.array[action->feature_number[1]].x -
filter->landmarks.array[action->feature_number[0]].x)));
success = true;
}
} else if (action->feature == FEATURE_POSE) {
if (action->feature_property == FEATURE_POSE_X) {
value = filter->pose.x;
success = true;
} else if (action->feature_property == FEATURE_POSE_Y) {
value = filter->pose.y;
success = true;
} else if (action->feature_property == FEATURE_POSE_Z) {
value = filter->pose.z;
success = true;
} else if (action->feature_property == FEATURE_POSE_W) {
value = filter->pose.w;
success = true;
}
} else if (action->feature == FEATURE_EXPRESSION && filter->expressions.num) {
if (action->feature_property == FEATURE_EXPRESSION_SINGLE) {
success = get_expression_value(filter, action->feature_number[0], &value);
if (success)
value *= action->factor;
} else if (action->feature_property != FEATURE_EXPRESSION_VECTOR) {
float a = 0.0f;
float b = 0.0f;
success = get_expression_value(filter, action->feature_number[0], &a) &&
get_expression_value(filter, action->feature_number[1], &b);
if (success) {
a *= action->factor;
b *= action->factor2;
if (action->feature_property == FEATURE_EXPRESSION_ADD) {
value = a + b;
} else if (action->feature_property == FEATURE_EXPRESSION_SUBSTRACT) {
value = a - b;
} else if (action->feature_property == FEATURE_EXPRESSION_DISTANCE) {
value = fabsf(a - b);
} else if (action->feature_property == FEATURE_EXPRESSION_AVG) {
value = (a + b) / 2.0f;
}
}
}
} else if (action->feature == FEATURE_GAZE) {
if (action->feature_property == FEATURE_GAZE_VECTOR_PITCH) {
value = DEG(filter->gaze_angles_vector[0]);
success = true;
} else if (action->feature_property == FEATURE_GAZE_VECTOR_YAW) {
value = DEG(filter->gaze_angles_vector[1]);
success = true;
} else if (action->feature_property == FEATURE_GAZE_HEADTRANSLATION_X) {
value = filter->head_translation[0];
success = true;
} else if (action->feature_property == FEATURE_GAZE_HEADTRANSLATION_Y) {
value = filter->head_translation[1];
success = true;
} else if (action->feature_property == FEATURE_GAZE_HEADTRANSLATION_Z) {
value = filter->head_translation[2];
success = true;
} else if (action->feature_property == FEATURE_GAZE_DIRECTION_CENTER_POINT_X) {
value = filter->gaze_direction[0].x;
success = true;
} else if (action->feature_property == FEATURE_GAZE_DIRECTION_CENTER_POINT_Y) {
value = filter->gaze_direction[0].y;
success = true;
} else if (action->feature_property == FEATURE_GAZE_DIRECTION_CENTER_POINT_Z) {
value = filter->gaze_direction[0].z;
success = true;
} else if (action->feature_property == FEATURE_GAZE_DIRECTION_VECTOR_X) {
value = filter->gaze_direction[1].x;
success = true;
} else if (action->feature_property == FEATURE_GAZE_DIRECTION_VECTOR_Y) {
value = filter->gaze_direction[1].y;
success = true;
} else if (action->feature_property == FEATURE_GAZE_DIRECTION_VECTOR_Z) {
value = filter->gaze_direction[1].z;
success = true;
}
} else if (action->feature == FEATURE_BODY && filter->keypoints.num) {
if (action->feature_number[0] >= (int32_t)filter->keypoints.num) {
} else if (filter->keypoints_confidence.array[action->feature_number[0]] < action->required_confidence) {
} else if (action->feature_property == BODY_CONFIDENCE) {
value = filter->keypoints_confidence.array[action->feature_number[0]];
success = true;
} else if (action->feature_property == BODY_2D_POSX) {
value = filter->keypoints.array[action->feature_number[0]].x;
success = true;
} else if (action->feature_property == BODY_2D_POSY) {
value = filter->keypoints.array[action->feature_number[0]].y;
success = true;
} else if (action->feature_property == BODY_3D_POSX) {
value = filter->keypoints3D.array[action->feature_number[0]].x;
success = true;
} else if (action->feature_property == BODY_3D_POSY) {
value = filter->keypoints3D.array[action->feature_number[0]].y;
success = true;
} else if (action->feature_property == BODY_3D_POSZ) {
value = filter->keypoints3D.array[action->feature_number[0]].z;
success = true;
} else if (action->feature_property == BODY_ANGLE_X) {
filter->joint_angles.array[action->feature_number[0]].x;
success = true;
} else if (action->feature_property == BODY_ANGLE_Y) {
filter->joint_angles.array[action->feature_number[0]].y;
success = true;
} else if (action->feature_property == BODY_ANGLE_Z) {
filter->joint_angles.array[action->feature_number[0]].z;
success = true;
} else if (action->feature_number[1] >= (int32_t)filter->keypoints.num) {
} else if (action->feature_property == BODY_2D_DISTANCE) {
float x = filter->keypoints.array[action->feature_number[0]].x -
filter->keypoints.array[action->feature_number[1]].x;
float y = filter->keypoints.array[action->feature_number[0]].y -
filter->keypoints.array[action->feature_number[1]].y;
value = sqrtf(x * x + y * y);
success = true;
} else if (action->feature_property == BODY_2D_ROT) {
value = DEG(atan2f((filter->keypoints.array[action->feature_number[1]].y -
filter->keypoints.array[action->feature_number[0]].y),
(filter->keypoints.array[action->feature_number[1]].x -
filter->keypoints.array[action->feature_number[0]].x)));
success = true;
} else if (action->feature_property == BODY_2D_DIFF_X) {
value = filter->keypoints.array[action->feature_number[1]].x -
filter->keypoints.array[action->feature_number[0]].x;
success = true;
} else if (action->feature_property == BODY_2D_DIFF_Y) {
value = filter->keypoints.array[action->feature_number[1]].y -
filter->keypoints.array[action->feature_number[0]].y;
success = true;
} else if (action->feature_property == BODY_3D_DISTANCE) {
float x = filter->keypoints3D.array[action->feature_number[0]].x -
filter->keypoints3D.array[action->feature_number[1]].x;
float y = filter->keypoints3D.array[action->feature_number[0]].y -
filter->keypoints3D.array[action->feature_number[1]].y;
float z = filter->keypoints3D.array[action->feature_number[0]].z -
filter->keypoints3D.array[action->feature_number[1]].z;
value = sqrtf(x * x + y * y);
value = sqrtf(value * value + z * z);
success = true;
} else if (action->feature_property == BODY_3D_DIFF_X) {
value = filter->keypoints3D.array[action->feature_number[1]].x -
filter->keypoints3D.array[action->feature_number[0]].x;
success = true;
} else if (action->feature_property == BODY_3D_DIFF_Y) {
value = filter->keypoints3D.array[action->feature_number[1]].y -
filter->keypoints3D.array[action->feature_number[0]].y;
success = true;
} else if (action->feature_property == BODY_3D_DIFF_Z) {
value = filter->keypoints3D.array[action->feature_number[1]].z -
filter->keypoints3D.array[action->feature_number[0]].z;
success = true;
}
}
if (action->feature != FEATURE_EXPRESSION)
value *= action->factor;
value += action->diff;
if (success && easing) {
value = action->previous_float * action->easing + value * (1.0f - action->easing);
action->previous_float = value;
}
*v = value;
return success;
}
static bool nv_move_action_get_vec2(struct nvidia_move_info *filter, struct nvidia_move_action *action, bool easing,
struct vec2 *value)
{
bool success = false;
value->x = 0.0f;
value->y = 0.0f;
if (action->feature == FEATURE_BOUNDINGBOX && filter->bboxes.max_boxes && filter->bboxes.num_boxes) {
if (filter->bboxes_confidence.array && filter->bboxes_confidence.array[0] < action->required_confidence) {
} else if (action->feature_property == FEATURE_BOUNDINGBOX_TOP_LEFT) {
value->x = filter->bboxes.boxes[0].x;
value->y = filter->bboxes.boxes[0].y;
success = true;
} else if (action->feature_property == FEATURE_BOUNDINGBOX_TOP_CENTER) {
value->x = filter->bboxes.boxes[0].x + filter->bboxes.boxes[0].width / 2.0f;
value->y = filter->bboxes.boxes[0].y;
success = true;
} else if (action->feature_property == FEATURE_BOUNDINGBOX_TOP_RIGHT) {
value->x = filter->bboxes.boxes[0].x + filter->bboxes.boxes[0].width;
value->y = filter->bboxes.boxes[0].y;
success = true;
} else if (action->feature_property == FEATURE_BOUNDINGBOX_CENTER_RIGHT) {
value->x = filter->bboxes.boxes[0].x + filter->bboxes.boxes[0].width;
value->y = filter->bboxes.boxes[0].y + filter->bboxes.boxes[0].height / 2.0f;
success = true;
} else if (action->feature_property == FEATURE_BOUNDINGBOX_BOTTOM_RIGHT) {
value->x = filter->bboxes.boxes[0].x + filter->bboxes.boxes[0].width;
value->y = filter->bboxes.boxes[0].y + filter->bboxes.boxes[0].height;
success = true;
} else if (action->feature_property == FEATURE_BOUNDINGBOX_BOTTOM_CENTER) {
value->x = filter->bboxes.boxes[0].x + filter->bboxes.boxes[0].width / 2.0f;
value->y = filter->bboxes.boxes[0].y + filter->bboxes.boxes[0].height;
success = true;
} else if (action->feature_property == FEATURE_BOUNDINGBOX_BOTTOM_LEFT) {
value->x = filter->bboxes.boxes[0].x;
value->y = filter->bboxes.boxes[0].y + filter->bboxes.boxes[0].height;
success = true;
} else if (action->feature_property == FEATURE_BOUNDINGBOX_CENTER_LEFT) {
value->x = filter->bboxes.boxes[0].x;
value->y = filter->bboxes.boxes[0].y + filter->bboxes.boxes[0].height / 2.0f;
success = true;
} else if (action->feature_property == FEATURE_BOUNDINGBOX_CENTER) {
value->x = filter->bboxes.boxes[0].x + filter->bboxes.boxes[0].width / 2.0f;
value->y = filter->bboxes.boxes[0].y + filter->bboxes.boxes[0].height / 2.0f;
success = true;
} else if (action->feature_property == FEATURE_BOUNDINGBOX_SIZE) {
value->x = filter->bboxes.boxes[0].width;
value->y = filter->bboxes.boxes[0].height;
success = true;
}
} else if (action->feature == FEATURE_LANDMARK && filter->landmarks.num) {
if (action->feature_number[0] >= (int32_t)filter->landmarks.num) {
} else if (filter->landmarks_confidence.array[action->feature_number[0]] < action->required_confidence) {
} else if (action->feature_property == FEATURE_LANDMARK_POS) {
value->x = filter->landmarks.array[action->feature_number[0]].x;
value->y = filter->landmarks.array[action->feature_number[0]].y;
success = true;
} else if (action->feature_number[1] >= (int32_t)filter->landmarks.num) {
} else if (action->feature_property == FEATURE_LANDMARK_DIFF) {
value->x = filter->landmarks.array[action->feature_number[1]].x -
filter->landmarks.array[action->feature_number[0]].x;
value->y = filter->landmarks.array[action->feature_number[1]].y -
filter->landmarks.array[action->feature_number[0]].y;
success = true;
}
} else if (action->feature == FEATURE_GAZE) {
if (action->feature_property == FEATURE_GAZE_VECTOR) {
value->x = DEG(filter->gaze_angles_vector[0]);
value->y = DEG(filter->gaze_angles_vector[1]);
success = true;
}
} else if (action->feature == FEATURE_EXPRESSION && filter->expressions.num) {
if (action->feature_property == FEATURE_EXPRESSION_VECTOR) {
success = get_expression_value(filter, action->feature_number[0], &value->x) &&
get_expression_value(filter, action->feature_number[1], &value->y);
}
} else if (action->feature == FEATURE_BODY && filter->keypoints.num) {
if (action->feature_number[0] >= (int32_t)filter->keypoints.num) {
} else if (filter->keypoints_confidence.array[action->feature_number[0]] < action->required_confidence) {
} else if (action->feature_property == BODY_2D_POS) {
value->x = filter->keypoints.array[action->feature_number[0]].x;
value->y = filter->keypoints.array[action->feature_number[0]].y;
success = true;
} else if (action->feature_number[1] >= (int32_t)filter->keypoints.num) {
} else if (filter->keypoints_confidence.array[action->feature_number[1]] < action->required_confidence) {
} else if (action->feature_property == BODY_2D_DIFF) {
value->x = filter->keypoints.array[action->feature_number[1]].x -
filter->keypoints.array[action->feature_number[0]].x;
value->y = filter->keypoints.array[action->feature_number[1]].y -
filter->keypoints.array[action->feature_number[0]].y;
success = true;
}
}
value->x *= action->factor;
value->x += action->diff;
value->y *= action->factor2;
value->y += action->diff2;
if (success && easing) {
value->x = action->previous_vec2.x * action->easing + value->x * (1.0f - action->easing);
action->previous_vec2.x = value->x;
value->y = action->previous_vec2.y * action->easing + value->y * (1.0f - action->easing);
action->previous_vec2.y = value->y;
}
return success;
}
static void nv_move_update(void *data, obs_data_t *settings)
{
struct nvidia_move_info *filter = (struct nvidia_move_info *)data;
size_t actions = (size_t)obs_data_get_int(settings, "actions");
if (actions < filter->actions.num) {
for (size_t i = actions; i < filter->actions.num; i++) {
struct nvidia_move_action *action = filter->actions.array + i;
obs_weak_source_release(action->target);
action->target = NULL;
bfree(action->name);
action->name = NULL;
}
}
da_resize(filter->actions, actions);
uint64_t feature_flags = 0;
struct dstr name = {0};
for (size_t i = 1; i <= actions; i++) {
struct nvidia_move_action *action = filter->actions.array + i - 1;
dstr_printf(&name, "action_%lld_disabled", i);
action->disabled = obs_data_get_bool(settings, name.array);
dstr_printf(&name, "action_%lld_action", i);
action->action = (uint32_t)obs_data_get_int(settings, name.array);
obs_weak_source_release(action->target);
action->target = NULL;
bfree(action->name);
action->name = NULL;
if (action->action == ACTION_MOVE_SOURCE || action->action == ACTION_SOURCE_VISIBILITY ||
action->action == ACTION_ATTACH_SOURCE) {
dstr_printf(&name, "action_%lld_scene", i);
const char *scene_name = obs_data_get_string(settings, name.array);
obs_source_t *source = obs_get_source_by_name(scene_name);
if (source) {
if (obs_source_is_scene(source) || obs_source_is_group(source))
action->target = obs_source_get_weak_source(source);
obs_source_release(source);
}
dstr_printf(&name, "action_%lld_sceneitem", i);
action->name = bstrdup(obs_data_get_string(settings, name.array));
}
if (action->action == ACTION_MOVE_SOURCE) {
dstr_printf(&name, "action_%lld_sceneitem_property", i);
action->property = (uint32_t)obs_data_get_int(settings, name.array);
} else if (action->action == ACTION_ENABLE_FILTER || action->action == ACTION_SOURCE_VISIBILITY) {
dstr_printf(&name, "action_%lld_enable", i);
action->property = (uint32_t)obs_data_get_int(settings, name.array);
dstr_printf(&name, "action_%lld_threshold", i);
action->threshold = (float)obs_data_get_double(settings, name.array);
} else if (action->action == ACTION_ATTACH_SOURCE) {
dstr_printf(&name, "action_%lld_attach", i);
action->property = (uint32_t)obs_data_get_int(settings, name.array);
}
if (action->action == ACTION_MOVE_VALUE || action->action == ACTION_ENABLE_FILTER) {
dstr_printf(&name, "action_%lld_source", i);
const char *source_name = obs_data_get_string(settings, name.array);
obs_source_t *source = obs_get_source_by_name(source_name);
if (source) {
dstr_printf(&name, "action_%lld_filter", i);
const char *filter_name = obs_data_get_string(settings, name.array);
obs_source_t *f = obs_source_get_filter_by_name(source, filter_name);
if (f || action->action == ACTION_ENABLE_FILTER) {
obs_source_release(source);
source = f;
}
action->target = obs_source_get_weak_source(source);
if (action->action == ACTION_MOVE_VALUE) {
dstr_printf(&name, "action_%lld_property", i);
action->name = bstrdup(obs_data_get_string(settings, name.array));
obs_properties_t *sp = obs_source_properties(source);
obs_property_t *p = obs_properties_get(sp, action->name);
action->is_int = (obs_property_get_type(p) == OBS_PROPERTY_INT);
obs_properties_destroy(sp);
}
obs_source_release(source);
}
}
if (action->action == ACTION_ATTACH_SOURCE) {
action->feature = FEATURE_LANDMARK;
} else {
dstr_printf(&name, "action_%lld_feature", i);
action->feature = (uint32_t)obs_data_get_int(settings, name.array);
}
feature_flags |= (1ull << action->feature);
if (action->feature == FEATURE_BOUNDINGBOX) {
dstr_printf(&name, "action_%lld_bounding_box", i);
action->feature_property = (uint32_t)obs_data_get_int(settings, name.array);
dstr_printf(&name, "action_%lld_required_confidence", i);
action->required_confidence = (float)obs_data_get_double(settings, name.array);
} else if (action->feature == FEATURE_LANDMARK) {
dstr_printf(&name, "action_%lld_landmark", i);
action->feature_property = (uint32_t)obs_data_get_int(settings, name.array);
dstr_printf(&name, "action_%lld_landmark_1", i);
if (obs_data_get_int(settings, name.array))
action->feature_number[0] = (int32_t)obs_data_get_int(settings, name.array) - 1;
dstr_printf(&name, "action_%lld_landmark_2", i);
if (obs_data_get_int(settings, name.array))
action->feature_number[1] = (int32_t)obs_data_get_int(settings, name.array) - 1;
dstr_printf(&name, "action_%lld_required_confidence", i);
action->required_confidence = (float)obs_data_get_double(settings, name.array);
} else if (action->feature == FEATURE_POSE) {
dstr_printf(&name, "action_%lld_pose", i);
action->feature_property = (uint32_t)obs_data_get_int(settings, name.array);
} else if (action->feature == FEATURE_EXPRESSION) {
dstr_printf(&name, "action_%lld_expression_property", i);
action->feature_property = (uint32_t)obs_data_get_int(settings, name.array);
dstr_printf(&name, "action_%lld_expression", i);
long long old = obs_data_get_int(settings, name.array);
if (old) {
obs_data_unset_user_value(settings, name.array);
dstr_printf(&name, "action_%lld_expression_1", i);
obs_data_set_int(settings, name.array, old);
}
dstr_printf(&name, "action_%lld_expression_1", i);
action->feature_number[0] = (int32_t)obs_data_get_int(settings, name.array) - 1;
dstr_printf(&name, "action_%lld_expression_2", i);
action->feature_number[1] = (int32_t)obs_data_get_int(settings, name.array) - 1;
} else if (action->feature == FEATURE_GAZE) {
dstr_printf(&name, "action_%lld_gaze", i);
action->feature_property = (int32_t)obs_data_get_int(settings, name.array);
} else if (action->feature == FEATURE_BODY) {
dstr_printf(&name, "action_%lld_body", i);
action->feature_property = (int32_t)obs_data_get_int(settings, name.array);
dstr_printf(&name, "action_%lld_body_1", i);
action->feature_number[0] = (int32_t)obs_data_get_int(settings, name.array);
dstr_printf(&name, "action_%lld_body_2", i);
action->feature_number[1] = (int32_t)obs_data_get_int(settings, name.array);
dstr_printf(&name, "action_%lld_required_confidence", i);
action->required_confidence = (float)obs_data_get_double(settings, name.array);
}
dstr_printf(&name, "action_%lld_factor2", i);
obs_data_set_default_double(settings, name.array, 100.0f);
dstr_printf(&name, "action_%lld_factor", i);
obs_data_set_default_double(settings, name.array, 100.0f);
action->factor = (float)obs_data_get_double(settings, name.array) / 100.0f;
dstr_printf(&name, "action_%lld_factor2", i);
action->factor2 = (float)obs_data_get_double(settings, name.array) / 100.0f;
dstr_printf(&name, "action_%lld_diff", i);
action->diff = (float)obs_data_get_double(settings, name.array);
dstr_printf(&name, "action_%lld_diff2", i);
action->diff2 = (float)obs_data_get_double(settings, name.array);
dstr_printf(&name, "action_%lld_easing", i);
action->easing = ExponentialEaseOut((float)obs_data_get_double(settings, name.array) / 100.0f);
if (action->action != ACTION_ATTACH_SOURCE) {
nv_move_action_get_float(filter, action, false, &action->previous_float);
nv_move_action_get_vec2(filter, action, false, &action->previous_vec2);
}
}
dstr_free(&name);
bfree(filter->last_error);
filter->last_error = NULL;
if (feature_flags & (1ull << FEATURE_BODY)) {
if (!filter->bodyHandle) {
if (nv_move_log_error(filter, NvAR_Create(NvAR_Feature_BodyPoseEstimation, &filter->bodyHandle),
"Create body"))
return;
nv_move_feature_handle(filter, filter->bodyHandle);
unsigned int numKeyPoints = 0;
NvCV_Status nvErr = NvAR_GetU32(filter->bodyHandle, NvAR_Parameter_Config(NumKeyPoints), &numKeyPoints);
if (nvErr == NVCV_SUCCESS) {
da_resize(filter->keypoints, numKeyPoints);
nvErr = NvAR_SetObject(filter->bodyHandle, NvAR_Parameter_Output(KeyPoints),
filter->keypoints.array, sizeof(NvAR_Point2f));
da_resize(filter->keypoints3D, numKeyPoints);
nvErr = NvAR_SetObject(filter->bodyHandle, NvAR_Parameter_Output(KeyPoints3D),
filter->keypoints3D.array, sizeof(NvAR_Point3f));
da_resize(filter->joint_angles, numKeyPoints);
nvErr = NvAR_SetObject(filter->bodyHandle, NvAR_Parameter_Output(JointAngles),
filter->joint_angles.array, sizeof(NvAR_Quaternion));
da_resize(filter->keypoints_confidence, numKeyPoints);
nvErr = NvAR_SetF32Array(filter->bodyHandle, NvAR_Parameter_Output(KeyPointsConfidence),
filter->keypoints_confidence.array, sizeof(float));
} else {
nv_move_log_error(filter, nvErr, "NumKeyPoints");
}
if (nv_move_log_error(filter, NvAR_Load(filter->bodyHandle), "Load body"))
return;
}
} else if (filter->bodyHandle) {
nv_move_log_error(filter, NvAR_Destroy(filter->bodyHandle), "Destroy body");
filter->bodyHandle = NULL;
}
if (feature_flags & (1ull << FEATURE_GAZE)) {
if (!filter->gazeHandle) {
if (nv_move_log_error(filter, NvAR_Create(NvAR_Feature_GazeRedirection, &filter->gazeHandle),
"Create gaze"))
return;
nv_move_feature_handle(filter, filter->gazeHandle);
nv_move_landmarks(filter, filter->gazeHandle);
NvAR_SetObject(filter->gazeHandle, NvAR_Parameter_Output(HeadPose), &filter->pose, sizeof(NvAR_Quaternion));
NvAR_SetF32Array(filter->gazeHandle, NvAR_Parameter_Output(OutputGazeVector), filter->gaze_angles_vector,
2);
NvAR_SetF32Array(filter->gazeHandle, NvAR_Parameter_Output(OutputHeadTranslation), filter->head_translation,
3);
NvAR_SetObject(filter->gazeHandle, NvAR_Parameter_Output(GazeDirection), &filter->gaze_direction,
sizeof(NvAR_Point3f));
da_resize(filter->gaze_output_landmarks, filter->landmarks.num);
NvAR_SetObject(filter->gazeHandle, NvAR_Parameter_Output(GazeOutputLandmarks),
filter->gaze_output_landmarks.array, sizeof(NvAR_Point2f));
NvAR_SetU32(filter->gazeHandle, NvAR_Parameter_Config(Temporal), -1);
NvAR_SetU32(filter->gazeHandle, NvAR_Parameter_Config(GazeRedirect), false);
NvAR_SetU32(filter->gazeHandle, NvAR_Parameter_Config(UseCudaGraph), true);
NvAR_SetU32(filter->gazeHandle, NvAR_Parameter_Config(EyeSizeSensitivity), 3);
if (nv_move_log_error(filter, NvAR_Load(filter->gazeHandle), "Load gaze"))
return;
}
} else if (filter->gazeHandle) {
nv_move_log_error(filter, NvAR_Destroy(filter->gazeHandle), "Destroy gaze");
filter->gazeHandle = NULL;
}
if (feature_flags & (1ull << FEATURE_EXPRESSION)) {
if (!filter->expressionHandle) {
if (nv_move_log_error(filter, NvAR_Create(NvAR_Feature_FaceExpressions, &filter->expressionHandle),
"Create expression"))
return;
nv_move_feature_handle(filter, filter->expressionHandle);
nv_move_landmarks(filter, filter->expressionHandle);
NvAR_SetObject(filter->expressionHandle, NvAR_Parameter_Output(Pose), &filter->pose,
sizeof(NvAR_Quaternion));
uint32_t expressionCount = 0;
NvCV_Status nvErr =
NvAR_GetU32(filter->expressionHandle, NvAR_Parameter_Config(ExpressionCount), &expressionCount);
if (nvErr == NVCV_SUCCESS) {
da_resize(filter->expressions, expressionCount);
nvErr = NvAR_SetF32Array(filter->expressionHandle, NvAR_Parameter_Output(ExpressionCoefficients),
filter->expressions.array, expressionCount);
}
if (nv_move_log_error(filter, NvAR_Load(filter->expressionHandle), "Load expression"))
return;
}
} else if (filter->expressionHandle) {
nv_move_log_error(filter, NvAR_Destroy(filter->expressionHandle), "Destroy expression");
filter->expressionHandle = NULL;
}
if ((feature_flags & (1ull << FEATURE_BOUNDINGBOX))) {
if (!filter->bboxes_confidence.num)
da_resize(filter->bboxes_confidence, BBOXES_COUNT);
if (filter->bodyHandle) {
NvAR_SetF32Array(filter->bodyHandle, NvAR_Parameter_Output(BoundingBoxesConfidence),
filter->bboxes_confidence.array, BBOXES_COUNT);
} else if (filter->gazeHandle) {
NvAR_SetF32Array(filter->gazeHandle, NvAR_Parameter_Output(BoundingBoxesConfidence),
filter->bboxes_confidence.array, BBOXES_COUNT);
} else if (filter->expressionHandle) {
NvAR_SetF32Array(filter->expressionHandle, NvAR_Parameter_Output(BoundingBoxesConfidence),
filter->bboxes_confidence.array, BBOXES_COUNT);
} else {
if (!filter->faceDetectHandle) {
if (nv_move_log_error(filter, NvAR_Create(NvAR_Feature_FaceBoxDetection, &filter->faceDetectHandle),
"Create faceDetect"))
return;
nv_move_feature_handle(filter, filter->faceDetectHandle);
NvAR_SetF32Array(filter->faceDetectHandle, NvAR_Parameter_Output(BoundingBoxesConfidence),
filter->bboxes_confidence.array, BBOXES_COUNT);
if (nv_move_log_error(filter, NvAR_Load(filter->faceDetectHandle), "Load faceDetect"))
return;
}
}
} else if (filter->faceDetectHandle) {
nv_move_log_error(filter, NvAR_Destroy(filter->faceDetectHandle), "Destroy faceDetect");
filter->faceDetectHandle = NULL;
}
if ((((feature_flags & (1ull << FEATURE_LANDMARK)) || (feature_flags & (1ull << FEATURE_POSE))) && !filter->gazeHandle &&
!filter->expressionHandle)) {
if (!filter->landmarkHandle) {
if (nv_move_log_error(filter, NvAR_Create(NvAR_Feature_LandmarkDetection, &filter->landmarkHandle),
"Create landmark"))
return;
nv_move_feature_handle(filter, filter->landmarkHandle);
nv_move_landmarks(filter, filter->landmarkHandle);
NvAR_SetObject(filter->landmarkHandle, NvAR_Parameter_Output(Pose), &filter->pose, sizeof(NvAR_Quaternion));
if (nv_move_log_error(filter, NvAR_Load(filter->landmarkHandle), "Load expression"))
return;
}
} else if (filter->landmarkHandle) {
nv_move_log_error(filter, NvAR_Destroy(filter->landmarkHandle), "Destroy landmark");
filter->landmarkHandle = NULL;
}
}
static void nv_move_actual_destroy(void *data)
{
struct nvidia_move_info *filter = (struct nvidia_move_info *)data;
if (filter->faceDetectHandle)
nv_move_log_error(filter, NvAR_Destroy(filter->faceDetectHandle), "Destroy faceDetect");
if (filter->landmarkHandle)
nv_move_log_error(filter, NvAR_Destroy(filter->landmarkHandle), "Destroy landmark");
if (filter->expressionHandle)
nv_move_log_error(filter, NvAR_Destroy(filter->expressionHandle), "Destroy expression");
if (filter->gazeHandle)
nv_move_log_error(filter, NvAR_Destroy(filter->gazeHandle), "Destroy gaze");
if (filter->bodyHandle)
nv_move_log_error(filter, NvAR_Destroy(filter->bodyHandle), "Destroy body");
if (filter->stream)
nv_move_log_error(filter, NvAR_CudaStreamDestroy(filter->stream), "Destroy Cuda Stream");