-
Notifications
You must be signed in to change notification settings - Fork 138
/
Copy pathjointEstimator2D.cpp
725 lines (604 loc) · 24.4 KB
/
jointEstimator2D.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
#include "jointEstimator2D.hpp"
#include <vector>
#include <algorithm> // std::sort
#include <stdio.h>
#include <string.h>
#include <time.h>
unsigned long tickBaseJointEstimator = 0;
unsigned long GetTickCountMicrosecondsJointEstimator()
{
struct timespec ts;
if ( clock_gettime(CLOCK_MONOTONIC,&ts) != 0)
{
return 0;
}
if (tickBaseJointEstimator==0)
{
tickBaseJointEstimator = ts.tv_sec*1000000 + ts.tv_nsec/1000;
return 0;
}
return ( ts.tv_sec*1000000 + ts.tv_nsec/1000 ) - tickBaseJointEstimator;
}
int dumpHeatmapToCSVFile(const char * filename,struct JointEstimator2D * jnet,std::vector<float> heatmap)
{
unsigned int width = jnet->heatmapWidth2DJointDetector;
unsigned int height = jnet->heatmapHeight2DJointDetector;
FILE * fp = fopen(filename,"w");
if (fp!=0)
{
//---------------------------
// Header
//---------------------------
for (int x=0; x<width; x++)
{
if (x!=0)
{
fprintf(fp,",");
}
fprintf(fp,"x=%u",x);
}
fprintf(fp,"\n");
//---------------------------
//---------------------------
// Body
//---------------------------
unsigned int i=0;
for (int y=0; y<height; y++)
{
for (int x=0; x<width; x++)
{
if (x!=0)
{
fprintf(fp,",");
}
if (heatmap[i]>0.01)
{
fprintf(fp,"%f",heatmap[i]);
}
else if (-0.01>heatmap[i])
{
fprintf(fp,"%f",heatmap[i]);
}
else
{
fprintf(fp,"0");
}
++i;
}
fprintf(fp,"\n");
}
//---------------------------
fclose(fp);
return 1;
}
return 0;
}
int loadJointEstimator2D(struct JointEstimator2D * jnet,int joint2DEstimatorSelected,int usePAFs,unsigned int forceCPU)
{
memset(jnet,0,sizeof(struct JointEstimator2D));
const char networkPathOpenPoseMiniStatic[]="dataset/combinedModel/openpose_model.pb";
const char networkPathVnectStatic[]="dataset/combinedModel/vnect_sm_pafs_8.1k.pb";
const char networkPathFORTHStatic[]="dataset/combinedModel/mobnet2_tiny_vnect_sm_1.9k.pb";
jnet->networkPath = (char*) networkPathFORTHStatic;
jnet->joint2DSensitivityPercent=30;
char networkInputLayer[]="input_1";
char networkOutputLayer[]="k2tfout_0";
jnet->numberOfOutputTensors = 3;
jnet->heatmapWidth2DJointDetector= 46;
jnet->heatmapHeight2DJointDetector= 46;
jnet->inputWidth2DJointDetector = 368;
jnet->inputHeight2DJointDetector = 368;
jnet->numberOfHeatmaps = 19;
//-----------------------------------------------------------------------------
switch (joint2DEstimatorSelected)
{
case JOINT_2D_ESTIMATOR_FORTH :
jnet->networkPath=(char*) networkPathFORTHStatic;
networkOutputLayer[8]='0';
jnet->joint2DSensitivityPercent=30;
jnet->numberOfOutputTensors = 3;
break;
case JOINT_2D_ESTIMATOR_VNECT :
jnet->networkPath = (char*) networkPathVnectStatic;
networkOutputLayer[8]='1';
jnet->joint2DSensitivityPercent=20;
jnet->numberOfOutputTensors = 4;
break;
case JOINT_2D_ESTIMATOR_OPENPOSE :
jnet->networkPath=(char*) networkPathOpenPoseMiniStatic;
networkOutputLayer[8]='1';
jnet->joint2DSensitivityPercent=40;
jnet->numberOfOutputTensors = 4;
break;
default :
fprintf(stderr,"No 2D Joint Estimator Selected..\n");
break;
};
//-----------------------------------------------------------------------------
if (
loadTensorflowInstance(
&jnet->network,
jnet->networkPath,
networkInputLayer,
networkOutputLayer,
forceCPU
)
)
{
return 1;
}
//-----------------------------------------------------------------------------
return 0;
}
int unloadJointEstimator2D(struct JointEstimator2D * jnet)
{
return unloadTensorflow(&jnet->network);
}
int sortBlobsBasedOnMaximumActivation(struct HeatmapBlob blobA,struct HeatmapBlob blobB)
{
return blobA.peakValue > blobB.peakValue;
}
int updateSubpixelPeak(struct JointEstimator2D * jnet,struct HeatmapBlob * blob,std::vector<float> heatmap,unsigned int width,unsigned int height)
{
//Uncomment to disable subpixel code..
//blob->subpixelPeakX = (float) blob->peakX;
//blob->subpixelPeakY = (float) blob->peakY;
//return 0;
#define DEBUG_SUBPIXEL_GRADIENT 0
#if DEBUG_SUBPIXEL_GRADIENT
std::vector<float> gradientX(width*height);
std::vector<float> gradientY(width*height);
#endif
if (blob->peakValue==0.0)
{
return 0;
}
float vX=(float) blob->peakX;
float vY=(float) blob->peakY;
float normalizedValue=0.0;
unsigned int location=0;
for (signed int y=0; y<blob->height; y++)
{
for (signed int x=0; x<blob->width; x++)
{
//fprintf(stderr,"Blob element (x=%u,y=%u) ",x,y);
location = (width * (y+blob->y)) + (x+blob->x);
//fprintf(stderr,"Location %u",location);
if (location<heatmap.size())
{
normalizedValue=(float) heatmap[location] / blob->peakValue;
normalizedValue= normalizedValue / ( blob->width * blob->height);
//fprintf(stderr,"NormalValue %0.2f",normalizedValue);
signed int peakInRelationToBlobX = (signed int) ((signed int) blob->peakX - (signed int) blob->x);
signed int peakInRelationToBlobY = (signed int) ((signed int) blob->peakY - (signed int) blob->y);
signed int relativePositionToPeakX = (signed int) ( (signed int) x - (signed int) peakInRelationToBlobX);
signed int relativePositionToPeakY = (signed int) ( (signed int) y - (signed int) peakInRelationToBlobY);
//fprintf(stderr,"Ppeak %d,%d",posX,posY);
float nX=(float) relativePositionToPeakX*normalizedValue;
float nY=(float) relativePositionToPeakY*normalizedValue;
//fprintf(stderr,"Add %f,%f\n",nX,nY);
#if DEBUG_SUBPIXEL_GRADIENT
gradientX[location]=nX;
gradientY[location]=nY;
#endif
if ( (nX!=nX) || (nY!=nY) )
{
//Handle NaN
}
else
{
//fprintf(stderr,"%f,%f ",nX,nY);
vX=vX+nX;
vY=vY+nY;
}
}
else
{
fprintf(stderr,"updateSubpixelPeak overflow..\n");
return 0;
}
}
}
#if DEBUG_SUBPIXEL_GRADIENT
char filename[512];
snprintf(filename,512,"GradientX.csv");
dumpHeatmapToCSVFile(filename,jnet,gradientX);
snprintf(filename,512,"GradientY.csv");
dumpHeatmapToCSVFile(filename,jnet,gradientY);
snprintf(filename,512,"Values.csv");
dumpHeatmapToCSVFile(filename,jnet,heatmap);
#endif
blob->subpixelPeakX = vX;
blob->subpixelPeakY = vY;
return 1;
}
int isNeighborWithBlob(char * blobLabels,int x,int y,int width,int height)
{
for (int iY=-1; iY<1; iY++)
{
for (int iX=-1; iX<=1; iX++)
{
if ( (iX==0) && (iY==0) )
{
}
else if (
(iX+x>=0) &&
(iY+y>=0) &&
(iX+x<width) &&
(iY+y<height)
)
{
int location = width * (y+iY) + (x+iX);
if (blobLabels[location]!=0)
{
return blobLabels[location];
}
}
}
}
return 0;
}
std::vector<struct HeatmapBlob> getBlobsFromHeatmap(struct JointEstimator2D * jnet,unsigned int heatmapID,std::vector<float> heatmap)
{
unsigned int width = jnet->heatmapWidth2DJointDetector;
unsigned int height = jnet->heatmapHeight2DJointDetector;
struct HeatmapBlob emptyBlob;
emptyBlob.x=width+1;
emptyBlob.y=height+1;
emptyBlob.width=0;
emptyBlob.height=0;
emptyBlob.width=0;
emptyBlob.peakX=0;
emptyBlob.peakY=0;
emptyBlob.peakValue=0.0;
emptyBlob.subpixelPeakX=0.0;
emptyBlob.subpixelPeakY=0.0;
std::vector<struct HeatmapBlob> blobsEncountered;
char blobLabels[width*height]= {0};
unsigned int currentBlobLabel=1;
int onHorizontalBlob=0;
int labelID=0;
unsigned int i=0;
float threshold = 0.1; //(float) jnet->joint2DSensitivityPercent/100;
for (int y=0; y<height; y++)
{
for (int x=0; x<width; x++)
{
if ( heatmap[i] > threshold )
{
if (!onHorizontalBlob)
{
//We were not on a horizontal blob so we need to search..!
labelID=isNeighborWithBlob(blobLabels,x,y,width,height);
if (!labelID)
{
//Our search did not give us a result
//This is a new blob disconnected from previous blobs..!
blobLabels[i]=currentBlobLabel;
onHorizontalBlob=currentBlobLabel;
labelID=currentBlobLabel-1;
++currentBlobLabel;
blobsEncountered.push_back(emptyBlob);
onHorizontalBlob=1;
}
else
{
//Already Existing Blob found we will add this pixel to it
onHorizontalBlob=labelID;
blobLabels[i]=onHorizontalBlob;
labelID=labelID-1;
}
}
else
{
//If we are already on a horizontal blob dont do expensive search
blobLabels[i]=onHorizontalBlob;
labelID=onHorizontalBlob-1;
}
if (labelID<blobsEncountered.size())
{
//fprintf(stderr,"Hit at %u,%u\n",x,y);
//fprintf(stderr,"%f ",heatmap[i]);
//Update Blob Start at X Axis
if (x<blobsEncountered[labelID].x)
{
blobsEncountered[labelID].x=x;
}
//Update Blob Start at Y Axis
if (y<blobsEncountered[labelID].y)
{
blobsEncountered[labelID].y=y;
}
//Update Blob Width
int thisLineWidth=1+x-blobsEncountered[labelID].x;
if (thisLineWidth>blobsEncountered[labelID].width)
{
blobsEncountered[labelID].width=thisLineWidth;
}
//Update Blob Height
int thisLineHeight=1+y-blobsEncountered[labelID].y;
if (thisLineHeight>blobsEncountered[labelID].height)
{
blobsEncountered[labelID].height=thisLineHeight;
}
//Update Peak to use as center later..
if (blobsEncountered[labelID].peakValue<heatmap[i])
{
blobsEncountered[labelID].peakValue=heatmap[i];
blobsEncountered[labelID].peakX=x;
blobsEncountered[labelID].peakY=y;
}
}
}//Above activation threshold..
else
{
//We just left a blob..
onHorizontalBlob=0;
}
++i;
} //End of X loop
//We just left a line so the blob has ended..
onHorizontalBlob=0;
} //End of Y loop
for (int blobID=0; blobID<blobsEncountered.size(); blobID++)
{
updateSubpixelPeak(jnet,&blobsEncountered[blobID],heatmap,width,height);
}
//Make sure the best value is first..
std::sort(blobsEncountered.begin(), blobsEncountered.end(),sortBlobsBasedOnMaximumActivation);
/*
fprintf(stderr,"Heatmap %u %s--------\n",heatmapID,UT_COCOBodyNames[heatmapID]);
for (int blobID=0; blobID<blobsEncountered.size(); blobID++)
{
fprintf(stderr,"Blob %u/%lu - ",blobID,blobsEncountered.size());
fprintf(stderr,"x=%u,y=%u(%ux%u) "
,blobsEncountered[blobID].x,blobsEncountered[blobID].y
,blobsEncountered[blobID].width,blobsEncountered[blobID].height
);
fprintf(stderr,"pX=%u,pY=%u>",blobsEncountered[blobID].peakX,blobsEncountered[blobID].peakY);
fprintf(stderr,"%0.2f",blobsEncountered[blobID].peakValue);
fprintf(stderr," subpixel(%0.2f,%0.2f)",blobsEncountered[blobID].subpixelPeakX,blobsEncountered[blobID].subpixelPeakY);
fprintf(stderr,"\n");
}
*/
return blobsEncountered;
}
int estimate2DSkeletonsFromHeatmaps(struct JointEstimator2D * jnet,struct Skeletons2DDetected * result,std::vector<std::vector<float> > heatmaps)
{
//char filename[512];
//fprintf(stderr,"New Frame:\n");
unsigned long startTime = GetTickCountMicrosecondsJointEstimator();
int blobsProceesed=0;
for (int heatmapID=0; heatmapID<heatmaps.size(); heatmapID++)
{
unsigned int body25ID = heatmapCorrespondenceToBODY25[heatmapID];
if (heatmapID!=UT_COCO_Bkg)
{
result->skeletons[0].body.joint2D[body25ID].x = 0;
result->skeletons[0].body.joint2D[body25ID].y = 0;
result->skeletons[0].body.active[body25ID]=0.0;
//--------------------------------------------------------
std::vector<struct HeatmapBlob> blobs = getBlobsFromHeatmap(jnet,heatmapID,heatmaps[heatmapID]);
if (blobs.size()>0)
{
result->skeletons[0].body.isPopulated=1;
float x=(float) blobs[0].subpixelPeakX/ jnet->heatmapWidth2DJointDetector;
float y=(float) blobs[0].subpixelPeakY/ jnet->heatmapHeight2DJointDetector;
result->skeletons[0].body.joint2D[body25ID].x = x;
result->skeletons[0].body.joint2D[body25ID].y = y;
if ( (x!=0) && (y!=0) ) {
result->skeletons[0].body.active[body25ID]=1.0;
}
if (blobsProceesed==0)
{
//Update Bbox Min
result->skeletons[0].body.bbox2D[0].x = x;
result->skeletons[0].body.bbox2D[0].y = y;
//Update Bbox Max
result->skeletons[0].body.bbox2D[1].x = x;
result->skeletons[0].body.bbox2D[1].y = y;
}
else
{
// if Min X > current X
if (result->skeletons[0].body.bbox2D[0].x > x )
{
result->skeletons[0].body.bbox2D[0].x =x;
}
// if Min Y > current Y
if (result->skeletons[0].body.bbox2D[0].y > y )
{
result->skeletons[0].body.bbox2D[0].y =y;
}
// if Max X < current X
if (result->skeletons[0].body.bbox2D[1].x < x )
{
result->skeletons[0].body.bbox2D[1].x =x;
}
// if Max Y < current Y
if (result->skeletons[0].body.bbox2D[1].y < y )
{
result->skeletons[0].body.bbox2D[1].y =y;
}
}
++blobsProceesed;
}
//--------------------------------------------------------
//snprintf(filename,512,"heatmap_%u.csv",heatmapID);
//dumpHeatmapToCSVFile(filename,jnet,heatmaps[0]);
//--------------------------------------------------------
}
}
/*
The following joints are not covered by the current networks
BODY25_MidHip,
BODY25_LBigToe,
BODY25_LSmallToe,
BODY25_LHeel,
BODY25_RBigToe,
BODY25_RSmallToe,
BODY25_RHeel,
*/
//Mid hip can be approximated by LHip and RHip
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
if (
(result->skeletons[0].body.joint2D[BODY25_RHip].x!=0) && (result->skeletons[0].body.joint2D[BODY25_LHip].x!=0) &&
(result->skeletons[0].body.joint2D[BODY25_RHip].y!=0) && (result->skeletons[0].body.joint2D[BODY25_LHip].y!=0)
)
{
result->skeletons[0].body.joint2D[BODY25_MidHip].x = (float) (result->skeletons[0].body.joint2D[BODY25_RHip].x+result->skeletons[0].body.joint2D[BODY25_LHip].x)/2;
result->skeletons[0].body.joint2D[BODY25_MidHip].y = (float) (result->skeletons[0].body.joint2D[BODY25_RHip].y+result->skeletons[0].body.joint2D[BODY25_LHip].y)/2;
result->skeletons[0].body.jointAccuracy[BODY25_MidHip] = (result->skeletons[0].body.jointAccuracy[BODY25_RHip]+result->skeletons[0].body.jointAccuracy[BODY25_LHip])/2;
result->skeletons[0].body.active[BODY25_MidHip] = 1.0;
//fprintf(stderr,"Mid hip populated and resides @ (%0.2f,%0.2f)\n",result->skeletons[0].body.joint2D[BODY25_MidHip].x,result->skeletons[0].body.joint2D[BODY25_MidHip].y);
} else
{
result->skeletons[0].body.joint2D[BODY25_MidHip].x = 0;
result->skeletons[0].body.joint2D[BODY25_MidHip].y = 0;
result->skeletons[0].body.jointAccuracy[BODY25_MidHip] = 0;
result->skeletons[0].body.active[BODY25_MidHip] = 0.0;
//fprintf(stderr,"Cannot populate Mid hip, this will degrade output!\n");
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
result->numberOfSkeletonsDetected=1;
unsigned long endTime = GetTickCountMicrosecondsJointEstimator();
// fprintf(stderr,"Resolving joint subpixel peaks took %lu microseconds\n",endTime-startTime);
return 1;
}
int convertNormalized2DJointsToOriginalImageCoordinates(
struct JointEstimator2D * jnet,
float * x,
float * y,
int correctOffset
)
{
//It is very common for points to be empty, they cannot be normalized so its best if we have
//a quick path for them..
if ( (*x==0.0) && (*y==0.0) ) {
return 1;
}
if (*x>1.0) {
*x=1.0;
}
if (*y>1.0) {
*y=1.0;
}
float normalizedX = *x;
float normalizedY = *y;
//fprintf(stderr,"Initial point is %0.2f,%0.2f\n",normalizedX,normalizedY);
float frameOfReferenceOfTensorflowX = normalizedX * jnet->inputWidth2DJointDetector;
float frameOfReferenceOfTensorflowY = normalizedY * jnet->inputHeight2DJointDetector;
//fprintf(stderr,"Tensorflow point is %0.2f,%0.2f\n",frameOfReferenceOfTensorflowX,frameOfReferenceOfTensorflowY);
float scaleFromTensorflowToBoundingBoxX = (float) jnet->crop.croppedDimensionWidth / jnet->inputWidth2DJointDetector;
float scaleFromTensorflowToBoundingBoxY = (float) jnet->crop.croppedDimensionHeight / jnet->inputHeight2DJointDetector;
*x = /*jnet->crop.offsetX +*/ (frameOfReferenceOfTensorflowX * scaleFromTensorflowToBoundingBoxX);
*y = /*jnet->crop.offsetY +*/ (frameOfReferenceOfTensorflowY * scaleFromTensorflowToBoundingBoxY);
if (correctOffset)
{
*x += jnet->crop.offsetX;
*y += jnet->crop.offsetY;
}
//fprintf(stderr,"Final point is %0.2f,%0.2f\n",*x,*y);
return 1;
}
std::vector<std::vector<float> > getHeatmaps(struct JointEstimator2D * jnet,unsigned char * rgbData,unsigned int width,unsigned int height)
{
// pass the frame to the Estimator
unsigned long startTime = GetTickCountMicrosecondsJointEstimator();
std::vector<std::vector<float> > joint2DOutput = predictTensorflowOnArrayOfHeatmaps(
&jnet->network,
(unsigned int) width,
(unsigned int) height,
(float*) rgbData,
jnet->heatmapWidth2DJointDetector,
jnet->heatmapHeight2DJointDetector,
jnet->numberOfOutputTensors
);
unsigned long endTime = GetTickCountMicrosecondsJointEstimator();
//fprintf(stderr,"Running 2D joint estimator took %lu microseconds\n",endTime-startTime);
return joint2DOutput;
}
int estimate2DSkeletonsFromImage(struct JointEstimator2D * jnet,struct Skeletons2DDetected * result,unsigned char * rgbData,unsigned int width,unsigned int height)
{
/*
unsigned long startTime = GetTickCountMicroseconds();
std::vector<cv::Point_<float> > pointsOf2DSkeleton = predictAndReturnSingleSkeletonOf2DCOCOJoints(
&jnet->network,
bgr,
minThreshold,
visualize,
saveVisualization,
frameNumber,
inputWidth2DJointDetector,
inputHeight2DJointDetector,
heatmapWidth2DJointDetector,
heatmapHeight2DJointDetector,
numberOfHeatmaps,
numberOfOutputTensors
);
unsigned long endTime = GetTickCountMicroseconds();
*fps = convertStartEndTimeFromMicrosecondsToFPS(startTime,endTime);
*/
// pass the frame to the Estimator
std::vector<std::vector<float> > joint2DOutput = predictTensorflowOnArrayOfHeatmaps(
&jnet->network,
(unsigned int) width,
(unsigned int) height,
(float*) rgbData,
jnet->heatmapWidth2DJointDetector,
jnet->heatmapHeight2DJointDetector,
jnet->numberOfOutputTensors
);
return 0;
}
int restore2DJointsToInputFrameCoordinates(struct JointEstimator2D * jnet,struct Skeletons2DDetected * input)
{
for (unsigned int skID=0; skID<input->numberOfSkeletonsDetected; skID++)
{
for (int i=0; i<BODY25_PARTS; i++)
{
//fprintf(stderr,"normalized(%0.2f,%0.2f) ",input->skeletons[skID].body.joint2D[i].x,input->skeletons[skID].body.joint2D[i].y);
convertNormalized2DJointsToOriginalImageCoordinates(jnet,&input->skeletons[skID].body.joint2D[i].x,&input->skeletons[skID].body.joint2D[i].y,1);
//fprintf(stderr,"regular(%0.2f,%0.2f) ",input->skeletons[skID].body.joint2D[i].x,input->skeletons[skID].body.joint2D[i].y);
}
/* //Currently dont have hand and head networks..!
for (int i=0; i<COCO_HAND_PARTS; i++)
{
convertNormalized2DJointsToOriginalImageCoordinates(jnet,&input->skeletons[skID].leftHand.joint2D[i].x,&input->skeletons[skID].leftHand.joint2D[i].y,1);
}
for (int i=0; i<COCO_HAND_PARTS; i++)
{
convertNormalized2DJointsToOriginalImageCoordinates(jnet,&input->skeletons[skID].rightHand.joint2D[i].x,&input->skeletons[skID].rightHand.joint2D[i].y,1);
}
for (int i=0; i<OP_HEAD_PARTS; i++)
{
convertNormalized2DJointsToOriginalImageCoordinates(jnet,&input->skeletons[skID].head.joint2D[i].x,&input->skeletons[skID].head.joint2D[i].y,1);
}
*/
}
return 1;
}
float percentOf2DPointsMissing(struct Skeletons2DDetected * input)
{
if (input->numberOfSkeletonsDetected==0) {
return 100.0;
}
unsigned int jointsThatExist=0;
unsigned int jointsThatShouldExist=0;
if (input->skeletons[0].body.isPopulated)
{
jointsThatShouldExist=BODY25_PARTS-2;
for (int jID=0; jID<BODY25_PARTS; jID++)
{
if ( input->skeletons[0].body.active[jID] )
{
++jointsThatExist;
}
}
//fprintf(stderr,"%u/%u joints observed\n",jointsThatExist,jointsThatShouldExist);
float percentOf2DPointsThatExist = (float) 100 * jointsThatExist / jointsThatShouldExist;
return (float) 100.0 - percentOf2DPointsThatExist;
}
//fprintf(stderr,"Body is not populated\n");
return 100.0;
}