slightly tweaked mocapnet alt container

This commit is contained in:
Kasisnu
2024-01-18 19:23:00 +05:30
parent 881c2fc840
commit 0d662c5b9d
294 changed files with 99862 additions and 2 deletions
@@ -0,0 +1,29 @@
project( CSVClusterPlot )
cmake_minimum_required( VERSION 2.8.13 )
#cmake_minimum_required(VERSION 3.5)
find_package(OpenCV REQUIRED)
INCLUDE_DIRECTORIES(${OpenCV_INCLUDE_DIRS})
#set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(CMAKE_CXX_STANDARD 11)
include_directories(${TENSORFLOW_INCLUDE_ROOT})
add_executable(
CSVClusterPlot
csvClusterPlot.cpp
perform2DClustering.cpp
perform3DClustering.cpp
${BVH_SOURCE}
)
target_link_libraries(CSVClusterPlot rt dl m ${OpenCV_LIBRARIES} ${OPENGL_LIBS} Tensorflow TensorflowFramework MocapNETLib2 )
#set_target_properties(CSVClusterPlot PROPERTIES DEBUG_POSTFIX "D")
set_target_properties(CSVClusterPlot PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}"
)
@@ -0,0 +1,759 @@
#include "opencv2/opencv.hpp"
/** @file csvClusterPlot.cpp
* @brief
* @author Ammar Qammaz (AmmarkoV)
*/
#include <stdio.h>
#include <sys/stat.h> //mkdir
#include "../MocapNETLib2/mocapnet2.hpp"
#include "../MocapNETLib2/IO/bvh.hpp"
#include "../MocapNETLib2/visualization/visualization.hpp"
#include "../MocapNETLib2/visualization/opengl.hpp"
#include "../MocapNETLib2/IO/csvRead.hpp"
#include <vector>
#include "../../../dependencies/RGBDAcquisition/opengl_acquisition_shared_library/opengl_depth_and_color_renderer/src/Library/MotionCaptureLoader/bvh_loader.h"
#include "../../../dependencies/RGBDAcquisition/opengl_acquisition_shared_library/opengl_depth_and_color_renderer/src/Library/MotionCaptureLoader/edit/bvh_filter.h"
#include "../../../dependencies/RGBDAcquisition/opengl_acquisition_shared_library/opengl_depth_and_color_renderer/src/Library/MotionCaptureLoader/edit/bvh_rename.h"
#include "../../../dependencies/RGBDAcquisition/opengl_acquisition_shared_library/opengl_depth_and_color_renderer/src/Library/MotionCaptureLoader/edit/bvh_randomize.h"
#include "perform2DClustering.hpp"
#include "perform3DClustering.hpp"
//#include <stdint.h>
using namespace cv;
int visualizeOpenGLEnabled=0;
#define BOOST_CONTRAST 2.0
char MocapNET1List[]="src/MocapNET2/CSVClusterPlot/listOfFilesToClusterMocapNET1";
char defaultList[]="src/MocapNET2/CSVClusterPlot/listOfFilesToCluster";
const char * perturbList1[] =
{
" ",
"rshoulder",
"lshoulder",
"rhip",
"lhip"
};
const char * perturbList2[] =
{
" ",
"rhand",
"relbow",
"lelbow",
"lhand",
"lknee",
"rknee",
"lfoot",
"rfoot"
};
const char * perturbList3[] =
{
" ",
"abdomen",
"chest"
};
/*
#define rotationSetting 0"
#define handToCloseHipMin "45"
#define handToCloseHipMax "90"
#define handToFarHipMin "100"
#define handToFarHipMax "160"
#define handToHandMin "150"
#define handToHandMax "250"
*/
#define rotationSetting "90"
#define handToCloseHipMin "0"
#define handToCloseHipMax "120"
#define handToFarHipMin "0"
#define handToFarHipMax "120"
#define handToHandMin "0"
#define handToHandMax "150"
const char * removeNeutralPosesRules[] =
{
"0", // 0 | Move Armature to 0 X Position
"0", // 1 | Move Armature to 0 Y Position
"-130.0", // 2 | Move Armature to -130.0 Z Position
"0", // 3 | Rotate Armature to 0deg X Rotation
rotationSetting, // 4 | Rotate Armature to 0deg Y Rotation
"0", // 5 | Rotate Armature to 0deg Z Rotation
//--------------------------------------------------------------------------
"1920", // 6 | Virtual 2D Rendering Width
"1080",// 7 | Virtual 2D Rendering Height
"570.7", // 8 | Virtual 2D Rendering Focal Length X
"570.3", // 9 | Virtual 2D Rendering Focal Length Y
//--------------------------------------------------------------------------
"6", // 10 | Number of joint rules
//--------------------------------------------------------------------------
"rhand", // 11 | Joint A
"lhip", // 12 | Joint B
handToFarHipMin, // 13 | Minimum Acceptable 2D Distance
handToFarHipMax, // 14 | Maximum Acceptable 2D Distance
"rhand", // 15 | Joint A
"rhip", // 16| Joint B
handToCloseHipMin, // 17 | Minimum Acceptable 2D Distance
handToCloseHipMax, // 18 | Maximum Acceptable 2D Distance
"rhand", // 19 | Joint A
"lhand", // 20 | Joint B
handToHandMin, // 21 | Minimum Acceptable 2D Distance
handToHandMax, // 22 | Maximum Acceptable 2D Distance
//--------------------------------------------------------------------------
"lhand", // 23 | Joint A
"rhip", // 24| Joint B
handToFarHipMin, // 25 | Minimum Acceptable 2D Distance
handToFarHipMax, // 26 | Maximum Acceptable 2D Distance
"lhand", // 27 | Joint A
"lhip", // 28| Joint B
handToCloseHipMin, // 29 | Minimum Acceptable 2D Distance
handToCloseHipMax, // 30 | Maximum Acceptable 2D Distance
"lhand", // 31 | Joint A
"rhand", // 32 | Joint B
handToHandMin, // 33 | Minimum Acceptable 2D Distance
handToHandMax // 34 | Maximum Acceptable 2D Distance
};
void convertHeatmapValueToRGB(float heatmap,unsigned char * R,unsigned char * G,unsigned char * B)
{
float r = fminf(1.0f, (fmaxf(0.5f, heatmap) - 0.5f) * 6.0f);
float g = fminf(1.0f, heatmap * 3.0f) - fminf(1.0f, fmaxf(0.0f, heatmap - 0.666f) * 3.0f);
float b = fmaxf(0.0f, 1.0f - fmaxf(0.0f, heatmap - 0.333f) * 6.0f);
if (heatmap==0.0)
{
r=0.0;
g=0.0;
b=0.0;
}
else if (heatmap<0.1)
{
r=0.0;
g=0.0;
b=0.3+10*heatmap;
if (b>=1.0)
{
b=1.0;
}
}
else if (heatmap>=1.0) //Cap
{
if (heatmap>=2.0)
{
r=1.0;
g=0.0;
b=1.0; //Final Limit
}
else
{
r=1.0 ;
g=0.0;
b=heatmap-1.0;
}
}
r=r*255.0;
g=g*255.0;
b=b*255.0;
*R = (unsigned char) r;
*G = (unsigned char) g;
*B = (unsigned char) b;
}
int draw2DClustering(cv::Mat &viewMat,struct BVH_MotionCapture * bvhMotion,std::vector<std::vector<float> > aPose,struct applicationState * state,const char * line, char * videoPath,unsigned int width,unsigned int height)
{
char buffer[1024]= {0};
memset(viewMat.data,0,width*height*3*sizeof(char));
/*
if ( state->maxAccumulatedSample > state->accumulatedSamples )
{
state->maxAccumulatedSample=state->accumulatedSamples;
}*/
unsigned char R,G,B;
//------------------------------------------------------------------------------
for (int y=0; y<height; y++)
{
for (int x=0; x<width; x++)
{
float heatmap = (float) state->accumulatedImage[y*width+x] / state->maxAccumulatedSample;
heatmap*=BOOST_CONTRAST;
convertHeatmapValueToRGB(heatmap,&R,&G,&B);
unsigned int pos=(y*width*3) + x*3;
viewMat.data[pos++]=B;
viewMat.data[pos++]=G;
viewMat.data[pos]=R;
}
//add a sidebar with the colors legend..
for (int x=width-5; x<width; x++)
{
float heatmapScaleValue = 1.0 - ((float) y / height);
heatmapScaleValue*=BOOST_CONTRAST; //;
convertHeatmapValueToRGB(heatmapScaleValue,&R,&G,&B);
unsigned int pos=(y*width*3) + x*3;
viewMat.data[pos++]=B;
viewMat.data[pos++]=G;
viewMat.data[pos]=R;
}
if (y%50==0)
{
float heatmapScaleValue = 1.0 - ((float) y / height);
heatmapScaleValue*=state->maxAccumulatedSample;
snprintf(buffer,1024,"%0.0f",heatmapScaleValue);
cv::putText(viewMat,buffer, cv::Point(width-50,y), cv::FONT_HERSHEY_DUPLEX, 0.3, cv::Scalar::all(255), 0.2, 8 );
}
}
drawSkeleton(viewMat,aPose,0,0,1);
snprintf(buffer,1024,"%lu accumulated samples, max heatmap value = %lu",state->accumulatedSamples,state->maxAccumulatedSample);
cv::putText(viewMat,buffer, cv::Point(10,30), cv::FONT_HERSHEY_DUPLEX, 0.5, cv::Scalar::all(255), 0.2, 8 );
snprintf(buffer,1024,"%s added with %u samples",line,bvhMotion->numberOfFrames);
cv::putText(viewMat,buffer, cv::Point(10,50), cv::FONT_HERSHEY_DUPLEX, 0.5, cv::Scalar::all(255), 0.2, 8 );
if (videoPath!=0)
{
snprintf(buffer,1024,"Label : %s ",videoPath);
cv::putText(viewMat,buffer, cv::Point(10,70), cv::FONT_HERSHEY_DUPLEX, 0.5, cv::Scalar::all(255), 0.2, 8 );
}
return 1;
}
int draw3DClustering(cv::Mat &viewMat,struct clusteringOf3DPoses * state,unsigned int width,unsigned int height,unsigned int depth)
{
memset(viewMat.data,0,width*height*3*sizeof(char));
unsigned char R,G,B;
//------------------------------------------------------------------------------
for (int y=0; y<height; y++)
{
for (int x=0; x<width; x++)
{
unsigned int hits=0;
for (int z=0; z<depth; z++)
{
unsigned long memoryLocation = (unsigned long) (z*width*height) + (y*width)+ x;
hits+=state->space[memoryLocation].element;
}
float heatmap = (float) hits / (depth*255);
heatmap*=10;
convertHeatmapValueToRGB(heatmap,&R,&G,&B);
unsigned int pos=(y*width*3) + x*3;
viewMat.data[pos++]=B;
viewMat.data[pos++]=G;
viewMat.data[pos]=R;
}
}
return 1;
}
int main(int argc, char *argv[])
{
struct clusteringOf3DPoses * state3D = (struct clusteringOf3DPoses *) malloc(sizeof(struct clusteringOf3DPoses) );
if (state3D==0)
{
fprintf(stderr,"Could not allocate enough memory to start csvClusterPlot..\n");
return 1;
}
memset(state3D,0,sizeof(struct clusteringOf3DPoses));
struct applicationState * state = (struct applicationState *) malloc(sizeof(struct applicationState) );
if (state==0)
{
fprintf(stderr,"Could not allocate enough memory to start csvClusterPlot..\n");
free(state3D);
return 1;
}
state->rotation=0;
state->previousSelection=0;
state->selectedJoint=0;
state->visualizationType=0;
state->stop=0;
state->save=0;
state->previousVisualizationType=2;// <- force redraw on first loop
state->redraw=1;
state->maxAccumulatedSample= 0;
int randomize=0;
int filterPoses=0;
int go3DMode=0;
unsigned int visualizationFrameNumber=0;
int saveVideo=0;
char * videoPath=0;
char videoFrameFinalFilename[512]= {0};
float skeletonDistance=-160;
unsigned int WIDTH = 1000;
unsigned int HEIGHT = 1000;
unsigned int DEPTH = 1000;
char * selectedSource = defaultList;
for (int i=0; i<argc; i++)
{
if (strcmp(argv[i],"--mocapnet1")==0)
{
selectedSource=MocapNET1List;
}
else if (strcmp(argv[i],"--saveVideo")==0)
{
if(argc>i+1)
{
videoPath=argv[i+1];
saveVideo=1;
mkdir(videoPath,0777);
}
}
else if (strcmp(argv[i],"--from")==0)
{
if(argc>i+1)
{
selectedSource=argv[i+1];
}
}
else if (strcmp(argv[i],"--rotation")==0)
{
if(argc>i+1)
{
state->rotation=atoi(argv[i+1]);
}
}
else if (strcmp(argv[i],"--randomize")==0)
{
randomize=1;
}
else if (strcmp(argv[i],"--filter")==0)
{
filterPoses=1;
}
else if (strcmp(argv[i],"--size")==0)
{
//To produce higher resolution heatmap..
// ./CSVClusterPlot --rotation 90 --onlyrhand --size 1920 1080 --distance -130 --filter
if(argc>i+2)
{
WIDTH=atoi(argv[i+1]);
HEIGHT=atoi(argv[i+2]);
}
}
else if (strcmp(argv[i],"--depth")==0)
{
if(argc>i+1)
{
DEPTH=atoi(argv[i+1]);
}
}
else if (strcmp(argv[i],"--distance")==0)
{
if(argc>i+1)
{
skeletonDistance=atof(argv[i+1]);
}
}
}
state->accumulatedImage = (unsigned long * ) malloc( (WIDTH) * (HEIGHT) * sizeof (unsigned long) );
if (state->accumulatedImage==0)
{
fprintf(stderr,"Could not allocate enough memory to start csvClusterPlot..\n");
free(state);
free(state3D);
return 1;
}
for (int y=0; y<HEIGHT; y++)
{
for (int x=0; x<WIDTH; x++)
{
state->accumulatedImage[y*WIDTH+x]=0;
}
}
state->accumulatedSamples=0;;
cv::Mat viewMat = Mat(Size(WIDTH,HEIGHT),CV_8UC3, Scalar(0,0,0));
namedWindow("BVH",1);
//controls(controlMat,&state);
//cv::moveWindow("3D Control",0,0); //y=inputHeight2DJointDetector
cv::moveWindow("BVH",0,0);
initializeBVHConverter(0,WIDTH,HEIGHT,1);
//------------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------
std::vector<char> activeJoints;
activeJoints.clear();
for (int i=0; i<MOCAPNET_OUTPUT_NUMBER; i++)
{
activeJoints.push_back(1);
}
activeJoints[ getBVHJointIDFromJointName("hip")]=0;
activeJoints[ getBVHJointIDFromJointName("lThigh")]=0;
activeJoints[ getBVHJointIDFromJointName("rThigh")]=0;
activeJoints[ getBVHJointIDFromJointName("lButtock")]=0;
activeJoints[ getBVHJointIDFromJointName("rButtock")]=0;
activeJoints[ getBVHJointIDFromJointName("abdomen")]=0;
//------------------------------------------------------------------------------------------------------------------
for (int i=0; i<argc; i++)
{
if (strcmp(argv[i],"--3d")==0)
{
//Sample use
// ./CSVClusterPlot --3d rHand --size 500 500 --depth 500 --distance -250
// ./CSVClusterPlot --3d rHand --size 256 256 --depth 256 --distance -500
go3DMode=1;
for (int z=0; z<MOCAPNET_OUTPUT_NUMBER; z++)
{
activeJoints[z]=0;
}
//activeJoints[ getBVHJointIDFromJointName("rForeArm")]=1;
if(argc>i+1)
{
activeJoints[ getBVHJointIDFromJointName(argv[i+1])]=1;
}
else
{
fprintf(stderr,"We need a limb to focus on e.g. rHand <- capitalization is imporant..\n");
}
}
else if (strcmp(argv[i],"--onlylimbs")==0)
{
for (int z=0; z<MOCAPNET_OUTPUT_NUMBER; z++)
{
activeJoints[z]=0;
}
activeJoints[ getBVHJointIDFromJointName("rShin")]=1;
activeJoints[ getBVHJointIDFromJointName("rFoot")]=1;
activeJoints[ getBVHJointIDFromJointName("lShin")]=1;
activeJoints[ getBVHJointIDFromJointName("lFoot")]=1;
activeJoints[ getBVHJointIDFromJointName("neck")]=1;
activeJoints[ getBVHJointIDFromJointName("head")]=1;
activeJoints[ getBVHJointIDFromJointName("lForeArm")]=1;
activeJoints[ getBVHJointIDFromJointName("lHand")]=1;
activeJoints[ getBVHJointIDFromJointName("rForeArm")]=1;
activeJoints[ getBVHJointIDFromJointName("rHand")]=1;
}
else if (strcmp(argv[i],"--onlyrhand")==0)
{
for (int z=0; z<MOCAPNET_OUTPUT_NUMBER; z++)
{
activeJoints[z]=0;
}
activeJoints[ getBVHJointIDFromJointName("rForeArm")]=1;
activeJoints[ getBVHJointIDFromJointName("rHand")]=1;
}
else if (strcmp(argv[i],"--onlylhand")==0)
{
for (int z=0; z<MOCAPNET_OUTPUT_NUMBER; z++)
{
activeJoints[z]=0;
}
activeJoints[ getBVHJointIDFromJointName("lForeArm")]=1;
activeJoints[ getBVHJointIDFromJointName("lHand")]=1;
}
else if (strcmp(argv[i],"--onlyrleg")==0)
{
for (int z=0; z<MOCAPNET_OUTPUT_NUMBER; z++)
{
activeJoints[z]=0;
}
activeJoints[ getBVHJointIDFromJointName("rShin")]=1;
activeJoints[ getBVHJointIDFromJointName("rFoot")]=1;
}
else if (strcmp(argv[i],"--onlylleg")==0)
{
for (int z=0; z<MOCAPNET_OUTPUT_NUMBER; z++)
{
activeJoints[z]=0;
}
activeJoints[ getBVHJointIDFromJointName("lShin")]=1;
activeJoints[ getBVHJointIDFromJointName("lFoot")]=1;
}
}
//------------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------
state->redraw=1;
srand(time(NULL));
//find dataset/MotionCapture/ -type f -name "*.bvh" > src/MocapNET2/CSVClusterPlot/listOfFilesToCluster
struct BVH_MotionCapture bvhMotion= {0};
char buffer[1024]= {0};
FILE * fp =0;
fp=fopen(selectedSource,"r");
if (fp==0)
{
fprintf(stderr,"Cannot open list of files to cluster\n");
free(state->accumulatedImage);
free(state);
free(state3D);
return 0;
}
char * line = NULL;
size_t len = 0;
ssize_t read;
unsigned int numberOfLinesProcessed=0;
unsigned long numberOfPosesLoaded=0;
while ((read = getline(&line, &len, fp)) != -1)
{
if (line!=0)
{
++numberOfLinesProcessed;
//-----------------------------------------------------------------
int lineLength=strlen(line);
if (lineLength>0)
{
if (line[lineLength-1]==10)
{
line[lineLength-1]=0;
}
if (line[lineLength-1]==13)
{
line[lineLength-1]=0;
}
}
if (lineLength>1)
{
if (line[lineLength-2]==10)
{
line[lineLength-2]=0;
}
if (line[lineLength-2]==13)
{
line[lineLength-2]=0;
}
}
//-----------------------------------------------------------------
fprintf(stderr,"Loading `%s`\n",line);
if ( bvh_loadBVH(line, &bvhMotion, 1.0) )
{
numberOfPosesLoaded+=bvhMotion.numberOfFrames;
bvh_renameJointsForCompatibility(&bvhMotion);
if (filterPoses)
{
filterOutPosesThatAreCloseToRules(&bvhMotion,35,removeNeutralPosesRules);
}
if (randomize)
{
//--perturbJointAngles 4 38.0 rshoulder lshoulder rhip lhip --perturbJointAngles 8 10.0 rhand relbow lelbow lhand lknee rknee lfoot rfoot
bvh_PerturbJointAngles(
&bvhMotion,
4,
38.0,
perturbList1,
0
);
bvh_PerturbJointAngles(
&bvhMotion,
8,
10.0,
perturbList2,
0
);
bvh_PerturbJointAngles(
&bvhMotion,
2,
10.0,
perturbList3,
0
);
}
if (go3DMode)
{
//3D Voxel Clustering Mode
std::vector<std::vector<float> > aPose = collect3DPoses(state3D,activeJoints,&bvhMotion,skeletonDistance,WIDTH,HEIGHT,DEPTH);
//memset(viewMat.data,0,WIDTH*HEIGHT*3*sizeof(char));
if (numberOfLinesProcessed%5==0)
{ draw3DClustering(viewMat,state3D,WIDTH,HEIGHT,DEPTH); }
drawSkeleton(viewMat,aPose,0,0,1);
}
else
{
//2D Projection Mode
std::vector<std::vector<float> > aPose = collectPoses(state,activeJoints,&bvhMotion,skeletonDistance,WIDTH,HEIGHT);
if ( aPose.size()>0 )
{
state->redraw=1;
}
if (state->redraw)
{
draw2DClustering(viewMat,&bvhMotion,aPose,state,line,videoPath,WIDTH,HEIGHT);
state->redraw=1;
}
}
fprintf(stderr,"Done with %s\n",line);
bvh_free(&bvhMotion);
fprintf(stderr,"deallocation complete..\n");
imshow("BVH", viewMat);
if (saveVideo)
{
snprintf(videoFrameFinalFilename,512,"%s/colorFrame_0_%05u.png",videoPath,visualizationFrameNumber);
imwrite(videoFrameFinalFilename,viewMat);
}
++visualizationFrameNumber;
waitKey(1);
}
else
{
fprintf(stderr,"Failed to load %s \n",line);
}
}//Line not empty
} //New line read
if (line!=0)
{
free(line);
line=0;
len=0;
}
fclose(fp);
// the camera will be deinitialized automatically in VideoCapture destructor
if (go3DMode)
{
fprintf(stderr,"3D clustering accumulated %lu samples \n",state3D->accumulatedSamples);
if (state3D->fp!=0)
{
fclose(state3D->fp);
}
//------------------------------------------------------------------------
int i=system("cat dataset/header.bvh > filteredPoses.bvh");
if (i!=0) { fprintf(stderr,"Could not use header for filterPoses.bvh\n"); }
//------------------------------------------------------------------------
i=system("echo \"MOTION\" >> filteredPoses.bvh");
if (i!=0) { fprintf(stderr,"Could not add MOTION to filterPoses.bvh\n"); }
//------------------------------------------------------------------------
i=system("echo \"Frames: `cat filteredPoses.bvhm | wc -l`\" >> filteredPoses.bvh");
if (i!=0) { fprintf(stderr,"Could not add number of poses\n"); }
//------------------------------------------------------------------------
i=system("echo \"Frame Time: 0.04\" >> filteredPoses.bvh");
if (i!=0) { fprintf(stderr,"Could not add frame time\n"); }
//------------------------------------------------------------------------
i=system("cat filteredPoses.bvhm >> filteredPoses.bvh");
if (i!=0) { fprintf(stderr,"Could not add motion frames\n"); }
//------------------------------------------------------------------------
i=system("rm filteredPoses.bvhm");
if (i!=0) { fprintf(stderr,"Could not remove intermediate motion frames\n"); }
//------------------------------------------------------------------------
}
free(state);
free(state3D);
fprintf(stderr,"Done overlaying %lu poses..!\n",numberOfPosesLoaded);
imshow("BVH", viewMat);
imwrite("csvCluster.png",viewMat);
if (saveVideo)
{
//Low-Res video encoding
//snprintf(videoFrameFinalFilename,512,"ffmpeg -framerate 30 -i %s/colorFrame_0_%%05d.png -y -r 30 -threads 8 -crf 9 -pix_fmt yuv420p %s/video.mp4",videoPath,videoPath);
//High-Res video encoding
snprintf(videoFrameFinalFilename,512,"ffmpeg -framerate 30 -i %s/colorFrame_0_%%05d.png -s 1200x720 -y -r 30 -pix_fmt yuv420p -threads 8 %s/video.mp4",videoPath,videoPath);
int i=system(videoFrameFinalFilename);
if (i==0)
{
fprintf(stderr,"Successfully wrote video file %s/video.mp4.. \n",videoPath);
}
else
{
fprintf(stderr,"Failed to write a video file %s/video.mp4.. \n",videoPath);
}
fprintf(stderr,"Since we wanted to output video this is probably a scripted run, will not wait for a keystroke..\n");
waitKey(1);
}
else
{
waitKey(0);
}
free(state->accumulatedImage);
free(state);
free(state3D);
return 0;
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,282 @@
dataset/MotionCapture/01/01_02.bvh
dataset/MotionCapture/01/01_03.bvh
dataset/MotionCapture/01/01_05.bvh
dataset/MotionCapture/01/01_06.bvh
dataset/MotionCapture/01/01_07.bvh
dataset/MotionCapture/01/01_08.bvh
dataset/MotionCapture/01/01_09.bvh
dataset/MotionCapture/01/01_10.bvh
dataset/MotionCapture/01/01_11.bvh
dataset/MotionCapture/01/01_12.bvh
dataset/MotionCapture/01/01_13.bvh
dataset/MotionCapture/01/01_14.bvh
dataset/MotionCapture/02/02_01.bvh
dataset/MotionCapture/02/02_02.bvh
dataset/MotionCapture/02/02_03.bvh
dataset/MotionCapture/02/02_04.bvh
dataset/MotionCapture/02/02_05.bvh
dataset/MotionCapture/02/02_06.bvh
dataset/MotionCapture/02/02_07.bvh
dataset/MotionCapture/02/02_08.bvh
dataset/MotionCapture/02/02_09.bvh
dataset/MotionCapture/02/02_10.bvh
dataset/MotionCapture/03/03_01.bvh
dataset/MotionCapture/03/03_02.bvh
dataset/MotionCapture/03/03_03.bvh
dataset/MotionCapture/03/03_04.bvh
dataset/MotionCapture/05/05_01.bvh
dataset/MotionCapture/05/05_02.bvh
dataset/MotionCapture/05/05_03.bvh
dataset/MotionCapture/05/05_04.bvh
dataset/MotionCapture/05/05_05.bvh
dataset/MotionCapture/05/05_06.bvh
dataset/MotionCapture/05/05_07.bvh
dataset/MotionCapture/05/05_08.bvh
dataset/MotionCapture/05/05_09.bvh
dataset/MotionCapture/05/05_10.bvh
dataset/MotionCapture/05/05_11.bvh
dataset/MotionCapture/05/05_12.bvh
dataset/MotionCapture/05/05_13.bvh
dataset/MotionCapture/05/05_14.bvh
dataset/MotionCapture/05/05_15.bvh
dataset/MotionCapture/05/05_16.bvh
dataset/MotionCapture/05/05_17.bvh
dataset/MotionCapture/05/05_18.bvh
dataset/MotionCapture/05/05_19.bvh
dataset/MotionCapture/05/05_20.bvh
dataset/MotionCapture/06/06_01.bvh
dataset/MotionCapture/06/06_02.bvh
dataset/MotionCapture/06/06_03.bvh
dataset/MotionCapture/06/06_04.bvh
dataset/MotionCapture/06/06_05.bvh
dataset/MotionCapture/06/06_06.bvh
dataset/MotionCapture/06/06_07.bvh
dataset/MotionCapture/06/06_08.bvh
dataset/MotionCapture/06/06_09.bvh
dataset/MotionCapture/06/06_10.bvh
dataset/MotionCapture/06/06_11.bvh
dataset/MotionCapture/06/06_12.bvh
dataset/MotionCapture/06/06_13.bvh
dataset/MotionCapture/06/06_14.bvh
dataset/MotionCapture/06/06_15.bvh
dataset/MotionCapture/07/07_01.bvh
dataset/MotionCapture/07/07_02.bvh
dataset/MotionCapture/07/07_03.bvh
dataset/MotionCapture/07/07_04.bvh
dataset/MotionCapture/07/07_05.bvh
dataset/MotionCapture/07/07_06.bvh
dataset/MotionCapture/07/07_07.bvh
dataset/MotionCapture/07/07_08.bvh
dataset/MotionCapture/07/07_09.bvh
dataset/MotionCapture/07/07_10.bvh
dataset/MotionCapture/07/07_11.bvh
dataset/MotionCapture/07/07_12.bvh
dataset/MotionCapture/08/08_01.bvh
dataset/MotionCapture/08/08_02.bvh
dataset/MotionCapture/08/08_03.bvh
dataset/MotionCapture/08/08_04.bvh
dataset/MotionCapture/08/08_05.bvh
dataset/MotionCapture/08/08_06.bvh
dataset/MotionCapture/08/08_07.bvh
dataset/MotionCapture/08/08_08.bvh
dataset/MotionCapture/08/08_09.bvh
dataset/MotionCapture/08/08_10.bvh
dataset/MotionCapture/08/08_11.bvh
dataset/MotionCapture/09/09_01.bvh
dataset/MotionCapture/09/09_02.bvh
dataset/MotionCapture/09/09_03.bvh
dataset/MotionCapture/09/09_04.bvh
dataset/MotionCapture/09/09_05.bvh
dataset/MotionCapture/09/09_06.bvh
dataset/MotionCapture/09/09_07.bvh
dataset/MotionCapture/09/09_08.bvh
dataset/MotionCapture/09/09_09.bvh
dataset/MotionCapture/09/09_10.bvh
dataset/MotionCapture/09/09_11.bvh
dataset/MotionCapture/09/09_12.bvh
dataset/MotionCapture/10/10_01.bvh
dataset/MotionCapture/10/10_02.bvh
dataset/MotionCapture/10/10_03.bvh
dataset/MotionCapture/10/10_04.bvh
dataset/MotionCapture/10/10_05.bvh
dataset/MotionCapture/10/10_06.bvh
dataset/MotionCapture/13/13_01.bvh
dataset/MotionCapture/13/13_02.bvh
dataset/MotionCapture/13/13_03.bvh
dataset/MotionCapture/13/13_04.bvh
dataset/MotionCapture/13/13_05.bvh
dataset/MotionCapture/13/13_06.bvh
dataset/MotionCapture/13/13_07.bvh
dataset/MotionCapture/13/13_08.bvh
dataset/MotionCapture/13/13_09.bvh
dataset/MotionCapture/13/13_10.bvh
dataset/MotionCapture/13/13_11.bvh
dataset/MotionCapture/13/13_12.bvh
dataset/MotionCapture/13/13_13.bvh
dataset/MotionCapture/13/13_14.bvh
dataset/MotionCapture/13/13_15.bvh
dataset/MotionCapture/13/13_16.bvh
dataset/MotionCapture/13/13_19.bvh
dataset/MotionCapture/13/13_20.bvh
dataset/MotionCapture/13/13_21.bvh
dataset/MotionCapture/13/13_22.bvh
dataset/MotionCapture/13/13_24.bvh
dataset/MotionCapture/13/13_25.bvh
dataset/MotionCapture/13/13_26.bvh
dataset/MotionCapture/13/13_27.bvh
dataset/MotionCapture/13/13_28.bvh
dataset/MotionCapture/13/13_29.bvh
dataset/MotionCapture/13/13_30.bvh
dataset/MotionCapture/13/13_31.bvh
dataset/MotionCapture/13/13_32.bvh
dataset/MotionCapture/13/13_33.bvh
dataset/MotionCapture/13/13_34.bvh
dataset/MotionCapture/13/13_35.bvh
dataset/MotionCapture/13/13_36.bvh
dataset/MotionCapture/13/13_37.bvh
dataset/MotionCapture/13/13_38.bvh
dataset/MotionCapture/13/13_39.bvh
dataset/MotionCapture/13/13_40.bvh
dataset/MotionCapture/13/13_41.bvh
dataset/MotionCapture/13/13_42.bvh
dataset/MotionCapture/14/14_01.bvh
dataset/MotionCapture/14/14_04.bvh
dataset/MotionCapture/14/14_05.bvh
dataset/MotionCapture/14/14_06.bvh
dataset/MotionCapture/14/14_07.bvh
dataset/MotionCapture/14/14_08.bvh
dataset/MotionCapture/14/14_09.bvh
dataset/MotionCapture/14/14_10.bvh
dataset/MotionCapture/14/14_11.bvh
dataset/MotionCapture/14/14_12.bvh
dataset/MotionCapture/14/14_13.bvh
dataset/MotionCapture/14/14_14.bvh
dataset/MotionCapture/14/14_15.bvh
dataset/MotionCapture/14/14_16.bvh
dataset/MotionCapture/14/14_17.bvh
dataset/MotionCapture/14/14_18.bvh
dataset/MotionCapture/14/14_19.bvh
dataset/MotionCapture/14/14_20.bvh
dataset/MotionCapture/14/14_21.bvh
dataset/MotionCapture/14/14_22.bvh
dataset/MotionCapture/14/14_24.bvh
dataset/MotionCapture/14/14_25.bvh
dataset/MotionCapture/14/14_26.bvh
dataset/MotionCapture/14/14_27.bvh
dataset/MotionCapture/14/14_28.bvh
dataset/MotionCapture/14/14_29.bvh
dataset/MotionCapture/14/14_30.bvh
dataset/MotionCapture/14/14_31.bvh
dataset/MotionCapture/14/14_32.bvh
dataset/MotionCapture/14/14_33.bvh
dataset/MotionCapture/14/14_34.bvh
dataset/MotionCapture/14/14_35.bvh
dataset/MotionCapture/14/14_36.bvh
dataset/MotionCapture/14/14_37.bvh
dataset/MotionCapture/15/15_01.bvh
dataset/MotionCapture/15/15_02.bvh
dataset/MotionCapture/15/15_03.bvh
dataset/MotionCapture/15/15_04.bvh
dataset/MotionCapture/15/15_05.bvh
dataset/MotionCapture/15/15_06.bvh
dataset/MotionCapture/15/15_07.bvh
dataset/MotionCapture/15/15_08.bvh
dataset/MotionCapture/15/15_09.bvh
dataset/MotionCapture/15/15_10.bvh
dataset/MotionCapture/15/15_11.bvh
dataset/MotionCapture/15/15_12.bvh
dataset/MotionCapture/15/15_13.bvh
dataset/MotionCapture/15/15_14.bvh
dataset/MotionCapture/16/16_01.bvh
dataset/MotionCapture/16/16_02.bvh
dataset/MotionCapture/16/16_03.bvh
dataset/MotionCapture/16/16_04.bvh
dataset/MotionCapture/16/16_05.bvh
dataset/MotionCapture/16/16_06.bvh
dataset/MotionCapture/16/16_07.bvh
dataset/MotionCapture/16/16_08.bvh
dataset/MotionCapture/16/16_09.bvh
dataset/MotionCapture/16/16_10.bvh
dataset/MotionCapture/16/16_11.bvh
dataset/MotionCapture/16/16_12.bvh
dataset/MotionCapture/16/16_13.bvh
dataset/MotionCapture/16/16_14.bvh
dataset/MotionCapture/16/16_15.bvh
dataset/MotionCapture/16/16_16.bvh
dataset/MotionCapture/16/16_17.bvh
dataset/MotionCapture/16/16_18.bvh
dataset/MotionCapture/16/16_19.bvh
dataset/MotionCapture/16/16_20.bvh
dataset/MotionCapture/16/16_21.bvh
dataset/MotionCapture/16/16_22.bvh
dataset/MotionCapture/16/16_23.bvh
dataset/MotionCapture/16/16_24.bvh
dataset/MotionCapture/16/16_25.bvh
dataset/MotionCapture/16/16_26.bvh
dataset/MotionCapture/16/16_27.bvh
dataset/MotionCapture/16/16_28.bvh
dataset/MotionCapture/16/16_29.bvh
dataset/MotionCapture/16/16_30.bvh
dataset/MotionCapture/16/16_31.bvh
dataset/MotionCapture/16/16_32.bvh
dataset/MotionCapture/16/16_33.bvh
dataset/MotionCapture/16/16_34.bvh
dataset/MotionCapture/16/16_35.bvh
dataset/MotionCapture/16/16_36.bvh
dataset/MotionCapture/16/16_37.bvh
dataset/MotionCapture/16/16_38.bvh
dataset/MotionCapture/16/16_39.bvh
dataset/MotionCapture/16/16_40.bvh
dataset/MotionCapture/16/16_41.bvh
dataset/MotionCapture/16/16_42.bvh
dataset/MotionCapture/16/16_43.bvh
dataset/MotionCapture/16/16_44.bvh
dataset/MotionCapture/16/16_47.bvh
dataset/MotionCapture/16/16_48.bvh
dataset/MotionCapture/16/16_49.bvh
dataset/MotionCapture/16/16_50.bvh
dataset/MotionCapture/16/16_51.bvh
dataset/MotionCapture/16/16_52.bvh
dataset/MotionCapture/16/16_53.bvh
dataset/MotionCapture/16/16_55.bvh
dataset/MotionCapture/16/16_56.bvh
dataset/MotionCapture/16/16_58.bvh
dataset/MotionCapture/17/17_01.bvh
dataset/MotionCapture/17/17_02.bvh
dataset/MotionCapture/17/17_03.bvh
dataset/MotionCapture/17/17_04.bvh
dataset/MotionCapture/17/17_05.bvh
dataset/MotionCapture/17/17_06.bvh
dataset/MotionCapture/17/17_07.bvh
dataset/MotionCapture/17/17_08.bvh
dataset/MotionCapture/17/17_09.bvh
dataset/MotionCapture/18/18_01.bvh
dataset/MotionCapture/18/18_02.bvh
dataset/MotionCapture/18/18_03.bvh
dataset/MotionCapture/18/18_04.bvh
dataset/MotionCapture/18/18_05.bvh
dataset/MotionCapture/18/18_06.bvh
dataset/MotionCapture/18/18_07.bvh
dataset/MotionCapture/18/18_08.bvh
dataset/MotionCapture/18/18_09.bvh
dataset/MotionCapture/18/18_10.bvh
dataset/MotionCapture/18/18_11.bvh
dataset/MotionCapture/18/18_12.bvh
dataset/MotionCapture/18/18_13.bvh
dataset/MotionCapture/18/18_14.bvh
dataset/MotionCapture/18/18_15.bvh
dataset/MotionCapture/19/19_01.bvh
dataset/MotionCapture/19/19_02.bvh
dataset/MotionCapture/19/19_03.bvh
dataset/MotionCapture/19/19_04.bvh
dataset/MotionCapture/19/19_05.bvh
dataset/MotionCapture/19/19_06.bvh
dataset/MotionCapture/19/19_07.bvh
dataset/MotionCapture/19/19_08.bvh
dataset/MotionCapture/19/19_09.bvh
dataset/MotionCapture/19/19_10.bvh
dataset/MotionCapture/19/19_11.bvh
dataset/MotionCapture/19/19_12.bvh
dataset/MotionCapture/19/19_13.bvh
dataset/MotionCapture/19/19_14.bvh
dataset/MotionCapture/19/19_15.bvh
@@ -0,0 +1,125 @@
#include "perform2DClustering.hpp"
#include "../MocapNETLib2/IO/bvh.hpp"
#include "../../../dependencies/RGBDAcquisition/opengl_acquisition_shared_library/opengl_depth_and_color_renderer/src/Library/MotionCaptureLoader/bvh_loader.h"
#include "../../../dependencies/RGBDAcquisition/opengl_acquisition_shared_library/opengl_depth_and_color_renderer/src/Library/MotionCaptureLoader/edit/bvh_filter.h"
#include "../../../dependencies/RGBDAcquisition/opengl_acquisition_shared_library/opengl_depth_and_color_renderer/src/Library/MotionCaptureLoader/edit/bvh_rename.h"
#include "../../../dependencies/RGBDAcquisition/opengl_acquisition_shared_library/opengl_depth_and_color_renderer/src/Library/MotionCaptureLoader/edit/bvh_randomize.h"
std::vector<std::vector<float> > collectPoses(
struct applicationState * state,
std::vector<char> &activeJoints,
struct BVH_MotionCapture * bvhMotion,
float distance,
unsigned int width,
unsigned int height
)
{
std::vector<std::vector<float> > bvh2DPoints;
if (bvhMotion==0)
{
return bvh2DPoints;
}
std::vector<float> bvhConfiguration;
bvhConfiguration.clear();
for (int i=0; i<bvhMotion->numberOfValuesPerFrame; i++)
{
bvhConfiguration.push_back(0.0);
}
bvhConfiguration[2]=(float) -150.0;
if ( bvhConfiguration.size() < bvhMotion->numberOfValuesPerFrame)
{
return bvh2DPoints;
}
unsigned int mID=0;
fprintf(stderr,"Collecting %u poses\n",bvhMotion->numberOfFrames);
// state->maxAccumulatedSample= 0;
for (int frameID=0; frameID<bvhMotion->numberOfFrames; frameID++)
{
//fprintf(stderr,".%u",frameID);
for (int i=0; i<bvhMotion->numberOfValuesPerFrame; i++)
{
//fprintf(stderr,"%u ",i);
int motionValueID = mID % (bvhMotion->numberOfValuesPerFrame * bvhMotion->numberOfFrames);
bvhConfiguration[i]=bvhMotion->motionValues[motionValueID];
++mID;
}
//fprintf(stderr,"!");
if (bvhConfiguration.size()>5)
{
bvhConfiguration[0]=0;
bvhConfiguration[1]=0;
bvhConfiguration[2]=distance;
bvhConfiguration[3]=0;
bvhConfiguration[4]=state->rotation;
bvhConfiguration[5]=0;
bvh2DPoints = convertBVHFrameTo2DPoints(bvhConfiguration); //,width, height
if (bvh2DPoints.size()>0)
{
++state->accumulatedSamples;
for (int i=0; i<bvh2DPoints.size(); i++)
{
//We want to exclude Hip joint because it is stuck in the same place for every frame..!
if (
( activeJoints[i] ) &&
( (bvh2DPoints[i][0]>0) && (bvh2DPoints[i][1]>0) && (bvh2DPoints[i][0]<width) && (bvh2DPoints[i][1]<height) )
)
{
unsigned int x=(unsigned int) bvh2DPoints[i][0];
unsigned int y=(unsigned int) bvh2DPoints[i][1];
if ( (x<width) && (y<height) )
{
unsigned long newValue = state->accumulatedImage[y*width+x] + 1;
if (newValue<=state->accumulatedSamples)
{
state->accumulatedImage[y*width+x] = newValue;
if (state->maxAccumulatedSample<newValue)
{
state->maxAccumulatedSample=newValue;
//fprintf(stderr,"Pixel %u,%u has largest value %lu\n",x,y,newValue);
}
}
}
else
{
fprintf(stderr,"%0.2f,%0.2f wrongly casted to %u,%u",bvh2DPoints[i][0],bvh2DPoints[i][1],x,y);
}
}
}
}
else
{
fprintf(stderr,"Could not project BVH 2D points\n");
}
}
} //For every frame loop..
return bvh2DPoints;
}
@@ -0,0 +1,28 @@
#pragma once
#include <stdio.h>
#include <vector>
struct applicationState
{
int rotation;
int selectedJoint,previousSelection;
int visualizationType,previousVisualizationType;
int stop;
int save;
int redraw;
//-----------------
unsigned long * accumulatedImage;
unsigned long accumulatedSamples;
unsigned long maxAccumulatedSample;
};
std::vector<std::vector<float> > collectPoses(
struct applicationState * state,
std::vector<char> &activeJoints,
struct BVH_MotionCapture * bvhMotion,
float distance,
unsigned int width,
unsigned int height
);
@@ -0,0 +1,223 @@
#include "perform3DClustering.hpp"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../MocapNETLib2/IO/bvh.hpp"
#include "../../../dependencies/RGBDAcquisition/opengl_acquisition_shared_library/opengl_depth_and_color_renderer/src/Library/MotionCaptureLoader/bvh_loader.h"
#include "../../../dependencies/RGBDAcquisition/opengl_acquisition_shared_library/opengl_depth_and_color_renderer/src/Library/MotionCaptureLoader/edit/bvh_filter.h"
#include "../../../dependencies/RGBDAcquisition/opengl_acquisition_shared_library/opengl_depth_and_color_renderer/src/Library/MotionCaptureLoader/edit/bvh_rename.h"
#include "../../../dependencies/RGBDAcquisition/opengl_acquisition_shared_library/opengl_depth_and_color_renderer/src/Library/MotionCaptureLoader/edit/bvh_randomize.h"
#define NORMAL "\033[0m"
#define BLACK "\033[30m" /* Black */
#define RED "\033[31m" /* Red */
#define GREEN "\033[32m" /* Green */
#define YELLOW "\033[33m" /* Yellow */
int appendBVHVectorToFile(FILE * fp, std::vector<float> vec)
{
if ( (fp!=0) && (vec.size()>0) )
{
for (unsigned int i=0; i<vec.size(); i++)
{
if (i!=0) { fprintf(fp," "); }
fprintf(fp,"%0.2f",vec[i]);
}
fprintf(fp,"\n");
return 1;
}
return 0;
}
std::vector<std::vector<float> > collect3DPoses(
struct clusteringOf3DPoses * state,
std::vector<char> &activeJoints,
struct BVH_MotionCapture * bvhMotion,
float distance,
unsigned int width,
unsigned int height,
unsigned int depth
)
{
std::vector<std::vector<float> > bvh2DPointsFront;
std::vector<std::vector<float> > bvh2DPointsSide;
if (bvhMotion==0)
{
//Return an empty vector of vectors..
return bvh2DPointsFront;
}
if (state->fp==0)
{
state->fp = fopen("filteredPoses.bvhm","w");
}
if (state->space==0)
{
state->allocatedSpaceMemorySize = width * height * depth * sizeof(struct voxelElement);
fprintf(stderr,"Will now try to allocate a huge chunk of memory (%lu bytes)\n",state->allocatedSpaceMemorySize);
state->space = (struct voxelElement * ) malloc(state->allocatedSpaceMemorySize);
if (state->space!=0)
{
fprintf(stderr,"Will now try to cleanup the huge chunk of memory (%lu bytes)\n",state->allocatedSpaceMemorySize);
memset(state->space,0,state->allocatedSpaceMemorySize);
fprintf(stderr,"Survived..\n");
} else
{
state->allocatedSpaceMemorySize=0;
fprintf(stderr,"Error allocating a huge chunk of memory..!\n");
return bvh2DPointsFront;
}
}
std::vector<float> bvhConfiguration;
bvhConfiguration.clear();
for (int i=0; i<bvhMotion->numberOfValuesPerFrame; i++)
{
bvhConfiguration.push_back(0.0);
}
bvhConfiguration[2]=(float) -150.0;
if (bvhMotion==0)
{
return bvh2DPointsFront;
}
if ( bvhConfiguration.size() < bvhMotion->numberOfValuesPerFrame)
{
return bvh2DPointsFront;
}
unsigned int mID=0;
fprintf(stderr,"Collecting %u poses\n",bvhMotion->numberOfFrames);
// state->maxAccumulatedSample= 0;
unsigned int negativesAtThisCall=0;
unsigned int hitsAtThisCall=0;
for (int frameID=0; frameID<bvhMotion->numberOfFrames; frameID++)
{
//fprintf(stderr,".%u",frameID);
for (int i=0; i<bvhMotion->numberOfValuesPerFrame; i++)
{
//fprintf(stderr,"%u ",i);
int motionValueID = mID % (bvhMotion->numberOfValuesPerFrame * bvhMotion->numberOfFrames);
bvhConfiguration[i]=bvhMotion->motionValues[motionValueID];
++mID;
}
//fprintf(stderr,"!");
if (bvhConfiguration.size()>5)
{
bvhConfiguration[0]=0;
bvhConfiguration[1]=0;
bvhConfiguration[2]=distance;
bvhConfiguration[3]=0;
bvhConfiguration[4]=0;
bvhConfiguration[5]=0;
bvhConfiguration[4]=0;
bvh2DPointsFront = convertBVHFrameTo2DPoints(bvhConfiguration); //,width,height
bvhConfiguration[4]=90;
bvh2DPointsSide = convertBVHFrameTo2DPoints(bvhConfiguration); //,width,height
bvhConfiguration[4]=0; // So the configuration we save is ok
if ( (bvh2DPointsFront.size()>0) && (bvh2DPointsSide.size()>0) && (bvh2DPointsFront.size()==bvh2DPointsSide.size()) )
{
for (int i=0; i<bvh2DPointsFront.size(); i++)
{
//We want to exclude Hip joint because it is stuck in the same place for every frame..!
if (
(activeJoints[i]) &&
( (bvh2DPointsFront[i][0]>0) && (bvh2DPointsFront[i][1]>0) && (bvh2DPointsFront[i][0]<width) && (bvh2DPointsFront[i][1]<height) ) &&
( (bvh2DPointsSide[i][0]>0) && (bvh2DPointsSide[i][1]>0) && (bvh2DPointsSide[i][0]<depth) && (bvh2DPointsSide[i][1]<height) )
)
{
unsigned int x=(unsigned int) bvh2DPointsFront[i][0];
unsigned int y=(unsigned int) bvh2DPointsFront[i][1];
unsigned int z=(unsigned int) bvh2DPointsSide[i][0];
//fprintf(stderr,"x=%u,y=%u,z=%u\n",x,y,z);
if ( (x<width) && (y<height) && (z<depth) )
{
unsigned long memoryLocation = (unsigned long) (z*width*height) + (y*width)+ x;
if (state->allocatedSpaceMemorySize>memoryLocation)
{
if (state->space[memoryLocation].element==0)
{
++state->accumulatedSamples;
appendBVHVectorToFile(state->fp, bvhConfiguration);
++hitsAtThisCall;
state->space[memoryLocation].element=1;
} else
{
++negativesAtThisCall;
if (state->space[memoryLocation].element<254)
{
state->space[memoryLocation].element+=1;
}
}
/*
if (newValue<=state->accumulatedSamples)
{
state->space[memoryLocation].element = newValue;
if (state->maxAccumulatedSample<newValue)
{
state->maxAccumulatedSample=newValue;
//fprintf(stderr,"Pixel %u,%u has largest value %lu\n",x,y,newValue);
}
} */
} else
{
fprintf(stderr,"Bad memory location for %u,%u,%u \n",x,y,z);
}
}
else
{
fprintf(stderr,"%0.2f,%0.2f wrongly casted to %u,%u",bvh2DPointsFront[i][0],bvh2DPointsFront[i][1],x,y);
}
}
}
}
else
{
fprintf(stderr,"Could not project BVH 2D points\n");
}
}
} //For every frame loop..
if (hitsAtThisCall>0)
{
fprintf(stderr,GREEN "Added %u more poses (%0.2f%% of the dataset is novel)..\n" NORMAL,hitsAtThisCall,(float) (100*hitsAtThisCall)/bvhMotion->numberOfFrames);
} else
{
fprintf(stderr,YELLOW "No new poses observed ( %u/%u negatives )..\n" NORMAL,negativesAtThisCall,bvhMotion->numberOfFrames);
}
return bvh2DPointsFront;
}
@@ -0,0 +1,35 @@
#pragma once
#include <stdio.h>
#include <vector>
struct voxelElement
{
char element;
};
struct clusteringOf3DPoses
{
FILE *fp;
struct voxelElement * space;
unsigned long allocatedSpaceMemorySize;
unsigned int width,height,depth;
unsigned long accumulatedSamples;
unsigned long maxAccumulatedSample;
};
std::vector<std::vector<float> > collect3DPoses(
struct clusteringOf3DPoses * state,
std::vector<char> &activeJoints,
struct BVH_MotionCapture * bvhMotion,
float distance,
unsigned int width,
unsigned int height,
unsigned int depth
);