KINECT STATS GENERATOR FOR SPORTS VISUALISATION
1.0
|
00001 #include <TwoDStatsGeneration.h> 00002 00003 /* 00004 LICENSING: You are free to use any part of this project provided I am informed about it via email 00005 at santoshwins@hotmail.com and referenced appropriately in your works 00006 */ 00007 00008 TwoDStatsGeneration::TwoDStatsGeneration() 00009 { 00010 00011 } 00012 00013 TwoDStatsGeneration::~TwoDStatsGeneration() 00014 { 00015 00016 } 00017 00018 void TwoDStatsGeneration::calculatePlayerImpactPtsFromIndices(std::vector<std::vector<cv::Point3f> > &_inputPlayerBallPts, 00019 std::vector<std::vector<int> > &_playerDeepestPtIndices, 00020 std::vector<cv::Point> &o_playerImpactPtsAllRallies) 00021 { 00022 if(_playerDeepestPtIndices.size() != 0) 00023 { 00024 for(int i = 0;i<_playerDeepestPtIndices.size();i++) 00025 { 00026 for(int j=0;j<_playerDeepestPtIndices[i].size();j++) 00027 { 00028 00029 // if the impact point index is not -1, then there is an impact point for this rally 00030 if(_playerDeepestPtIndices[i][j] != -1) 00031 { 00032 o_playerImpactPtsAllRallies.push_back(cv::Point((int)(_inputPlayerBallPts[i][_playerDeepestPtIndices[i][j]]).x,(int)(_inputPlayerBallPts[i][_playerDeepestPtIndices[i][j]]).y)); 00033 } 00034 else 00035 { 00036 std::cout<<"No impact point for Rally number:"<<i<<"..so skipping to next rally.\n"; 00037 } 00038 00039 } 00040 } 00041 } 00042 else 00043 { 00044 std::cout<<"No data in indices array for the player.\n"; 00045 } 00046 } 00047 00048 00049 00050 void TwoDStatsGeneration::generatePercentageDistribution(int _widthBounds, int _heightBounds, 00051 std::vector<cv::Point> &_playerImpactPtsAllRallies, 00052 int _whichQuadrant, 00053 std::vector<cv::Point>& o_specificQuadPts, 00054 float& o_percentage) 00055 { 00056 00057 switch(_whichQuadrant) 00058 { 00059 //bottom left 00060 case 0: 00061 { 00062 for(int i=0;i<_playerImpactPtsAllRallies.size();i++) 00063 { 00064 if((_playerImpactPtsAllRallies[i].x <= _widthBounds) && (_playerImpactPtsAllRallies[i].y <= _heightBounds)) 00065 { 00066 // if it falls into the requested quadrant then fill in the buffer 00067 o_specificQuadPts.push_back(_playerImpactPtsAllRallies[i]); 00068 } 00069 } 00070 break; 00071 } 00072 // top left 00073 case 1: 00074 { 00075 for(int i=0;i<_playerImpactPtsAllRallies.size();i++) 00076 { 00077 if((_playerImpactPtsAllRallies[i].x <= _widthBounds) && (_playerImpactPtsAllRallies[i].y >= _heightBounds)) 00078 { 00079 // if it falls into the requested quadrant then fill in the buffer 00080 o_specificQuadPts.push_back(_playerImpactPtsAllRallies[i]); 00081 } 00082 } 00083 break; 00084 00085 } 00086 // top right 00087 case 2: 00088 { 00089 for(int i=0;i<_playerImpactPtsAllRallies.size();i++) 00090 { 00091 if((_playerImpactPtsAllRallies[i].x > _widthBounds) && (_playerImpactPtsAllRallies[i].y > _heightBounds)) 00092 { 00093 // if it falls into the requested quadrant then fill in the buffer 00094 o_specificQuadPts.push_back(_playerImpactPtsAllRallies[i]); 00095 } 00096 } 00097 break; 00098 00099 } 00100 // bottom right 00101 case 3: 00102 { 00103 for(int i=0;i<_playerImpactPtsAllRallies.size();i++) 00104 { 00105 if((_playerImpactPtsAllRallies[i].x > _widthBounds) && (_playerImpactPtsAllRallies[i].y < _heightBounds)) 00106 { 00107 // if it falls into the requested quadrant then fill in the buffer 00108 o_specificQuadPts.push_back(_playerImpactPtsAllRallies[i]); 00109 } 00110 } 00111 break; 00112 00113 } 00114 } 00115 00116 00117 o_percentage = (float)((float)o_specificQuadPts.size()/(float)_playerImpactPtsAllRallies.size()); 00118 o_percentage = o_percentage * 100; 00119 00120 } 00121 00122 00123 00124 00125 00126 // may be we can have an overloaded function for the above one 00127 // where instead of 4 output buffers, 00128 // we need to generate output into as many buffers as there are grid boxes 00129 // for percentage density 00130 00131