[chronojump] kneeAngle: kneePointFront & Back



commit 571f617291174be2df4207f6d84119d48385a6d7
Author: Xavier de Blas <xaviblas gmail com>
Date:   Thu Apr 29 00:07:33 2010 +0800

    kneeAngle: kneePointFront & Back

 src/angle/kneeAngle.cpp          |   60 +++++++++++++++++++++++++++-----------
 src/angle/kneeAngleFunctions.cpp |   42 ++++++++++++++++++--------
 src/angle/kneeAngleGlobal.cpp    |    1 +
 3 files changed, 73 insertions(+), 30 deletions(-)
---
diff --git a/src/angle/kneeAngle.cpp b/src/angle/kneeAngle.cpp
index ed98e7c..30c2290 100644
--- a/src/angle/kneeAngle.cpp
+++ b/src/angle/kneeAngle.cpp
@@ -390,6 +390,11 @@ int main(int argc,char **argv)
 	std::vector<int> toeYVector;
 	std::vector<double> angleVector;
 	std::vector<int> rectVector;
+			
+	std::vector<int> kneePointFrontXVector;
+	std::vector<int> kneePointFrontYVector;
+	std::vector<int> kneePointBackXVector;
+	std::vector<int> kneePointBackYVector;
 	
 	/*
 	int upLegMarkedDist = 0;
@@ -445,8 +450,8 @@ int main(int argc,char **argv)
 	CvPoint hipPointBackAtExtension = pointToZero();
 
 	//this contains data useful to validation: max and min Height and Width of all rectangles
-	/*
 	int validationRectHMax = 0;
+	/*
 	int validationRectHMin = 100000;
 	int validationRectWMax = 0;
 	int validationRectWMin = 100000;
@@ -847,16 +852,16 @@ int main(int argc,char **argv)
 				}
 
 
-				if(ProgramMode == validation) {
+				if(ProgramMode != skinOnlyMarkers) {
 					cvRectangle(frame_copy,
 							cvPoint(maxrect.x,maxrect.y),
 							cvPoint(maxrect.x + maxrect.width, maxrect.y + maxrect.height),
 							CV_RGB(255,0,0),1,1);
 
-					/*
 					//assign validationRect data if maxs or mins reached
 					if(maxrect.height > validationRectHMax)
 						validationRectHMax = maxrect.height;
+					/*
 					if(maxrect.height < validationRectHMin) {
 						validationRectHMin = maxrect.height;
 						//store angle at validationRectHMin
@@ -1006,7 +1011,6 @@ int main(int argc,char **argv)
 				}
 				*/
 				
-				cvShowImage("toClick", frame_copy);
 				//cvShowImage("threshold",output);
 				
 				//exit if we are going up and soon jumping.
@@ -1014,6 +1018,7 @@ int main(int argc,char **argv)
 				//detected if minThetaMarked is littler than thetaMarked, when thetaMarked is big
 				if(askForMaxFlexion && thetaMarked > 140 && minThetaMarked +10 < thetaMarked)
 				{
+					cvShowImage("toClick", frame_copy);
 					imageGuiResult(gui, "Min flex before. End?. 'y'es, 'n'o, 'N'ever", font);
 					int option = optionAccept(true);	
 					eraseGuiResult(gui, true);
@@ -1040,6 +1045,7 @@ int main(int argc,char **argv)
 		 * 5 a
 		 * IF BLACKANDMARKERS MODE, FIND POINTS
 		 * UNUSED NOW BECAUSE WE ARE USING ONLY RECTANGLE
+		 * AND KNEEPOINTS
 		 */
 
 		/*
@@ -1060,11 +1066,9 @@ int main(int argc,char **argv)
 			hipExpected.y = hipPointBack.y;
 
 			//knee	
-			kneePointFront = findKneePointFront(output,maxrect,hipPointBack.y, foundAngleOneTime);
+			kneePointFront = findKneePointFront(output, maxrect, foundAngleOneTime);
 			//hueco popliteo
-			kneePointBack = findKneePointBack(output,maxrect, 
-					hipPointBack.y, kneePointFront.x,
-					foundAngleOneTime); 
+			kneePointBack = findKneePointBack(output, maxrect, kneePointFront.x, foundAngleOneTime); 
 
 			//toe
 			int toeMinWidth;
@@ -1406,15 +1410,33 @@ int main(int argc,char **argv)
 		
 		/*
 		 * 5 b
-		 * IF BLACKANDMARKERS MODE, FIND RECTANGLE
+		 * IF BLACKANDMARKERS MODE, FIND RECTANGLE, AND KNEE POINTS
 		 */
 
 		angleVector.push_back(thetaMarked);
 	
-		if(ProgramMode == skinOnlyMarkers) 
+		if(ProgramMode == skinOnlyMarkers) {
 			rectVector.push_back(-1);
-		else
+			kneePointFrontXVector.push_back(-1);
+			kneePointFrontYVector.push_back(-1);
+			kneePointBackXVector.push_back(-1); 
+			kneePointBackYVector.push_back(-1); 
+		} else {
 			rectVector.push_back(maxrect.height);
+			
+			//knee visible points on black pants
+			CvPoint kneePointFront = findKneePointFront(output, maxrect, validationRectHMax);
+			CvPoint kneePointBack = findKneePointBack(output, maxrect, kneePointFront.x, validationRectHMax); 
+			crossPoint(frame_copy, kneePointFront, GREY, MID);
+			crossPoint(frame_copy, kneePointBack, GREY, MID);
+			kneePointFrontXVector.push_back(kneePointFront.x);
+			kneePointFrontYVector.push_back(kneePointFront.y);
+			kneePointBackXVector.push_back(kneePointBack.x); 
+			kneePointBackYVector.push_back(kneePointBack.y); 
+		}
+			
+		//cvCopy(frame_copy,result);
+		cvShowImage("toClick", frame_copy);
 
 
 		//cvWaitKey(0);
@@ -1995,16 +2017,18 @@ int main(int argc,char **argv)
 		if(ProgramMode != skinOnlyMarkers) 
 			rectHeightMax = findMaxInVector(rectVector);
 
-		fprintf(fDataRaw, "hipX;hipY;kneeX;kneeY;toeX;toeY;angle;rectH;rectHP\n");
+		fprintf(fDataRaw, "hipX;hipY;kneeX;kneeY;toeX;toeY;kpfX;kpfY;kpbX;kpbY;angle;rectH;rectHP\n");
 		for (int i=flexionStartsAtFrame; i < lowestAngleFrameReally; i ++) {
 			double rectHeightPercent = -1;
 			if(ProgramMode != skinOnlyMarkers)
 				rectHeightPercent = 100 * (double) rectVector[i] / rectHeightMax;
 
-			fprintf(fDataRaw, "%d;%d;%d;%d;%d;%d;%f;%d;%f\n", 
+			fprintf(fDataRaw, "%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%f;%d;%f\n", 
 					hipXVector[i], verticalHeight - hipYVector[i],
 					kneeXVector[i], verticalHeight - kneeYVector[i],
-					toeXVector[i], verticalHeight -toeYVector[i],
+					toeXVector[i], verticalHeight - toeYVector[i],
+					kneePointFrontXVector[i], verticalHeight - kneePointFrontYVector[i], 
+					kneePointBackXVector[i], verticalHeight - kneePointBackYVector[i],
 					angleVector[i], rectVector[i], 
 					rectHeightPercent);
 		}
@@ -2031,7 +2055,7 @@ int main(int argc,char **argv)
 		if(ProgramMode != skinOnlyMarkers)
 			rectHeightMax = findMaxInVector(rectVector);
 
-		fprintf(fDataSmooth, "hipX;hipY;kneeX;kneeY;toeX;toeY;angleTest;angle;rectH;rectHP\n");
+		fprintf(fDataSmooth, "hipX;hipY;kneeX;kneeY;toeX;toeY;kpfX;kpfY;kpbX;kpbY;angleTest;angle;rectH;rectHP\n");
 		for (int i=flexionStartsAtFrame; i < lowestAngleFrameReally; i ++) {
 			//Note: smoothed angle don't comes from smoothing the angle points, 
 			//comes from calculating the angle in the smoothed X,Y of three joints
@@ -2047,10 +2071,12 @@ int main(int argc,char **argv)
 			if(ProgramMode != skinOnlyMarkers)
 				rectHeightPercent = 100 * (double) rectVector[i] / rectHeightMax;
 
-			fprintf(fDataSmooth, "%d;%d;%d;%d;%d;%d;%f;%f;%d;%f\n", 
+			fprintf(fDataSmooth, "%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%f;%f;%d;%f\n", 
 					hipXVector[i], verticalHeight - hipYVector[i],
 					kneeXVector[i], verticalHeight - kneeYVector[i],
-					toeXVector[i], verticalHeight -toeYVector[i],
+					toeXVector[i], verticalHeight - toeYVector[i],
+					kneePointFrontXVector[i], verticalHeight - kneePointFrontYVector[i], 
+					kneePointBackXVector[i], verticalHeight - kneePointBackYVector[i],
 					angleVector[i], //trying angle smoothed
 					angleSmoothed, rectVector[i], 
 					rectHeightPercent);
diff --git a/src/angle/kneeAngleFunctions.cpp b/src/angle/kneeAngleFunctions.cpp
index df7c67f..b91a815 100644
--- a/src/angle/kneeAngleFunctions.cpp
+++ b/src/angle/kneeAngleFunctions.cpp
@@ -65,7 +65,7 @@ CvPoint findHipPoint(IplImage* img,CvRect roirect)
 	CvPoint pt;
 	pt.x =0;pt.y=0;
 	int starty = roirect.y;
-	int endy = starty + roirect.height*2/3; /* meu: why 2/3 */
+	int endy = starty + roirect.height*2/3; /* meu: why 2/3?... because have to be in the 2/3 up image*/
 	CvMat *srcmat,src_stub;
 	srcmat = cvGetMat(img,&src_stub);
 	uchar *srcdata = srcmat->data.ptr;
@@ -113,28 +113,33 @@ CvPoint findHipPoint(IplImage* img,CvRect roirect)
 }
 
 /*
- * takes as input arguement the bounding rectangle of the largest contour,the image containing the bounding rectangle and the y coordinate of the hip point
+ * takes as input argument the bounding rectangle of the largest contour,the image containing the bounding rectangle and the y coordinate of the hip point
  * Calculates the knee point
  * Knee point is a white pixel below the hip point and having maximum x coordinate in the bounding box
  * Returns the coordinate of the knee point
  */
-CvPoint findKneePointFront(IplImage *img,CvRect roirect,int starty, bool foundAngleOneTime)
+//CvPoint findKneePointFront(IplImage *img, CvRect roirect, bool foundAngleOneTime)
+CvPoint findKneePointFront(IplImage *img, CvRect roirect, int rectHMax)
 {
 	CvPoint pt;
 	pt.x = 0; pt.y = 0;
 	
+	int starty = roirect.y;
 	//int endy = roirect.y+roirect.height*9/10; //this is ok if shoes or platform is shown in standup image
 	int endy = roirect.y+roirect.height;
 	
+	//if person is totally in extension, don't try to find kneePointFront and back,
+	//because there's lot of error because quadriceps is in front
+	if(roirect.height >= .97 * rectHMax) {
+		return pt;
+	}
 	/*
-	 * if we never found and angle before, knee must be more or less at the middle. 
-	 * Is important to find it at start of flexion, to try to get the kneeCenter at (close to extension)
-	 * and use it's X for hipPoint and backLength.
-	 * For this reason, now we only search in the middle of the image
+	 * if person is in extension, knee must be more or less at the middle. 
+	 * we are in extension because roirect.height >= 85% rectHMax
 	 */
-	if(! foundAngleOneTime) {
-		starty = roirect.y + roirect.height*1/3;
-		endy = roirect.y + roirect.height*2/3;
+	if(roirect.height >= .85 * rectHMax) {
+		starty = roirect.y + roirect.height*2/5;
+		endy = roirect.y + roirect.height*4/5;
 	}
 
 	CvMat *srcmat,src_stub;
@@ -183,11 +188,12 @@ CvPoint findKneePointFront(IplImage *img,CvRect roirect,int starty, bool foundAn
 }
 
 //hueco popliteo
-CvPoint findKneePointBack(IplImage *img,CvRect roirect,int starty, int kneePointFrontX, bool foundAngleOneTime)
+CvPoint findKneePointBack(IplImage *img, CvRect roirect, int kneePointFrontX, int rectHMax)
 {
 	CvPoint pt;
 	pt.x = 0; pt.y = 0;
 
+	int starty = roirect.y;
 	/*
 	 * this 8/10 makes no error when jump starts, 
 	 * if not, on jump, the bottom of the pants can be taken as kneeBack
@@ -196,8 +202,13 @@ CvPoint findKneePointBack(IplImage *img,CvRect roirect,int starty, int kneePoint
 	/*
 	 * same as finddKneePointFront
 	 */
-	if(! foundAngleOneTime)
-		endy = roirect.y + roirect.height*2/3;
+	if(roirect.height >= .97 * rectHMax) {
+		return pt;
+	}
+	if(roirect.height >= .85 * rectHMax) {
+		starty = roirect.y + roirect.height*2/5;
+		endy = roirect.y + roirect.height*4/5;
+	}
 
 	CvMat *srcmat,src_stub;
 	srcmat = cvGetMat(img,&src_stub);
@@ -1376,6 +1387,11 @@ void on_mouse_gui( int event, int x, int y, int flags, void* param )
 	else 
 		MouseMultiplier = false;
 
+	if(flags & CV_EVENT_FLAG_CTRLKEY)
+		MouseControl = true;
+	else 
+		MouseControl = false;
+
 
 	bool success; //this helps to navigate between modes. Is not a return value
 	switch( event ) {
diff --git a/src/angle/kneeAngleGlobal.cpp b/src/angle/kneeAngleGlobal.cpp
index 471b319..7e85437 100644
--- a/src/angle/kneeAngleGlobal.cpp
+++ b/src/angle/kneeAngleGlobal.cpp
@@ -102,6 +102,7 @@ CvPoint MarkedMouse;
 int ForceMouseMark;
 int MouseClicked = undefined;
 bool MouseMultiplier = false; //using shift key
+bool MouseControl = false; //using CTRL key
 
 bool Zoomed = false;
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]