Add MocapNET

This commit is contained in:
Justin John
2023-12-15 04:22:41 +05:30
parent 8434144ded
commit 65e8934d5e
336 changed files with 100584 additions and 0 deletions
@@ -0,0 +1,36 @@
project( convertH36GroundTruthToMocapNETInput )
cmake_minimum_required(VERSION 3.5)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
include_directories(${TENSORFLOW_INCLUDE_ROOT})
#-----------------------------------------------
# This is the converter utilities..
#-----------------------------------------------
add_executable(
convertH36GroundTruthToMocapNETInput
convertH36GroundTruthToMocapNETInput.cpp
../../MocapNETLib2/tools.cpp
../../MocapNETLib2/IO/jsonRead.cpp
../../MocapNETLib2/IO/jsonMocapNETHelpers.cpp
../../../../dependencies/InputParser/InputParser_C.cpp
${BVH_SOURCE}
${OPENGL_SOURCE}
../../MocapNETLib2/IO/bvh.cpp
../../MocapNETLib2/IO/conversions.cpp
../../MocapNETLib2/IO/csvRead.cpp
../../MocapNETLib2/IO/csvWrite.cpp
)
#-----------------------------------------------
target_link_libraries(convertH36GroundTruthToMocapNETInput rt dl m pthread MocapNETLib2)
set_target_properties(convertH36GroundTruthToMocapNETInput PROPERTIES DEBUG_POSTFIX "D")
set_target_properties(convertH36GroundTruthToMocapNETInput PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}"
)
@@ -0,0 +1,241 @@
/*
* Export utility from OpenPose BODY 25 JSON format to a more regular CSV file
* Sample call : ./convertBody25JSONToCSV --from frames/GOPR3223.MP4-data/ --label colorFrame_0_ -o .
* */
#include <iostream>
#include <vector>
#include <math.h>
#include <string.h>
#include "../../../MocapNET2/MocapNETLib2/tools.hpp"
#include "../../../MocapNET2/MocapNETLib2/mocapnet2.hpp"
#include "../../../MocapNET2/MocapNETLib2/IO/commonSkeleton.hpp"
#include "../../../MocapNET2/MocapNETLib2/IO/jsonRead.hpp"
#include "../../../MocapNET2/MocapNETLib2/IO/csvRead.hpp"
#include "../../../MocapNET2/MocapNETLib2/IO/csvWrite.hpp"
#if USE_BVH
#include "../../../../dependencies/RGBDAcquisition/tools/AmMatrix/matrix4x4Tools.h"
#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/calculate/bvh_project.h"
#include "../../../../dependencies/RGBDAcquisition/opengl_acquisition_shared_library/opengl_depth_and_color_renderer/src/Library/MotionCaptureLoader/calculate/bvh_transform.h"
#include "../../../../dependencies/RGBDAcquisition/opengl_acquisition_shared_library/opengl_depth_and_color_renderer/src/Library/MotionCaptureLoader/ik/bvh_inverseKinematics.h"
#else
#warning "BVH code not included.."
#endif // USE_BVH
#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 main(int argc, char *argv[])
{
#if USE_BVH
float fX = 582.18394; //570.0
float fY = 582.52915; //570.0
unsigned int width = 1920;
unsigned int height = 1080;
struct simpleRenderer renderer= {0};
simpleRendererDefaults(
&renderer,
width,//1920
height,//1080
fX, //570.0
fY //570.0
);
simpleRendererInitialize(&renderer);
const char * path=0;
const char * label=0;
char outputPathFull[2048]= {"./h36ToMnet.csv"};
const char * outputPath=outputPathFull;
float offsetX=0.0,offsetY=0.0,offsetZ=0.0;
int flipX=0;
int flipY=1;
for (int i=0; i<argc; i++)
{
if (strcmp(argv[i],"--from")==0)
{
path = argv[i+1];
}
else if (strcmp(argv[i],"--to")==0)
{
outputPath = argv[i+1];
}
else if (strcmp(argv[i],"--offset")==0)
{
offsetX=atof(argv[i+1]);
offsetY=atof(argv[i+2]);
offsetZ=atof(argv[i+3]);
}
else if (strcmp(argv[i],"--flipX")==0)
{
offsetX=atof(argv[i+1]);
offsetY=atof(argv[i+2]);
offsetZ=atof(argv[i+3]);
}
}
std::vector<std::vector<float> > result;
std::vector<float> points2DOfASpecificFrame;
struct CSVFileContext csv= {0};
struct CSVFloatFileLine csvLine= {0};
if ( openCSVFile(&csv,path) )
{
parseCSVHeader(&csv);
while (parseNextCSVFloatLine(&csv,&csvLine))
{
points2DOfASpecificFrame.clear();
float pos3D[4]= {0};
//pos3D[3]=1.0;
float position2DX=0,position2DY=0,position2DW=0;
float center[4]= {0};
float rotation[3]= {0};
float hipX = csvLine.field[9 * 3 + 0];
float hipY = csvLine.field[9 * 3 + 1];
float hipZ = csvLine.field[9 * 3 + 2];
for (unsigned int pointID=0; pointID<csv.numberOfHeaderFields/3; pointID++)
{
//--------------------------------------
pos3D[0]=(float) (csvLine.field[pointID * 3 + 0]) + offsetX;
pos3D[1]=(float) (csvLine.field[pointID * 3 + 1]) + offsetY;
pos3D[2]=(float) -1 * (csvLine.field[pointID * 3 + 2]) + offsetZ;
//fprintf(stderr,"Projecting %0.2f,%0.2f,%0.2f : ",pos3D[0],pos3D[1],pos3D[2]);
//--------------------------------------
if (
simpleRendererRender(
&renderer,
pos3D,
center,
rotation,
ROTATION_ORDER_RPY,
&position2DX,
&position2DY,
&position2DW
)
)
{
if (flipX)
{
position2DX = width - position2DX;
}
if (flipY)
{
position2DY = height - position2DY;
}
if (position2DW>0.0)
{
//fprintf(stderr,"output is %0.2f,%0.2f \n",position2DX,position2DY);
points2DOfASpecificFrame.push_back((float) position2DX);
points2DOfASpecificFrame.push_back((float) position2DY);
}
else
{
//fprintf(stderr,"behind camera(%0.2f).. %0.2f,%0.2f \n",position2DW,position2DX,position2DY);
points2DOfASpecificFrame.push_back(0.0);
points2DOfASpecificFrame.push_back(0.0);
}
} else
{
points2DOfASpecificFrame.push_back(0.0);
points2DOfASpecificFrame.push_back(0.0);
}
}
result.push_back(points2DOfASpecificFrame);
}
if (result.size()>0)
{
FILE * fp = fopen(outputPath,"w");
if (fp!=0)
{
fprintf(fp,"frameNumber,skeletonID,totalSkeletons");
for (unsigned int pointID=0; pointID<csv.numberOfHeaderFields/3; pointID++)
{
char * pointLabel = csv.field[pointID*3].str + 4;
//Translate H36M labels to MNET labels..
if ( strcmp(pointLabel,"nose")==0 ) { fprintf(fp,",2DX_head,2DY_head,visible_head"); } else
if ( strcmp(pointLabel,"rwrist")==0 ) { fprintf(fp,",2DX_rhand,2DY_rhand,visible_rhand"); } else
if ( strcmp(pointLabel,"lwrist")==0 ) { fprintf(fp,",2DX_lhand,2DY_lhand,visible_lhand"); } else
if ( strcmp(pointLabel,"midhip")==0 ) { fprintf(fp,",2DX_hip,2DY_hip,visible_hip"); } else
//rankle/lankle instead..
if ( strcmp(pointLabel,"rheel")==0 ) { fprintf(fp,",2DX_rfoot,2DY_rfoot,visible_rfoot"); } else
if ( strcmp(pointLabel,"lheel")==0 ) { fprintf(fp,",2DX_lfoot,2DY_lfoot,visible_lfoot"); } else
if ( strcmp(pointLabel,"reye")==0 ) { fprintf(fp,",2DX_endsite_eye.r,2DY_endsite_eye.r,visible_endsite_eye.r"); } else
if ( strcmp(pointLabel,"leye")==0 ) { fprintf(fp,",2DX_endsite_eye.l,2DY_endsite_eye.l,visible_endsite_eye.l"); } else
if ( strcmp(pointLabel,"rbigtoe")==0 ) { fprintf(fp,",2DX_endsite_toe1-2.r,2DY_endsite_toe1-2.r,visible_endsite_toe1-2.r"); } else
if ( strcmp(pointLabel,"lbigtoe")==0 ) { fprintf(fp,",2DX_endsite_toe1-2.l,2DY_endsite_toe1-2.l,visible_endsite_toe1-2.l"); } else
if ( strcmp(pointLabel,"rsmalltoe")==0 ) { fprintf(fp,",2DX_endsite_toe5-3.r,2DY_endsite_toe5-3.r,visible_endsite_toe5-3.r"); } else
if ( strcmp(pointLabel,"lsmalltoe")==0 ) { fprintf(fp,",2DX_endsite_toe5-3.l,2DY_endsite_toe5-3.l,visible_endsite_toe5-3.l"); } else
{ fprintf(fp,",2DX_%s,2DY_%s,visible_%s",pointLabel,pointLabel,pointLabel); }
}
fprintf(fp,"\n");
for (unsigned int frameID=0; frameID<result.size(); frameID++)
{
fprintf(fp,"%u,0,0",frameID);
for (unsigned int pointID=0; pointID<result[frameID].size(); pointID++)
{
float normalizedPoint = result[frameID][pointID];
unsigned int element = pointID%2;
if (element==0) { normalizedPoint/= width; fprintf(fp,",%f",normalizedPoint); } else
{ normalizedPoint/= height; fprintf(fp,",%f,1",normalizedPoint); }
}
fprintf(fp,"\n");
}
fclose(fp);
}
}
closeCSVFile(&csv);
}
#else
fprintf(stderr,"This utility is only available if you compile the BVH code in..\n");
#endif
return 0;
}
@@ -0,0 +1,37 @@
project( convertOpenPoseJSONToCSV )
cmake_minimum_required(VERSION 3.5)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
include_directories(${TENSORFLOW_INCLUDE_ROOT})
#-----------------------------------------------
# This is the converter utilities..
#-----------------------------------------------
add_executable(
convertOpenPoseJSONToCSV
convertOpenPoseJSONToCSV.cpp
../../MocapNETLib2/tools.cpp
../../MocapNETLib2/IO/jsonRead.cpp
../../MocapNETLib2/IO/jsonMocapNETHelpers.cpp
../../../../dependencies/InputParser/InputParser_C.cpp
${BVH_SOURCE}
${OPENGL_SOURCE}
../../MocapNETLib2/IO/bvh.cpp
../../MocapNETLib2/IO/csvWrite.cpp
)
#-----------------------------------------------
target_link_libraries(convertOpenPoseJSONToCSV rt dl m pthread MocapNETLib2)
set_target_properties(convertOpenPoseJSONToCSV PROPERTIES DEBUG_POSTFIX "D")
set_target_properties(convertOpenPoseJSONToCSV PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}"
)
@@ -0,0 +1,284 @@
/*
* Export utility from OpenPose BODY25 + Hands + Face JSON format to a trivially parseable CSV file
* Check https://github.com/CMU-Perceptual-Computing-Lab/openpose/blob/master/doc/output.md on more information on OpenPose JSON files..
*
* Sample call : ./convertOpenPoseJSONToCSV --from frames/GOPR3223.MP4-data/ --label colorFrame_0_ -o .
*
* This utility converts OpenPose json output to a CSV file that can be easily parsed and used as MocapNET input
*
* My workflow when working with OpenPose is first dumping any video file that I want to process (let's call it video.mp4) to images using ffmpeg.
* This ensures a well defined framerate and a well defined 1:1 correspondence of color/json/and my output frames regardless of video container.
*
* I typically use this script -> https://github.com/AmmarkoV/RGBDAcquisition/blob/master/grabber/frames/dump_video.sh to dump the video to files
* but it is equivalent to running :
* mkdir videoFiles && ffmpeg -i video.mp4 -r 30 -q:v 1 videoFiles/colorFrame_0_%05d.jpg && cp videoFiles/colorFrame_0_00001.jpg videoFiles/colorFrame_0_00000.jpg
*
* Having a well defined serialized version of the dataset ( with serial numbers that start from 0 instead of 1 ) we can be sure on what frame each openpose output will correspond
*
* Running :
* openpose.bin -number_people_max 1 --hand --face --write_json videoFiles/ -image_dir videoFiles/
*
* The directory will be populated with colorFrame_0_xxxxx_keypoints.json files
* each of the colorFrame_0_xxxxx_keypoints.json will correspond to a colorFrame_0_xxxxx.jpg
*
* This can then be converted to a CSV file using :
* ./convertOpenPoseJSONToCSV --from videoFiles/
*
*
* If you want to use a custom json labeling scheme and not rely on images as OpenPose input you will need to :
*
* 1) provide the proper image resolution ( since the JSON files alone do not have this information )
* The image resolution is *CRUCIAL* for the software to correctly normalize input 2D points and respect the training aspect ratio
* if you don't supply the correct size a Full-HD(1920x1080p) input will be assumed. If this does not correspond to the original video resolution output will be adversly affected
* You can do this with the --size WIDTH HEIGHT parameter
*
* 2) Depending on your datasets and filenames supply the proper number of characters for a valid serial frame number length
* i.e. frame_xxxxx_keypoints.json needs --seriallength 5
* frame_xxxxxxx_keypoints.json needs --seriallength 7
* etc
*
* 3) Depending on your datasets and filenames supply the correct label for the dataset
* i.e. datasetNameA_xxxxx_keypoints.json needs --label datasetNameA
* AMoreComplexLabel_IsTHIS_0_xxxxxxx_keypoints.json needs --label AMoreComplexLabel_IsTHIS_0
* etc
*
* 4) Depending on the starting frame and ending frame of your dataset supply the --startAt X , --maxFrames X
* i.e dataset_00001_keypoints.json - dataset_00101_keypoints.json should need --startAt 1 --maxFrames 102
* i.e dataset_00000_keypoints.json - dataset_0099_keypoints.json should need --startAt 0 --maxFrames 100
*
* */
#include <iostream>
#include <vector>
#include <math.h>
#include <string.h>
#include "../../../MocapNET2/MocapNETLib2/tools.hpp"
#include "../../../MocapNET2/MocapNETLib2/mocapnet2.hpp"
#include "../../../MocapNET2/MocapNETLib2/IO/commonSkeleton.hpp"
#include "../../../MocapNET2/MocapNETLib2/IO/jsonRead.hpp"
#include "../../../MocapNET2/MocapNETLib2/IO/csvRead.hpp"
#include "../../../MocapNET2/MocapNETLib2/IO/csvWrite.hpp"
#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 findFirstJSONFileInDirectory(const char * path,const char * formatString, const char * label, unsigned int * frameIDOutput)
{
char filePathOfJSONFile[1025]={0};
const int maximumFilesToSearchFor=1000;
unsigned int frameID=0;
int found=0;
while (!found)
{
snprintf(filePathOfJSONFile,1024,formatString,path,label,frameID);
if( fileExists(filePathOfJSONFile) )
{
*frameIDOutput=frameID;
return 1;
}
++frameID;
if (frameID==maximumFilesToSearchFor)
{
fprintf(stderr,"Stopping search after %u checks ..\n",maximumFilesToSearchFor);
break;
//return 0;
}
}
fprintf(stderr,"findFirstJSONFileInDirectory: failed to find any JSON files.. :(\n");
fprintf(stderr,"Path : %s \n",path);
fprintf(stderr,"Format : %s \n",formatString);
fprintf(stderr,"Label : %s \n",label);
return 0;
}
int main(int argc, char *argv[])
{
unsigned int respectTrainingAspectRatio = 1;
unsigned int width=1920 , height=1080 , frameLimit=100000 , processed = 0 , serialLength = 5 ,forcedSize=0;
const char * path=0;
const char * label=0;
char outputPathFull[2048]={0};
const char * outputPath=0;
float version=1.4;
int noLabel=0;
float acceptableThreshold = 0.5;
for (int i=0; i<argc; i++)
{
if (strcmp(argv[i],"--maxFrames")==0)
{
frameLimit=atoi(argv[i+1]);
}
else if (strcmp(argv[i],"--from")==0)
{
path = argv[i+1];
}
else if (strcmp(argv[i],"--threshold")==0)
{
acceptableThreshold = atof(argv[i+1]);
}
else if (strcmp(argv[i],"-i")==0)
{
path = argv[i+1];
}
else if (strcmp(argv[i],"--label")==0)
{
label = argv[i+1];
}
else if (strcmp(argv[i],"--out")==0)
{
outputPath = argv[i+1];
}
else if (strcmp(argv[i],"--ignoreTrainingAspectRatio")==0)
{
fprintf(stderr,RED "Training aspect ratio is going to be ignored during training..!\n" NORMAL);
fprintf(stderr,RED "this is not a good idea unless you really know what you are doing\n" NORMAL);
respectTrainingAspectRatio = 0;
}
else if (strcmp(argv[i],"-o")==0)
{
outputPath = argv[i+1];
}
else if (strcmp(argv[i],"--to")==0)
{
outputPath = argv[i+1];
}
else if (strcmp(argv[i],"-v")==0)
{
version = atof(argv[i+1]);
}
else if (strcmp(argv[i],"--seriallength")==0)
{
serialLength = atoi(argv[i+1]);
}
else if (strcmp(argv[i],"--size")==0)
{
width = atoi(argv[i+1]);
height = atoi(argv[i+2]);
forcedSize=1;
}
else if (strcmp(argv[i],"--nolabel")==0)
{
//New datasets dont have a label in the filename..!
noLabel =1 ;
}
}
if (path==0)
{
path="./";
}
if (label==0)
{
label="colorFrame_0_";
}
if (noLabel)
{
label="";
}
if (outputPath==0)
{
snprintf(outputPathFull,2048,"%s/2dJoints_v%0.1f.csv",path,version);
}
else
{
if (strstr(outputPath,".csv")!=0)
{
fprintf(stderr,"Output path is actually a csv file so treating it as one..\n");
snprintf(outputPathFull,2048,"%s",outputPath);
} else
{
snprintf(outputPathFull,2048,"%s/2dJoints_v%0.1f.csv",outputPath,version);
}
}
char formatString[256]= {0};
char filePathOfJSONFile[2048]= {0};
snprintf(formatString,256,"%%s/%%s%%0%uu.jpg",serialLength);
snprintf(filePathOfJSONFile,2048,formatString,path,label,1/*Frame ID*/);
snprintf(formatString,256,"%%s/%%s%%0%uu_keypoints.json",serialLength);
if (!forcedSize)
{
if ( getImageWidthHeight(filePathOfJSONFile,&width,&height) )
{
fprintf(stderr,"Image dimensions changed from default to %ux%u",width,height);
}
else
{
fprintf(stderr,"Assuming default image dimensions %ux%u , you can change this using --size x y\n",width,height);
}
} else
{
fprintf(stderr,"Forcing size due to --size %u %u commandline parameter\n",width,height);
}
float totalTime=0.0;
unsigned int totalSamples=0;
struct skeletonStructure skeleton;
memset(&skeleton,0,sizeof(struct skeletonStructure));
unsigned int frameID=1;
fprintf(stderr,"Threshold is set to %0.2f\n",acceptableThreshold);
fprintf(stderr,"Processing : \n");
if ( findFirstJSONFileInDirectory(path, formatString,label,&frameID) )
{
frameLimit+=frameID;
fprintf(stderr,"First frame is %u, last will be %u \n",frameID,frameLimit);
} else
{
fprintf(stderr,RED "Failed to find a JSON file..!\n " NORMAL);
return 0;
}
while (frameID<frameLimit)
{
snprintf(filePathOfJSONFile,1024,formatString,path,label,frameID);
fprintf(stderr,"%s (%ux%u)\n",filePathOfJSONFile,width,height);
if (parseJsonCOCOSkeleton(filePathOfJSONFile,&skeleton,acceptableThreshold,processed))
{
if (processed==0)
{
writeOpenPoseCSVHeaderFromSkeleton(outputPathFull,&skeleton,width,height);
}
if (skeleton.leftHand.isPopulated) { fprintf(stderr,GREEN "Left Hand " NORMAL); }
if (skeleton.rightHand.isPopulated) { fprintf(stderr,GREEN "Right Hand " NORMAL); }
if (skeleton.body.isPopulated) { fprintf(stderr,GREEN "Body " NORMAL); }
if (skeleton.head.isPopulated) { fprintf(stderr,GREEN "Head " NORMAL); }
writeOpenPoseCSVBodyFromSkeleton(outputPathFull,&skeleton,respectTrainingAspectRatio,width,height);
++processed;
}
else
{
fprintf(stderr,"Done processing %u frames..\n",frameID);
fprintf(stderr,"Output has been stored at %s \n",outputPathFull);
break;
}
++frameID;
}
return 0;
}
@@ -0,0 +1,36 @@
project( convertCSV3DToMocapNETInput )
cmake_minimum_required(VERSION 3.5)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
include_directories(${TENSORFLOW_INCLUDE_ROOT})
#-----------------------------------------------
# This is the converter utilities..
#-----------------------------------------------
add_executable(
convertCSV3DToMocapNETInput
convertCSV3DToMocapNETInput.cpp
../../MocapNETLib2/tools.cpp
../../MocapNETLib2/IO/jsonRead.cpp
../../MocapNETLib2/IO/jsonMocapNETHelpers.cpp
../../../../dependencies/InputParser/InputParser_C.cpp
${BVH_SOURCE}
${OPENGL_SOURCE}
../../MocapNETLib2/IO/bvh.cpp
../../MocapNETLib2/IO/conversions.cpp
../../MocapNETLib2/IO/csvRead.cpp
../../MocapNETLib2/IO/csvWrite.cpp
)
#-----------------------------------------------
target_link_libraries(convertCSV3DToMocapNETInput rt dl m pthread MocapNETLib2)
set_target_properties(convertCSV3DToMocapNETInput PROPERTIES DEBUG_POSTFIX "D")
set_target_properties(convertCSV3DToMocapNETInput PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}"
)
@@ -0,0 +1,322 @@
/*
* Export utility from OpenPose BODY 25 JSON format to a more regular CSV file
* Sample call : ./convertBody25JSONToCSV --from frames/GOPR3223.MP4-data/ --label colorFrame_0_ -o .
* */
#include <iostream>
#include <vector>
#include <math.h>
#include <string.h>
#include "../../../MocapNET2/MocapNETLib2/tools.hpp"
#include "../../../MocapNET2/MocapNETLib2/mocapnet2.hpp"
#include "../../../MocapNET2/MocapNETLib2/IO/commonSkeleton.hpp"
#include "../../../MocapNET2/MocapNETLib2/IO/jsonRead.hpp"
#include "../../../MocapNET2/MocapNETLib2/IO/csvRead.hpp"
#include "../../../MocapNET2/MocapNETLib2/IO/csvWrite.hpp"
#if USE_BVH
#include "../../../../dependencies/RGBDAcquisition/tools/AmMatrix/matrix4x4Tools.h"
#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/calculate/bvh_project.h"
#include "../../../../dependencies/RGBDAcquisition/opengl_acquisition_shared_library/opengl_depth_and_color_renderer/src/Library/MotionCaptureLoader/calculate/bvh_transform.h"
#include "../../../../dependencies/RGBDAcquisition/opengl_acquisition_shared_library/opengl_depth_and_color_renderer/src/Library/MotionCaptureLoader/ik/bvh_inverseKinematics.h"
#else
#warning "BVH code not included.."
#endif // USE_BVH
#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 main(int argc, char *argv[])
{
#if USE_BVH
float fX = 582.18394; //570.0
float fY = 582.52915; //570.0
unsigned int width = 1920;
unsigned int height = 1080;
struct simpleRenderer renderer= {0};
simpleRendererDefaults(
&renderer,
width,//1920
height,//1080
fX, //570.0
fY //570.0
);
simpleRendererInitialize(&renderer);
const char * path=0;
const char * label=0;
char outputPathFull[2048]= {"./handToMnet.csv"};
const char * outputPath=outputPathFull;
float scale2DX=1.0,scale2DY=1.0;
float offset2DX=0,offset2DY=0;
float scale3DX=1.0,scale3DY=1.0,scale3DZ=-1.0;
float offset3DX=0.0,offset3DY=0.0,offset3DZ=0.0;
int flipX=0;
int flipY=1;
unsigned int thereIsALineLimit=0;
unsigned int maxLinesToProcess=0;
// ./convertCSV3DToMocapNETInput --from /home/ammar/Documents/Datasets/STB/test.csv --to /home/ammar/Documents/Datasets/STB/test2D.csv --meters --flipY --offset3D 0 0 -100
int i=0;
while (i<argc)
{
if (strcmp(argv[i],"--from")==0)
{
path = argv[i+1];
i+=1;
}
else if (strcmp(argv[i],"--to")==0)
{
outputPath = argv[i+1];
i+=1;
}
else if (strcmp(argv[i],"--maxFrames")==0)
{
thereIsALineLimit=1;
maxLinesToProcess=atoi(argv[i+1]);
i+=1;
}
else if (strcmp(argv[i],"--meters")==0)
{
scale3DX = 1000.0;
scale3DY = 1000.0;
scale3DZ = 1000.0;
}
else if (strcmp(argv[i],"--scale3D")==0)
{
scale3DX=atof(argv[i+1]);
scale3DY=atof(argv[i+2]);
scale3DZ=atof(argv[i+3]);
i+=3;
}
else if (strcmp(argv[i],"--offset3D")==0)
{
offset3DX=atof(argv[i+1]);
offset3DY=atof(argv[i+2]);
offset3DZ=atof(argv[i+3]);
i+=3;
}
else if (strcmp(argv[i],"--scale2D")==0)
{
scale2DX=atof(argv[i+1]);
scale2DY=atof(argv[i+2]);
i+=2;
}
else if (strcmp(argv[i],"--offset2D")==0)
{
offset2DX=atof(argv[i+1]);
offset2DY=atof(argv[i+2]);
i+=2;
}
else if (strcmp(argv[i],"--flipX")==0)
{
if (flipX)
{
flipX=0;
}
else
{
flipX=1;
}
}
else if (strcmp(argv[i],"--flipY")==0)
{
if (flipY)
{
flipY=0;
}
else
{
flipY=1;
}
}
else
{
fprintf(stderr,RED "Unknown parameter : %s \n" NORMAL,argv[i]);
}
++i;
}
fprintf(stderr,"\n\n\n\nConversion from 3D CSV ground truth file configuration\n");
fprintf(stderr,"_____________________________________________________________\n");
fprintf(stderr,"3D input will have following modifiers : \n");
fprintf(stderr," Scale | %0.2f | %0.2f | %0.2f \n",scale3DX,scale3DY,scale3DZ);
fprintf(stderr," Offset | %0.2f | %0.2f | %0.2f \n",offset3DX,offset3DY,offset3DZ);
fprintf(stderr,"\nVirtual Camera : \n");
fprintf(stderr," Width=%0.2f Height=%0.2f\n",renderer.width,renderer.height);
fprintf(stderr," fX=%0.2f fY=%0.2f cX=%0.2f cY=%0.2f \n",renderer.fx,renderer.fy,renderer.cx,renderer.cy);
fprintf(stderr,"\n2D output will have following modifiers : \n");
fprintf(stderr," Scale | %0.2f | %0.2f \n",scale2DX,scale2DY);
fprintf(stderr," Offset | %0.2f | %0.2f \n",offset2DX,offset2DY);
fprintf(stderr,"\nFile I/O : \n");
fprintf(stderr," 3D CSV ground truth file: `%s`\n",path);
fprintf(stderr," 2D CSV output file: `%s`\n",outputPath);
fprintf(stderr,"_____________________________________________________________\n");
std::vector<std::vector<float> > result;
std::vector<float> points2DOfASpecificFrame;
struct CSVFileContext csv= {0};
struct CSVFloatFileLine csvLine= {0};
unsigned int linesProcessed=0;
if ( openCSVFile(&csv,path) )
{
parseCSVHeader(&csv);
fprintf(stderr,"%u columns of %u points to be outputted : ",csv.numberOfHeaderFields,(unsigned int) csv.numberOfHeaderFields/3);
for (unsigned int pointID=0; pointID<csv.numberOfHeaderFields; pointID++)
{
if (pointID!=0)
{
fprintf(stderr,",");
}
fprintf(stderr,"%s",csv.field[pointID].str);
}
fprintf(stderr,"\n_____________________________________________________________\n");
while ( (parseNextCSVFloatLine(&csv,&csvLine)) && ( (!thereIsALineLimit) || (linesProcessed+1<maxLinesToProcess) ) )
{
points2DOfASpecificFrame.clear();
float pos3D[4]= {0};
float position2DX=0.0,position2DY=0.0,position2DW=0.0;
float position2DOutputX=0.0,position2DOutputY=0.0;
float center[4]= {0};
float rotation[3]= {0};
for (unsigned int pointID=0; pointID<csv.numberOfHeaderFields/3; pointID++)
{
//--------------------------------------
pos3D[0]=(float) (scale3DX*csvLine.field[pointID * 3 + 0]) + offset3DX;
pos3D[1]=(float) (scale3DY*csvLine.field[pointID * 3 + 1]) + offset3DY;
pos3D[2]=(float) (scale3DZ*csvLine.field[pointID * 3 + 2]) + offset3DZ;
pos3D[3]=1.0;
//fprintf(stderr,"Projecting %0.2f,%0.2f,%0.2f : ",pos3D[0],pos3D[1],pos3D[2]);
//--------------------------------------
if (
simpleRendererRender(
&renderer,
pos3D,
center,
rotation,
ROTATION_ORDER_RPY,
&position2DX,
&position2DY,
&position2DW)
)
{
if (flipX) { position2DX = width - position2DX; }
if (flipY) { position2DY = height - position2DY; }
position2DOutputX=0.0;
position2DOutputY=0.0;
if (position2DW>0.0)
{
//fprintf(stderr,"output is %0.2f,%0.2f \n",position2DX,position2DY);
position2DOutputX = (scale2DX*position2DX) + offset2DX;
position2DOutputY = (scale2DY*position2DY) + offset2DY;
}
else
{
//fprintf(stderr,"behind camera(%0.2f).. %0.2f,%0.2f \n",position2DW,position2DX,position2DY);
}
//We normalize our 2D output..!
position2DOutputX=(float) position2DOutputX/renderer.width;
position2DOutputY=(float) position2DOutputY/renderer.height;
fprintf(stderr,"3D %0.2f,%0.2f,%0.2f => 2D %0.2f,%0.2f \n",pos3D[0],pos3D[1],pos3D[2],position2DOutputX,position2DOutputY);
points2DOfASpecificFrame.push_back(position2DOutputX);
points2DOfASpecificFrame.push_back(position2DOutputY);
}
else
{
points2DOfASpecificFrame.push_back(0.0);
points2DOfASpecificFrame.push_back(0.0);
}
} //For every point in this CSV line
result.push_back(points2DOfASpecificFrame);
++linesProcessed;
}//While we there are more lines to process
if (result.size()>0)
{
FILE * fp = fopen(outputPath,"w");
if (fp!=0)
{
fprintf(fp,"frameNumber,skeletonID,totalSkeletons");
for (unsigned int pointID=0; pointID<csv.numberOfHeaderFields/3; pointID++)
{
char * pointLabel = csv.field[pointID*3].str + 4; //This is the fastest way to get rid of the `3D*_` part of the stream
//Translate H36M labels to MNET labels..
if ( strcmp(pointLabel,"nose")==0 ) { fprintf(fp,",2DX_head,2DY_head,visible_head"); } else
if ( strcmp(pointLabel,"rwrist")==0 ) { fprintf(fp,",2DX_rhand,2DY_rhand,visible_rhand"); } else
if ( strcmp(pointLabel,"lwrist")==0 ) { fprintf(fp,",2DX_lhand,2DY_lhand,visible_lhand"); } else
if ( strcmp(pointLabel,"midhip")==0 ) { fprintf(fp,",2DX_hip,2DY_hip,visible_hip"); } else
if ( strcmp(pointLabel,"rheel")==0 ) { fprintf(fp,",2DX_rfoot,2DY_rfoot,visible_rfoot"); } else //rankle/lankle instead..
if ( strcmp(pointLabel,"lheel")==0 ) { fprintf(fp,",2DX_lfoot,2DY_lfoot,visible_lfoot"); } else
if ( strcmp(pointLabel,"reye")==0 ) { fprintf(fp,",2DX_endsite_eye.r,2DY_endsite_eye.r,visible_endsite_eye.r"); } else
if ( strcmp(pointLabel,"leye")==0 ) { fprintf(fp,",2DX_endsite_eye.l,2DY_endsite_eye.l,visible_endsite_eye.l"); } else
if ( strcmp(pointLabel,"rbigtoe")==0 ) { fprintf(fp,",2DX_endsite_toe1-2.r,2DY_endsite_toe1-2.r,visible_endsite_toe1-2.r"); } else
if ( strcmp(pointLabel,"lbigtoe")==0 ) { fprintf(fp,",2DX_endsite_toe1-2.l,2DY_endsite_toe1-2.l,visible_endsite_toe1-2.l"); } else
if ( strcmp(pointLabel,"rsmalltoe")==0 ) { fprintf(fp,",2DX_endsite_toe5-3.r,2DY_endsite_toe5-3.r,visible_endsite_toe5-3.r"); } else
if ( strcmp(pointLabel,"lsmalltoe")==0 ) { fprintf(fp,",2DX_endsite_toe5-3.l,2DY_endsite_toe5-3.l,visible_endsite_toe5-3.l"); } else
{ fprintf(fp,",2DX_%s,2DY_%s,visible_%s",pointLabel,pointLabel,pointLabel); }
}
fprintf(fp,"\n");
for (unsigned int frameID=0; frameID<result.size(); frameID++)
{
fprintf(fp,"%u,0,0",frameID);
for (unsigned int pointID=0; pointID<result[frameID].size(); pointID++)
{
if ( pointID%2==0) { fprintf(fp,",%f",result[frameID][pointID]); } else
{ fprintf(fp,",%f,1",result[frameID][pointID]); }
}
fprintf(fp,"\n");
}
fclose(fp);
}
}
closeCSVFile(&csv);
} //CSV file can be successfully opened
#else
fprintf(stderr,"This utility is only available if you compile the BVH code in..\n");
#endif
return 0;
}
@@ -0,0 +1,276 @@
#!/usr/bin/env python3
import numpy as np
import gc
import os
import sys
import csv
import time
import array
import matplotlib
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from mpl_toolkits.mplot3d import axes3d, Axes3D
width=1920.0
height=1080.0
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
def pointListReturnXYListForScatterPlot(A):
numberOfPoints=A.shape[0]
xs=list()
ys=list()
frameNumber=A[0]
skeletonID=A[1]
totalSkeletons=A[2]
for i in range(3,int(numberOfPoints/3)):
x=width*float(A[i*3+0])
y=height*float(A[i*3+1])
visibility=int(A[i*3+2])
if (visibility==1):
xs.append(x)
ys.append(y)
print('Point(',x,',',y,')')
return xs,ys
def checkIfFileExists(filename):
return os.path.isfile(filename)
def convert_bytes(num):
"""
this function will convert bytes to MB.... GB... etc
"""
step_unit = 1000.0 #1024 bad the size
for x in ['bytes', 'KB', 'MB', 'GB', 'TB']:
if num < step_unit:
return "%3.1f %s" % (num, x)
num /= step_unit
def getNumberOfLines(filename):
print("Counting number of lines in file ",filename)
with open(filename) as f:
return sum(1 for line in f)
#---------------------------------------------------------------------------------------------------------------------------------------------
#---------------------------------------------------------------------------------------------------------------------------------------------
#---------------------------------------------------------------------------------------------------------------------------------------------
def readCSVFile(filename,memPercentage,csvDelimiter,useHalfFloats,groupOutput):
print("CSV file :",filename,"..\n")
if (not checkIfFileExists(filename)):
print( bcolors.WARNING + "Input file "+filename+" does not exist, cannot read ground truth.." + bcolors.ENDC)
print("Current Directory was "+os.getcwd())
sys.exit(0)
start = time.time()
dtypeSelected=np.dtype(np.float32)
dtypeSelectedByteSize=int(dtypeSelected.itemsize)
if (useHalfFloats):
dtypeSelected=np.dtype(np.float16)
dtypeSelectedByteSize=int(dtypeSelected.itemsize)
progress=0.0
sampleNumber=0
receivedHeader=0
inputNumberOfColumns=0
inputLabels=list()
#-------------------------------------------------------------------------------------------------
numberOfSamplesInput=getNumberOfLines(filename)-2
print(" Input file has ",numberOfSamplesInput," training samples\n")
#-------------------------------------------------------------------------------------------------
numberOfSamples = numberOfSamplesInput
numberOfSamplesLimit=int(numberOfSamples*memPercentage)
#-------------------------------------------------------------------------------------------------
if (memPercentage==0.0):
print("readGroundTruthFile was asked to occupy 0 memory so this probably means we just want one record")
numberOfSamplesLimit=2
if (memPercentage>1.0):
print("Memory Limit will be interpreted as a raw value..")
numberOfSamplesLimit=int(memPercentage)
#-------------------------------------------------------------------------------------------------
thisInput = array.array('f')
#---------------------------------
fi = open(filename, "r")
readerIn = csv.reader( fi , delimiter=csvDelimiter, skipinitialspace=True)
for rowIn in readerIn:
#------------------------------------------------------
if (not receivedHeader): #use header to get labels
#------------------------------------------------------
inputNumberOfColumns=len(rowIn)
#Make sure CSV files that end with delimiter are correctly handled..
if (inputNumberOfColumns>0):
if (rowIn[inputNumberOfColumns-1]==''):
inputNumberOfColumns=inputNumberOfColumns-1
#-----------------------------------------------------
inputLabels = list(rowIn[i] for i in range(0,inputNumberOfColumns) )
print("Number of Input elements : ",len(inputLabels))
#------------------------------------------------------
if (memPercentage==0):
print("Will only return labels\n")
return {'labels':inputLabels};
#i=0
#print("class Input(Enum):")
#for label in inputLabels:
# print(" ",label," = ",i," #",int(i/3))
# print(" ",label,"=",int(i/3))
# i=i+1
#---------------------------------
# Allocate Lists
#---------------------------------
for i in range(inputNumberOfColumns):
thisInput.append(0.0)
#---------------------------------
#---------------------------------
# Allocate Numpy Arrays
#---------------------------------
inputSize=0
startCompressed=0
inputSize=inputSize+inputNumberOfColumns
startCompressed=inputNumberOfColumns
npInputBytesize=0+numberOfSamplesLimit * inputSize * dtypeSelectedByteSize
print(" Input file on disk has a shape of [",numberOfSamples,",",inputSize,"]")
print(" Input we will read has a shape of [",numberOfSamplesLimit,",",inputSize,"]")
print(" Input will occupy ",convert_bytes(npInputBytesize)," of RAM\n")
npInput = np.full([numberOfSamplesLimit,inputSize],fill_value=0,dtype=dtypeSelected,order='C')
#----------------------------------------------------------------------------------------------------------
receivedHeader=1
#sys.exit(0)
else:
#-------------------------------------------
# First convert our string INPUT to floats
#-------------------------------------------
for i in range(inputNumberOfColumns):
thisInput[i]=float(rowIn[i])
#-------------------------------------------
for num in range(0,inputNumberOfColumns):
npInput[sampleNumber,num]=float(thisInput[num]);
#-------------------------------------------
sampleNumber=sampleNumber+1
if (numberOfSamples>0):
progress=sampleNumber/numberOfSamplesLimit
if (sampleNumber%1000==0) :
progressString = "%0.2f"%float(100*progress)
print("\rReading from disk (",sampleNumber,") - ",progressString," % \r", end="", flush=True)
if (numberOfSamplesLimit<=sampleNumber):
print("\rStopping reading file to obey memory limit given by parameter --mem ",memPercentage,"\n")
break
#-------------------------------------------
fi.close()
del readerIn
gc.collect()
print("\n read, Samples: ",sampleNumber,", was expecting ",numberOfSamples," samples\n")
print(npInput.shape)
totalNumberOfBytes=npInput.nbytes;
totalNumberOfGigaBytes=totalNumberOfBytes/1073741824;
print("Size Occupied by data = ",totalNumberOfGigaBytes," GB \n")
end = time.time()
print("Time elapsed : ",(end-start)/60," mins")
#---------------------------------------------------------------------
if (groupOutput==0):
#New better dictionary
output = dict()
for i in range(0,len(inputLabels)):
lowerCaseName = inputLabels[i].lower()
#print("Joint ",lowerCaseName)
output[lowerCaseName]=list()
for frameID in range(0,len(npInput)):
output[lowerCaseName].append(npInput[frameID][i])
return output
else:
#This is the old dictionary way (better for tensorflow training)
return {'label':inputLabels, 'body':npInput };
#---------------------------------------------------------------------------------------------------------------------------------------------
#---------------------------------------------------------------------------------------------------------------------------------------------
#---------------------------------------------------------------------------------------------------------------------------------------------
drawPlot=1
ground=readCSVFile("test2D.csv",1.0,',',0,1)
if (drawPlot):
print("Using matplotlib:",matplotlib.__version__)
# === Plot and animate ===
fig = plt.figure()
fig.set_size_inches(19.2, 10.8, forward=True)
ax = fig.add_subplot(1, 2, 1)
ax2 = fig.add_subplot(1, 2, 2)
#ax3 = fig.add_subplot(2, 2, 3)
#ax4 = fig.add_subplot(2, 2, 4)
fig.subplots_adjust(left=0.05, bottom=0.05, right=0.95, top=0.95)
ax.set_xlabel('X Axis')
ax.set_ylabel('Y Axis')
#ax.set_zlabel('Z Axis')
#ax.view_init(90, 90)
print("Ground truth file has %u elements ",len(ground['body']))
for i in range(0,len(ground['body'])):
if (drawPlot):
plt.cla()
ax.cla()
ax2.cla()
xs, ys = pointListReturnXYListForScatterPlot(ground['body'][i])
ax.scatter(xs, ys)
img = plt.imread("images/im%u.png" % i)
ax2.imshow(img)
#-------------------------
ax.set_xlim(auto=False,left=0,right=width)
ax.set_ylim(auto=False,bottom=height,top=0)
#ax.set_zlim(auto=False,bottom=2000,top=6000)
ax.set_xlabel('X Axis')
ax.set_ylabel('Y Axis')
#ax.set_zlabel('Z Axis')
#-------------------------
plt.show(block=False)
#plt.savefig('p%05u.png'%i)
#fig.canvas.draw()
plt.pause(0.102)
@@ -0,0 +1,316 @@
#!/usr/bin/env python3
import numpy as np
import gc
import os
import sys
import csv
import time
import array
import matplotlib
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from mpl_toolkits.mplot3d import axes3d, Axes3D
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
def pointListReturnXYZListForScatterPlot(A):
numberOfPoints=A.shape[0]
xs=list()
ys=list()
zs=list()
for i in range(0,int(numberOfPoints/3)):
xs.append(float(-1000*10*A[i*3+0]))
ys.append(float(1000*10*A[i*3+1]))
zs.append(float(1000*10*A[i*3+2]))
return xs,ys,zs
def checkIfFileExists(filename):
return os.path.isfile(filename)
def convert_bytes(num):
"""
this function will convert bytes to MB.... GB... etc
"""
step_unit = 1000.0 #1024 bad the size
for x in ['bytes', 'KB', 'MB', 'GB', 'TB']:
if num < step_unit:
return "%3.1f %s" % (num, x)
num /= step_unit
def getNumberOfLines(filename):
print("Counting number of lines in file ",filename)
with open(filename) as f:
return sum(1 for line in f)
#---------------------------------------------------------------------------------------------------------------------------------------------
#---------------------------------------------------------------------------------------------------------------------------------------------
#---------------------------------------------------------------------------------------------------------------------------------------------
def readCSVFile(filename,memPercentage,csvDelimiter,useHalfFloats,groupOutput):
print("CSV file :",filename,"..\n")
if (not checkIfFileExists(filename)):
print( bcolors.WARNING + "Input file "+filename+" does not exist, cannot read ground truth.." + bcolors.ENDC)
print("Current Directory was "+os.getcwd())
sys.exit(0)
start = time.time()
dtypeSelected=np.dtype(np.float32)
dtypeSelectedByteSize=int(dtypeSelected.itemsize)
if (useHalfFloats):
dtypeSelected=np.dtype(np.float16)
dtypeSelectedByteSize=int(dtypeSelected.itemsize)
progress=0.0
sampleNumber=0
receivedHeader=0
inputNumberOfColumns=0
inputLabels=list()
#-------------------------------------------------------------------------------------------------
numberOfSamplesInput=getNumberOfLines(filename)-2
print(" Input file has ",numberOfSamplesInput," training samples\n")
#-------------------------------------------------------------------------------------------------
numberOfSamples = numberOfSamplesInput
numberOfSamplesLimit=int(numberOfSamples*memPercentage)
#-------------------------------------------------------------------------------------------------
if (memPercentage==0.0):
print("readGroundTruthFile was asked to occupy 0 memory so this probably means we just want one record")
numberOfSamplesLimit=2
if (memPercentage>1.0):
print("Memory Limit will be interpreted as a raw value..")
numberOfSamplesLimit=int(memPercentage)
#-------------------------------------------------------------------------------------------------
thisInput = array.array('f')
#---------------------------------
fi = open(filename, "r")
readerIn = csv.reader( fi , delimiter=csvDelimiter, skipinitialspace=True)
for rowIn in readerIn:
#------------------------------------------------------
if (not receivedHeader): #use header to get labels
#------------------------------------------------------
inputNumberOfColumns=len(rowIn)
#Make sure CSV files that end with delimiter are correctly handled..
if (inputNumberOfColumns>0):
if (rowIn[inputNumberOfColumns-1]==''):
inputNumberOfColumns=inputNumberOfColumns-1
#-----------------------------------------------------
inputLabels = list(rowIn[i] for i in range(0,inputNumberOfColumns) )
print("Number of Input elements : ",len(inputLabels))
#------------------------------------------------------
if (memPercentage==0):
print("Will only return labels\n")
return {'labels':inputLabels};
#i=0
#print("class Input(Enum):")
#for label in inputLabels:
# print(" ",label," = ",i," #",int(i/3))
# print(" ",label,"=",int(i/3))
# i=i+1
#---------------------------------
# Allocate Lists
#---------------------------------
for i in range(inputNumberOfColumns):
thisInput.append(0.0)
#---------------------------------
#---------------------------------
# Allocate Numpy Arrays
#---------------------------------
inputSize=0
startCompressed=0
inputSize=inputSize+inputNumberOfColumns
startCompressed=inputNumberOfColumns
npInputBytesize=0+numberOfSamplesLimit * inputSize * dtypeSelectedByteSize
print(" Input file on disk has a shape of [",numberOfSamples,",",inputSize,"]")
print(" Input we will read has a shape of [",numberOfSamplesLimit,",",inputSize,"]")
print(" Input will occupy ",convert_bytes(npInputBytesize)," of RAM\n")
npInput = np.full([numberOfSamplesLimit,inputSize],fill_value=0,dtype=dtypeSelected,order='C')
#----------------------------------------------------------------------------------------------------------
receivedHeader=1
#sys.exit(0)
else:
#-------------------------------------------
# First convert our string INPUT to floats
#-------------------------------------------
for i in range(inputNumberOfColumns):
thisInput[i]=float(rowIn[i])
#-------------------------------------------
for num in range(0,inputNumberOfColumns):
npInput[sampleNumber,num]=float(thisInput[num]);
#-------------------------------------------
sampleNumber=sampleNumber+1
if (numberOfSamples>0):
progress=sampleNumber/numberOfSamplesLimit
if (sampleNumber%1000==0) :
progressString = "%0.2f"%float(100*progress)
print("\rReading from disk (",sampleNumber,") - ",progressString," % \r", end="", flush=True)
if (numberOfSamplesLimit<=sampleNumber):
print("\rStopping reading file to obey memory limit given by parameter --mem ",memPercentage,"\n")
break
#-------------------------------------------
fi.close()
del readerIn
gc.collect()
print("\n read, Samples: ",sampleNumber,", was expecting ",numberOfSamples," samples\n")
print(npInput.shape)
totalNumberOfBytes=npInput.nbytes;
totalNumberOfGigaBytes=totalNumberOfBytes/1073741824;
print("Size Occupied by data = ",totalNumberOfGigaBytes," GB \n")
end = time.time()
print("Time elapsed : ",(end-start)/60," mins")
#---------------------------------------------------------------------
if (groupOutput==0):
#New better dictionary
output = dict()
for i in range(0,len(inputLabels)):
lowerCaseName = inputLabels[i].lower()
#print("Joint ",lowerCaseName)
output[lowerCaseName]=list()
for frameID in range(0,len(npInput)):
output[lowerCaseName].append(npInput[frameID][i])
return output
else:
#This is the old dictionary way (better for tensorflow training)
return {'label':inputLabels, 'body':npInput };
#---------------------------------------------------------------------------------------------------------------------------------------------
#---------------------------------------------------------------------------------------------------------------------------------------------
#---------------------------------------------------------------------------------------------------------------------------------------------
drawPlot=1
ground=readCSVFile("ground3D.csv",1.0,',',0,1)
if (drawPlot):
print("Using matplotlib:",matplotlib.__version__)
# === Plot and animate ===
fig = plt.figure()
fig.set_size_inches(19.2, 10.8, forward=True)
ax = fig.add_subplot(1, 2, 1, projection='3d')
ax2 = fig.add_subplot(1, 2, 2)
#ax3 = fig.add_subplot(2, 2, 3)
#ax4 = fig.add_subplot(2, 2, 4)
fig.subplots_adjust(left=0.05, bottom=0.05, right=0.95, top=0.95)
ax.set_xlabel('X Axis')
ax.set_ylabel('Y Axis')
ax.set_zlabel('Z Axis')
ax.view_init(90, 90)
print("Ground truth file has %u elements ",len(ground['body']))
for i in range(0,len(ground['body'])):
if (drawPlot):
plt.cla()
ax.cla()
ax2.cla()
#ax3.cla()
#ax4.cla()
categories = np.array([0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20
])
color0=(0.0, 1.0, 1.0, 1.0) #Palm
color1=(0.6, 0.0, 0.0, 1.0) #Thumb
color2=(0.8, 0.0, 0.0, 1.0) #Finger 1.2
color3=(1.0, 0.0, 0.0, 1.0) #Finger 1.3
color4=(0.0, 1.0, 1.0, 1.0) #BaseOfFourFingers
color5=(0.0, 1.0, 0.0, 1.0) #Finger 2.3
color6=(0.0, 0.8, 0.0, 1.0) #Finger 2.2
color7=(0.0, 0.6, 0.0, 1.0) #Finger 2.1
color8=(0.0, 0.4, 0.0, 1.0) #Metacarpal 1
color9=(0.0, 0.0, 1.0, 1.0) #Finger 3.3
color10=(0.0, 0.0, 0.8, 1.0) #Finger 3.2
color11=(0.0, 0.0, 0.6, 1.0) #Finger 3.1
color12=(0.0, 0.0, 0.4, 1.0) #Metacarpal 2
color13=(0.0, 1.0, 1.0, 1.0) #Finger 4.3
color14=(0.0, 0.8, 0.8, 1.0) #Finger 4.2
color15=(0.0, 0.6, 0.6, 1.0) #Finger 4.1
color16=(0.0, 0.4, 0.4, 1.0) #Metacarpal 3
color17=(1.0, 1.0, 0.0, 1.0) #Finger 5.3
color18=(0.8, 0.8, 0.0, 1.0) #Finger 5.2
color19=(0.6, 0.6, 0.0, 1.0) #Finger 5.1
color20=(0.4, 0.4, 0.0, 1.0) #Metacarpal 4
colormap = np.array([color0,color1,color2,color3,color4,color5,color6,color7,color8,color9,color10,color11,color12,color13,color14,color15,color16,color17,color18,color19,color20])
xs, ys, zs = pointListReturnXYZListForScatterPlot(ground['body'][i])
ax.scatter(xs, ys, zs, c=colormap[categories])
img = plt.imread("images/im%u.png" % i)
ax2.imshow(img)
#-------------------------
ax.set_xlim(auto=False,left=-600,right=300)
ax.set_ylim(auto=False,bottom=-1600,top=200)
ax.set_zlim(auto=False,bottom=2000,top=6000)
ax.set_xlabel('X Axis')
ax.set_ylabel('Y Axis')
ax.set_zlabel('Z Axis')
#-------------------------
plt.show(block=False)
#plt.savefig('p%05u.png'%i)
#fig.canvas.draw()
plt.pause(0.001)