chronojump r418 - trunk/src/angle



Author: xaviblas
Date: Tue Oct  7 11:42:23 2008
New Revision: 418
URL: http://svn.gnome.org/viewvc/chronojump?rev=418&view=rev

Log:
lots of changes


Modified:
   trunk/src/angle/kneeAngle.cpp
   trunk/src/angle/kneeAngleFunctions.cpp
   trunk/src/angle/kneeAngleUtil.cpp

Modified: trunk/src/angle/kneeAngle.cpp
==============================================================================
--- trunk/src/angle/kneeAngle.cpp	(original)
+++ trunk/src/angle/kneeAngle.cpp	Tue Oct  7 11:42:23 2008
@@ -23,7 +23,7 @@
  * Xavier de Blas 
  * xaviblas gmail com
  *
- * version: 1.3 (Oct, 3, 2008)
+ * version: 1.3.2 (Oct, 7, 2008)
  *
  */
 
@@ -41,7 +41,7 @@
  * 
  * -Person have to be "looking" to the right of the camera
  * -Camera view area will be (having jumper stand up):
- *   below: the foot preferrably has not to be shown
+ *   below: the toe preferrably has not to be shown
  *   above: the top part of the image will be the right hand (fully included)
  * -Black trousers should be use. Rest of the clothes should not be black.
  * -White background is highly recommended
@@ -153,9 +153,14 @@
 {
 	if(argc < 2)
 	{
-		cout<<"Provide file location as a first argument..."<<endl;
+		cout<<"Provide file location as a first argument...\noptional: provide start photogramme at 2nd argument."<<endl;
 		exit(1);
 	}
+
+	int startAt = -1;
+	if(argc == 3)
+		startAt = atoi(argv[2]);
+
 	CvCapture* capture = NULL;
 	capture = cvCaptureFromAVI(argv[1]);
 	if(!capture)
@@ -163,9 +168,9 @@
 		exit(0);
 	}
 
-	int framesNumber = cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_COUNT);
-	printf("--%d--\n", framesNumber);
-
+	//int framesNumber = cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_COUNT);
+	//printf("--%d--\n", framesNumber);
+			
 	IplImage *frame=0,*frame_copy=0,*gray=0,*segmented=0,*edge=0,*temp=0,*output=0;
 	IplImage *segmentedValidationHoles=0;
 	IplImage *foundHoles=0;
@@ -177,7 +182,7 @@
 	bool foundAngle = false; //found angle on current frame
 	bool foundAngleOneTime = false; //found angle at least one time on the video
 
-	double knee2Hip,knee2Foot,hip2Foot;
+	double knee2Hip,knee2Toe,hip2Toe;
 	double theta, thetaHoles;
 	string text,angle;
 	double minTheta = 360;
@@ -191,7 +196,7 @@
 //	cvNamedWindow("output",1);
 
 	int kneePointWidth = -1;
-	int footPointWidth;
+	int toePointWidth;
 		
 	//to make lines at resultPointsLines
 	CvPoint notFoundPoint;
@@ -199,7 +204,7 @@
 	int lowestAngleFrame = 0;
 
 
-	char *label = new char[30];
+	char *label = new char[80];
 	CvFont font;
 	int fontLineType = CV_AA; // change it to 8 to see non-antialiased graphics
 	double fontSize = .4;
@@ -212,15 +217,29 @@
 	CvMemStorage* stickStorage = cvCreateMemStorage(0);
 	CvSeq* hipSeq = cvCreateSeq( CV_SEQ_KIND_GENERIC|CV_32SC2, sizeof(CvSeq), sizeof(CvPoint), stickStorage );
 	CvSeq* kneeSeq = cvCreateSeq( CV_SEQ_KIND_GENERIC|CV_32SC2, sizeof(CvSeq), sizeof(CvPoint), stickStorage );
-	CvSeq* footSeq = cvCreateSeq( CV_SEQ_KIND_GENERIC|CV_32SC2, sizeof(CvSeq), sizeof(CvPoint), stickStorage );
-
+	CvSeq* toeSeq = cvCreateSeq( CV_SEQ_KIND_GENERIC|CV_32SC2, sizeof(CvSeq), sizeof(CvPoint), stickStorage );
+  
+	sprintf(label, "    fps a_black a_holes [   diff diff(%)] kneeDif  a_supD  a_infD");
+	printf("%s\n" ,label);
+
+	double avgThetaDiff = 0;
+	double avgThetaDiffPercent = 0;
+	double avgKneeDistance = 0;
+	double avgKneeBackDistance = 0;
+	int framesDetected = 0;
+	int framesCount = 0;
 
 	while(!shouldEnd) 
 	{
+		framesCount ++;
 
 		frame = cvQueryFrame(capture);
 		if(!frame)
 			break;
+		if(startAt > framesCount) {
+			continue;
+		}
+
 		if( !frame_copy )
 			frame_copy = cvCreateImage( cvSize(frame->width,frame->height),IPL_DEPTH_8U, frame->nChannels );
 		if( frame->origin == IPL_ORIGIN_TL )
@@ -260,10 +279,24 @@
 		CvPoint kneeHolesPoint = *CV_GET_SEQ_ELEM( CvPoint, seqHolesEnd, 1 ); 
 		CvPoint toeHolesPoint = *CV_GET_SEQ_ELEM( CvPoint, seqHolesEnd, 2 ); 
 
-
 		CvPoint hipPoint = FindHipPoint(output,maxrect);
+
+
+
+//knee	
 		CvPoint kneePoint = FindKneePoint(output,maxrect,hipPoint.y);
-		CvPoint footPoint = FindToePoint(output,maxrect,kneePoint.x,kneePoint.y);
+		CvPoint kneePointBack = FindKneePointBack(output,maxrect,hipPoint.y, kneePoint.x); //hueco popliteo
+
+/*
+ * to know how the horizontal distance between the kneeHole and the right of the knee we can use this
+ * as observed, distance only changes a bit, and is higher in maximum flexion
+ * search X distance between kneeHoles and kneeRight
+ */
+//printf("[%f]", getDistance(kneeHolesPoint, cvPoint(kneePoint.x, kneeHolesPoint.y)));
+
+
+		
+		CvPoint toePoint = FindToePoint(output,maxrect,kneePoint.x,kneePoint.y);
 
 		foundAngle = false;
 		if(minwidth == 0)
@@ -274,7 +307,9 @@
 		{
 			if((double)(kneePoint.x- hipPoint.x) > 1.15*minwidth 
 					&&
-					upperSimilarThanLower(hipPoint, kneePoint, footPoint)
+					upperSimilarThanLower(hipPoint, kneePoint, toePoint)
+					&& !pointIsNull(hipHolesPoint) && !pointIsNull(kneeHolesPoint) && 
+					!pointIsNull(toeHolesPoint)
 					)
 				/* get lower this 1.25 because now we use mid leg to solve the hand problem and width is lower*/
 				/*1.25 again, because we use hip y again*/
@@ -285,35 +320,64 @@
 		//Finds angle between Hip to Knee line and Knee to Toe line
 		if(foundAngle)
 		{
-			cvCircle(frame_copy,kneePoint,2, CV_RGB(255,0,255),1,8,0);
+			cvCircle(frame_copy,kneePoint,2, CV_RGB(128,128,128),1,8,0);
 			
 			//find width of knee, only one time and will be used for all the photogrammes
 			if(kneePointWidth == -1) {
 				kneePointWidth = FindWidth(output, kneePoint);
 			}
 
-			//fix kneepoint.x at the right 1/2 of the knee width
-			kneePoint.x -= kneePointWidth /2;
-			cvCircle(frame_copy,kneePoint,3, CV_RGB(0,255,0),1,8,0);
+//knee stuff
+			cvCircle(frame_copy,kneePointBack,2, CV_RGB(128,128,128),1,8,0);
+			cvLine(frame_copy,kneePoint,kneePointBack,CV_RGB(128,128,128),1,1);
+			CvPoint kneePointBackPrima;
+		        kneePointBackPrima.x = kneePointBack.x - kneePoint.x;
+		        kneePointBackPrima.y = kneePointBack.y - kneePoint.y;
 
+			int kneePointBackPrimaTempX = kneePointBackPrima.x;
+			
+			//don't use horizontal knee distance on each photogramme
+			//kneePointBackPrima.x += getDistance(kneePoint, kneePointBack) * .6;
+			//use it on first photogramme: kneePointWidth
 
-			//find width of foot for each photogramme
-			footPointWidth = FindWidth(output, footPoint);
-			cvCircle(frame_copy,footPoint,2, CV_RGB(255,0,255),1,8,0);
-			
-			//fix footpoint.x at the 1/2 of the foot width
-			footPoint.x -= footPointWidth /2;
-			cvCircle(frame_copy,footPoint,3, CV_RGB(0,0,255),1,8,0);
+			double kneeXConvertedRatio = (double) abs(kneePointBackPrima.x) / kneePointWidth *.4;
+			kneePointBackPrima.x *= kneeXConvertedRatio;
+			kneePointBackPrima.y *= kneeXConvertedRatio;
+
+			kneePointBack.x = kneePointBackPrima.x + kneePoint.x;
+			kneePointBack.y = kneePointBackPrima.y + kneePoint.y;
+			cvCircle(frame_copy,kneePointBack,3, CV_RGB(255,255,0),1,8,0);
+
+
+
+
+//fix kneepoint.x at the right 1/2 of the knee width
+			//kneePoint.x -= kneePointWidth /2;
+			kneePoint.x -= .4 * kneePointWidth;
+			cvCircle(frame_copy,kneePoint,3, CV_RGB(255,0,0),1,8,0);
+
+			
+
+			//find width of toe for each photogramme
+			toePointWidth = FindWidth(output, toePoint);
+			cvCircle(frame_copy,toePoint,2, CV_RGB(128,128,128),1,8,0);
+			
+			theta = findAngle(hipPoint, toePoint, kneePoint);
+
+			//fix toepoint.x at the 1/2 of the toe width
+			//toePoint.x -= toePointWidth /2;
+			toePoint.x = fixToePointX(toePoint.x, toePointWidth, theta);
+			cvCircle(frame_copy,toePoint,3, CV_RGB(255,0,0),1,8,0);
 
 			
 			//fix hipPoint ...
 			int hipPointFirstY = hipPoint.y;
-			cvCircle(frame_copy,hipPoint,2, CV_RGB(255,0,255),1,8,0);
+			cvCircle(frame_copy,hipPoint,2, CV_RGB(128,128,128),1,8,0);
 			
 			//... find at 3/2 of hip (surely under the hand) ...
-			theta = findAngle(hipPoint, footPoint, kneePoint);
+			//theta = findAngle(hipPoint, toePoint, kneePoint);
 			hipPoint = FixHipPoint1(output, hipPoint, kneePoint, theta);
-			cvCircle(frame_copy,hipPoint,2, CV_RGB(255,0,255),1,8,0);
+			cvCircle(frame_copy,hipPoint,2, CV_RGB(128,128,128),1,8,0);
 
 			//... cross first hippoint with the knee-hippoint line to find real hippoint
 			hipPoint = FixHipPoint2(output, hipPointFirstY, kneePoint, hipPoint);
@@ -321,26 +385,27 @@
 			
 
 			//find flexion angle
-			theta = findAngle(hipPoint, footPoint, kneePoint);
+			theta = findAngle(hipPoint, toePoint, kneePoint);
+			double thetaBack = findAngle(hipPoint, toePoint, kneePointBack);
 			thetaHoles = findAngle(hipHolesPoint, toeHolesPoint, kneeHolesPoint);
 			
 			//draw 2 main lines
-			cvLine(frame_copy,kneePoint,hipPoint,CV_RGB(128,128,128),1,1);
-			cvLine(frame_copy,kneePoint,footPoint,CV_RGB(128,128,128),1,1);
+			cvLine(frame_copy,kneePoint,hipPoint,CV_RGB(255,0,0),1,1);
+			cvLine(frame_copy,kneePoint,toePoint,CV_RGB(255,0,0),1,1);
 			
 			cvSeqPush( hipSeq, &hipPoint );
 			cvSeqPush( kneeSeq, &kneePoint );
-			cvSeqPush( footSeq, &footPoint );
+			cvSeqPush( toeSeq, &toePoint );
 
 			/*draw line of knee distance between holes validation and black detection
 			 */
 
 			if(kneeHolesPoint.x > 0) 
-				cvLine(frame_copy,kneeHolesPoint, kneePoint,CV_RGB(225,225,0),1,1);
+				cvLine(frame_copy,kneeHolesPoint, kneePoint,CV_RGB(128,128,128),1,1);
 			if(hipHolesPoint.x > 0) 
-				cvLine(frame_copy,hipHolesPoint, hipPoint,CV_RGB(225,225,0),1,1);
+				cvLine(frame_copy,hipHolesPoint, hipPoint,CV_RGB(128,128,128),1,1);
 			if(toeHolesPoint.x > 0) 
-				cvLine(frame_copy,toeHolesPoint, footPoint,CV_RGB(225,225,0),1,1);
+				cvLine(frame_copy,toeHolesPoint, toePoint,CV_RGB(128,128,128),1,1);
 
 			/*
 			 * draw perpendicular line (min distance)
@@ -412,21 +477,38 @@
 					cvPoint(maxrect.x + maxrect.width, maxrect.y + maxrect.height),
 					CV_RGB(255,0,0),1,1);
 
-			//print angles
-			sprintf(label, "        black  holes  diff diff(%)");
-			cvPutText(frame_copy, label, cvPoint(5,frame->height *.7),&font,cvScalar(0,0,255));
-			sprintf(label, "current: %.1f %.1f %.1f %.1f", theta, thetaHoles, 
-					thetaHoles-theta, relError(theta, thetaHoles));
-			cvPutText(frame_copy, label, cvPoint(5,frame->height *.7 +20),&font,cvScalar(0,0,255));
-			sprintf(label, "min:     %.1f %.1f %.1f %.1f", minTheta, minThetaHoles, 
-					minThetaHoles-minTheta, relError(minTheta, minThetaHoles));
-			cvPutText(frame_copy, label, cvPoint(5,frame->height *.7 +40),&font,cvScalar(0,0,255));
+			//print data
+			double thetaSup = findAngle(hipPoint, cvPoint(0,kneePoint.y), kneePoint);
+			double thetaHolesSup = findAngle(hipHolesPoint, cvPoint(0, kneeHolesPoint.y), kneeHolesPoint);
+
+			double thetaInf = findAngle(cvPoint(0,kneePoint.y), toePoint, kneePoint);
+			double thetaHolesInf = findAngle(cvPoint(0,kneeHolesPoint.y), toeHolesPoint, kneeHolesPoint);
+
+			//sprintf(label, "%7d %7.2f %7.2f [%7.2f %7.2f] %7.2f %7.2f %7.2f %7.2f", framesCount, theta, thetaHoles, 
+			//		thetaHoles-theta, relError(theta, thetaHoles), 
+			sprintf(label, "%7d %7.2f %7.2f [%7.2f %7.2f] %7.2f %7.2f %7.2f %7.2f", framesCount, thetaBack, thetaHoles, 
+					thetaHoles-thetaBack, relError(thetaBack, thetaHoles), 
+					getDistance(kneePoint, kneeHolesPoint), 
+					thetaSup-thetaHolesSup, thetaInf-thetaHolesInf,
+					getDistance(kneePointBack, kneeHolesPoint) 
+					);
+			printf("%s\n" ,label);
+
+			avgThetaDiff += abs(thetaHoles-theta);
+			avgThetaDiffPercent += abs(relError(theta, thetaHoles));
+			avgKneeDistance += getDistance(kneePoint, kneeHolesPoint);
+			avgKneeBackDistance += getDistance(kneePointBack, kneeHolesPoint);
+			framesDetected ++;
 		} else{
 			cvSeqPush( hipSeq, &notFoundPoint );
 			cvSeqPush( kneeSeq, &notFoundPoint );
-			cvSeqPush( footSeq, &notFoundPoint );
+			cvSeqPush( toeSeq, &notFoundPoint );
 		}
 			
+		sprintf(label, "%d", framesCount);
+		cvPutText(frame_copy, label, cvPoint(10,frame->height-20),&font,CV_RGB(255,255,255));
+			
+			
 		cvShowImage("result",frame_copy);
 
 		/* wait key for pause
@@ -463,11 +545,20 @@
 
 		//cvShowImage("foundHoles",foundHoles);
 		//cvShowImage("output",output);
+		//
+
 	}
 	
 	if(foundAngleOneTime) {
+			
+		avgThetaDiff = (double) avgThetaDiff / framesDetected;
+		avgThetaDiffPercent = (double) avgThetaDiffPercent / framesDetected;
+		avgKneeDistance = (double) avgKneeDistance / framesDetected;
+		avgKneeBackDistance = (double) avgKneeBackDistance / framesDetected;
+		
+		printf("\n[%f %f] %f %f\n", avgThetaDiff, avgThetaDiffPercent, avgKneeDistance, avgKneeBackDistance);
 
-
+//exit(0);
 		if(showStickThePoints || 
 				showStickTheLinesBetweenDifferentPoints ||
 				showStickTheLinesBetweenSamePoints) {
@@ -478,18 +569,21 @@
 				if(pointIsNull(hipLast)) {
 					cvSeqPop( hipSeq );
 					cvSeqPop( kneeSeq );
-					cvSeqPop( footSeq );
+					cvSeqPop( toeSeq );
 				}
 			
 				hipLast = *CV_GET_SEQ_ELEM( CvPoint, hipSeq, hipSeq->total-1);
 			} while(pointIsNull(hipLast) );
 
-			if(mixStickWithMinAngleWindow)
-				paintStick(result, lowestAngleFrame, hipSeq, kneeSeq, footSeq, 
+//exit(0);
+			if(mixStickWithMinAngleWindow) {
+				paintStick(result, lowestAngleFrame, hipSeq, kneeSeq, toeSeq, 
 						showStickThePoints, showStickTheLinesBetweenDifferentPoints,
 						showStickTheLinesBetweenSamePoints, showStickOnlyStartMinEnd, font);
-			else {
-				paintStick(resultStick, lowestAngleFrame, hipSeq, kneeSeq, footSeq, 
+				cvNamedWindow("Minimum Frame",1);
+				cvShowImage("Minimum Frame", result);
+			} else {
+				paintStick(resultStick, lowestAngleFrame, hipSeq, kneeSeq, toeSeq, 
 						showStickThePoints, showStickTheLinesBetweenDifferentPoints,
 						showStickTheLinesBetweenSamePoints, showStickOnlyStartMinEnd, font);
 				cvNamedWindow("Stick Figure",1);
@@ -497,16 +591,15 @@
 			}
 		}
 		
-		cvNamedWindow("Minimum Frame",1);
-		sprintf(label, "        black  holes  diff diff(%)");
-		cvPutText(result, label, cvPoint(5,frame->height *.7),&font,cvScalar(0,0,255));
-		sprintf(label, "%.1f %.1f %.1f %.1f", minTheta, minThetaHoles, 
+		printf("Minimum Frame\n");
+		sprintf(label, "minblack minholes    diff diff(%)");
+		sprintf(label, "%8.2f %8.2f [%7.2f %7.2f]", minTheta, minThetaHoles, 
 					minThetaHoles-minTheta, relError(minTheta, minThetaHoles));
-		cvPutText(result, label, cvPoint(5,frame->height *.7 +20),&font,cvScalar(0,0,255));
-		cvShowImage("Minimum Frame", result);
+		printf("%s\n" ,label);
 		
 		cvWaitKey(0);
 	}
+//exit(0); abans d'aqui
 
 	/* show all windows*/	
 	/*

Modified: trunk/src/angle/kneeAngleFunctions.cpp
==============================================================================
--- trunk/src/angle/kneeAngleFunctions.cpp	(original)
+++ trunk/src/angle/kneeAngleFunctions.cpp	Tue Oct  7 11:42:23 2008
@@ -157,6 +157,63 @@
 	return pt;
 }
 
+//hueco popliteo
+CvPoint FindKneePointBack(IplImage *img,CvRect roirect,int starty, int kneePointFrontX)
+{
+	CvPoint pt;
+	pt.x = 0; pt.y = 0;
+
+	/*
+	 * this 8/10 makes no error when jump starts, 
+	 * if not, on jump, the bottom of the pants can be taken as kneeBack
+	 */
+	int endy = roirect.y+roirect.height*8/10; 
+
+	CvMat *srcmat,src_stub;
+	srcmat = cvGetMat(img,&src_stub);
+	uchar *srcdata = srcmat->data.ptr;
+	int width = img->width;
+	int maxx = 0;
+	int maxy = 0;
+	
+	//use to fount the lowest consecutive point (under the maxx, maxy)
+	//then we will found the 1/2 height between  both
+	int maxx2 = 0;
+	int maxy2 = -1;
+	
+	bool foundNow = false;
+	for(int y=starty;y<endy;y++)
+	{
+		uchar *srcdataptr = srcdata + y*img->width;
+		for(int x=0; x < kneePointFrontX; x++)
+		{
+			if(srcdataptr[x] > 0)
+			{
+				if(x>maxx)
+				{
+					maxx = x;
+					maxy = y;
+					foundNow = true;
+				}
+				else if(foundNow && x==maxx) {
+					maxx2 = x;
+					maxy2 = y;
+				} else
+					foundNow = false;
+		
+				break;
+			}
+		}
+	}
+	pt.x = maxx;
+	if(maxy2 != -1 && maxx == maxx2)
+		pt.y = (maxy2+maxy)/2;
+	else 
+		pt.y = maxy;
+
+	return pt;
+}
+
 /*
  * takes as input arguement the bounding rectangle of the largest contour,the image containing the bounding rectangle and the x and y coordinate of the knee point
  * Calculates the toe point
@@ -169,8 +226,8 @@
 	pt.x = 0; pt.y = 0;
 	
 	
-	/* if foot is in the image, is better to try to avoid it capturing above, if not then capture all
-	 * maybe force user to capture without foot, or ask and put a boolean
+	/* if toe is in the image, is better to try to avoid it capturing above, if not then capture all
+	 * maybe force user to capture without toe, or ask and put a boolean
 	 */
 
 	//int endy = roirect.y+roirect.height*9/10; //this is ok if shoes or platform is shown in standup image
@@ -233,16 +290,6 @@
 	
 	//stick storage
 	CvMemStorage* storage = cvCreateMemStorage(0);
-	CvSeq* seq0 = cvCreateSeq( CV_SEQ_KIND_GENERIC|CV_32SC2, sizeof(CvSeq), sizeof(CvPoint), storage );
-	CvSeq* seq1 = cvCreateSeq( CV_SEQ_KIND_GENERIC|CV_32SC2, sizeof(CvSeq), sizeof(CvPoint), storage );
-	CvSeq* seq2 = cvCreateSeq( CV_SEQ_KIND_GENERIC|CV_32SC2, sizeof(CvSeq), sizeof(CvPoint), storage );
-	CvSeq* seq3 = cvCreateSeq( CV_SEQ_KIND_GENERIC|CV_32SC2, sizeof(CvSeq), sizeof(CvPoint), storage );
-	CvSeq* seq4 = cvCreateSeq( CV_SEQ_KIND_GENERIC|CV_32SC2, sizeof(CvSeq), sizeof(CvPoint), storage );
-	CvSeq* seq5 = cvCreateSeq( CV_SEQ_KIND_GENERIC|CV_32SC2, sizeof(CvSeq), sizeof(CvPoint), storage );
-	CvSeq* seq6 = cvCreateSeq( CV_SEQ_KIND_GENERIC|CV_32SC2, sizeof(CvSeq), sizeof(CvPoint), storage );
-	CvSeq* seq7 = cvCreateSeq( CV_SEQ_KIND_GENERIC|CV_32SC2, sizeof(CvSeq), sizeof(CvPoint), storage );
-	CvSeq* seq8 = cvCreateSeq( CV_SEQ_KIND_GENERIC|CV_32SC2, sizeof(CvSeq), sizeof(CvPoint), storage );
-	CvSeq* seq9 = cvCreateSeq( CV_SEQ_KIND_GENERIC|CV_32SC2, sizeof(CvSeq), sizeof(CvPoint), storage );
 
 	cvZero(foundHoles);
 
@@ -260,7 +307,7 @@
 			{
 				if(srcdataptrH[x] == 0) {
 					pt.x =x;pt.y=y;
-					cvCircle(foundHoles,pt,1, CV_RGB(128,128,128),1,8,0);
+					//cvCircle(foundHoles,pt,1, CV_RGB(128,128,128),1,8,0);
 
 					cvSeqPush( seqPoints, &pt );
 				}
@@ -284,23 +331,6 @@
 
 	printf("\n");
 */
-		//find three biggest seqs
-		/*	
-		 * seq0, seq1, ... amb els punts
-		 * seqHolesUpLeft un seq amb els 10 punts de dalt a l'esquerra de cada hole 
-		 * seqHolesDownRight un seq amb els 10 punts de baix a la dreta de cada hole
-		 * seqHolesCenter un seq amb els 10 punts centre de cada hole
-		 * seqHolesSize un seq amb les mides de cada hole (en nombre de punts)
-		 * que miri la 3a mes gran a seqHolesize (sempre i quan la seva horiz i vertical sigui d'uns valors minims (per no agafar linies rectes llargues)), fer-ho restant el downRight dels upleft per ax i y
-		 * que assigni hip al seqHolesCenter que aparegui en primera posicià dels 3 que sÃn prou grans
-		 * que assigni knee al seqHolesCenter que aparegui en segona posicià dels 3 que sÃn prou grans
-		 * que assigni toe al seqHolesCenter que aparegui en tercera posicià dels 3 que sÃn prou grans
-		 * que pinti un cercle a cada un dels tres punts i faci l'angle...
-		 *
-		 * finalment, agafar la imatge gray (la del histograma i pintar de negre tots els punts que estiguin blancs dels seq0..seq1.. triats com a hip, knee, toe)
-		 * -----------------------
-		 *
-		 */
 
 	CvPoint pt1; CvPoint pt2; CvPoint pt3;
  	
@@ -404,32 +434,32 @@
 				cvRectangle(imgMain, 
 						cvPoint(sp1.x-1,sp1.y-1),
 						cvPoint(sp2.x+1, sp2.y+1),
-						CV_RGB(255,0,0),1,1);
+						CV_RGB(0,255,0),1,1);
 				hipPoint.x = center.x; hipPoint.y = center.y;
-				cvCircle(imgMain,center,1, CV_RGB(255,255,0),CV_FILLED,8,0);
+//				cvCircle(imgMain,center,1, CV_RGB(0,255,0),CV_FILLED,8,0);
 			} else if(kneePoint.x == 0) {
 				cvRectangle(imgMain, 
 						cvPoint(sp1.x-1,sp1.y-1),
 						cvPoint(sp2.x+1, sp2.y+1),
 						CV_RGB(0,255,0),1,1);
 				kneePoint.x = center.x; kneePoint.y = center.y;
-				cvCircle(imgMain,center,1, CV_RGB(255,255,0),CV_FILLED,8,0);
+//				cvCircle(imgMain,center,1, CV_RGB(0,255,0),CV_FILLED,8,0);
 			} else {
 				cvRectangle(imgMain, 
 						cvPoint(sp1.x-1,sp1.y-1),
 						cvPoint(sp2.x+1, sp2.y+1),
-						CV_RGB(0,0,255),1,1);
+						CV_RGB(0,255,0),1,1);
 				toePoint.x = center.x; toePoint.y = center.y;
-				cvCircle(imgMain,center,1, CV_RGB(255,255,0),CV_FILLED,8,0);
+//				cvCircle(imgMain,center,1, CV_RGB(0,255,0),CV_FILLED,8,0);
 			}
 		}
 	}
 
 	if(kneePoint.x > 0) {
 		if(hipPoint.x > 0)
-			cvLine(imgMain,hipPoint,kneePoint,CV_RGB(128,128,128),1,1);
+			cvLine(imgMain,hipPoint,kneePoint,CV_RGB(0,255,0),1,1);
 		if(toePoint.x > 0)
-			cvLine(imgMain,toePoint,kneePoint,CV_RGB(128,128,128),1,1);
+			cvLine(imgMain,toePoint,kneePoint,CV_RGB(0,255,0),1,1);
 	}
 	
 	/* Test:
@@ -446,11 +476,27 @@
 	}
 	*/
 	//end of test
+
+	CvPoint notFoundPoint;
+	notFoundPoint.x = 0; notFoundPoint.y = 0;
 	
 	CvSeq* seqHolesEnd = cvCreateSeq( CV_SEQ_KIND_GENERIC|CV_32SC2, sizeof(CvSeq), sizeof(CvPoint), storage );
-	cvSeqPush( seqHolesEnd, &hipPoint );
-	cvSeqPush( seqHolesEnd, &kneePoint );
-	cvSeqPush( seqHolesEnd, &toePoint );
+	
+	if(hipPoint.x > 0) 
+		cvSeqPush( seqHolesEnd, &hipPoint );
+	else
+		cvSeqPush( seqHolesEnd, &notFoundPoint );
+	
+	if(kneePoint.x > 0) 
+		cvSeqPush( seqHolesEnd, &kneePoint );
+	else
+		cvSeqPush( seqHolesEnd, &notFoundPoint );
+
+	if(toePoint.x > 0) 
+		cvSeqPush( seqHolesEnd, &toePoint );
+	else
+		cvSeqPush( seqHolesEnd, &notFoundPoint );
+	
 	return seqHolesEnd;
 }
 
@@ -504,8 +550,39 @@
 	return maxrect;
 }
 
+//point will be more at right if there's more flexion
+int fixToePointX(int toeX, int toeWidth, double kneeAngle)
+{
+			
+//	toePoint.x -= toePointWidth /2;
+
+	//point will be more at right if there's more flexion
+	double mult;
+	double maxRight = .7; //maximum right
+	double valueAtExtension = .6;
+	if(kneeAngle >= 180)
+		mult = valueAtExtension;
+	else if(kneeAngle < 90)
+		mult = maxRight;
+	else {
+		double temp = maxRight - valueAtExtension;
+		double sum = ((180/kneeAngle) -1) *temp;
+		mult = valueAtExtension + sum;
+//		printf("%f-%f-%f  ", kneeAngle, sum, mult);
+	}
+	
+	//ptHK.x = (startX + countX) /2;
+	int startX = toeX - toeWidth; 
+	int endX = toeX; 
+	toeX = startX + (endX-startX)*mult;
+//	printf("%d-%d-%d\n", startX, endX, ptHK.x);
+
+//	ptHK.y = y;
+	
+	return toeX;
+}
 
-CvPoint FixHipPoint1(IplImage* img, CvPoint hip, CvPoint knee, double angle)
+CvPoint FixHipPoint1(IplImage* img, CvPoint hip, CvPoint knee, double kneeAngle)
 {
 	CvPoint ptHK;
 	ptHK.x =0;ptHK.y=0;
@@ -536,21 +613,22 @@
 
 	//point will be more at right if there's more flexion
 	double mult;
+	double valueAtExtension = .6;
 	double maxRight = .7; //maximum right
-	if(angle >= 180)
-		mult = .5;
-	else if(angle < 90)
+	if(kneeAngle >= 180)
+		mult = valueAtExtension;
+	else if(kneeAngle < 90)
 		mult = maxRight;
 	else {
-		double temp = maxRight -.5; //if 5, then will be added to 
-		double sum = ((180/angle) -1) *temp;
-		mult = .5 + sum;
-		printf("%f-%f-%f  ", angle, sum, mult);
+		double temp = maxRight - valueAtExtension; 
+		double sum = ((180/kneeAngle) -1) *temp;
+		mult = valueAtExtension + sum;
+		//printf("%f-%f-%f  ", kneeAngle, sum, mult);
 	}
 	
 	//ptHK.x = (startX + countX) /2;
 	ptHK.x = startX + (endX-startX)*mult;
-	printf("%d-%d-%d\n", startX, endX, ptHK.x);
+	//printf("%d-%d-%d\n", startX, endX, ptHK.x);
 
 	ptHK.y = y;
 	
@@ -604,7 +682,7 @@
 }
 
 /* paints stick figure at end */
-void paintStick(IplImage *img, int lowestAngleFrame, CvSeq *hipSeq, CvSeq* kneeSeq, CvSeq *footSeq, 
+void paintStick(IplImage *img, int lowestAngleFrame, CvSeq *hipSeq, CvSeq* kneeSeq, CvSeq *toeSeq, 
 		bool showPoints, bool showLinesDiff, bool showLinesSame, bool onlyStartMinEnd, CvFont font) {
 	
 	//colors for start, end points, and up, down lines
@@ -623,7 +701,7 @@
 	{
 		CvPoint hip = *CV_GET_SEQ_ELEM( CvPoint, hipSeq, i );
 		CvPoint knee = *CV_GET_SEQ_ELEM( CvPoint, kneeSeq, i );
-		CvPoint foot = *CV_GET_SEQ_ELEM( CvPoint, footSeq, i );
+		CvPoint toe = *CV_GET_SEQ_ELEM( CvPoint, toeSeq, i );
 
 		//if this point was found
 		if(!pointIsNull(hip)) {
@@ -649,23 +727,23 @@
 			if(showPoints) {
 				cvCircle(img,knee,size, currentColor,1,8,0);
 				cvCircle(img,hip,size, currentColor,1,8,0);
-				cvCircle(img,foot,size, currentColor,1,8,0);
+				cvCircle(img,toe,size, currentColor,1,8,0);
 			}
 			if(showLinesDiff && paintAngleLines) {
 				cvLine(img,knee,hip,currentColor,1,1);
-				cvLine(img,knee,foot,currentColor,1,1);
+				cvLine(img,knee,toe,currentColor,1,1);
 			}
 			if(showLinesSame) {
 				if(i>0) {
 					CvPoint hipOld = *CV_GET_SEQ_ELEM( CvPoint, hipSeq, i-1);
 					CvPoint kneeOld = *CV_GET_SEQ_ELEM( CvPoint, kneeSeq, i-1);
-					CvPoint footOld = *CV_GET_SEQ_ELEM( CvPoint, footSeq, i-1);
+					CvPoint toeOld = *CV_GET_SEQ_ELEM( CvPoint, toeSeq, i-1);
 
 					//only paint line if previous point was found
 					if(!pointIsNull(hipOld)) {
 						cvLine(img, hip, hipOld, connectedWithPreviousColor,1,1);
 						cvLine(img, knee, kneeOld, connectedWithPreviousColor,1,1);
-						cvLine(img, foot, footOld, connectedWithPreviousColor,1,1);
+						cvLine(img, toe, toeOld, connectedWithPreviousColor,1,1);
 					}
 				}
 			}

Modified: trunk/src/angle/kneeAngleUtil.cpp
==============================================================================
--- trunk/src/angle/kneeAngleUtil.cpp	(original)
+++ trunk/src/angle/kneeAngleUtil.cpp	Tue Oct  7 11:42:23 2008
@@ -160,6 +160,13 @@
 	return countX;;
 }
 
+double abs(double val)
+{
+	if(val<0)
+		val *= -1;
+	return val;
+}
+
 double getDistance(CvPoint p1, CvPoint p2)
 {
 	return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
@@ -220,7 +227,7 @@
 	if(val2-val1 == 0 || val2 == 0)
 		return -1;
 	else
-		return (val2-val1)/val2 *100;
+		return (double) (val2-val1)/val2 *100;
 }
 
 int getMaxValue(CvSeq* seqGroups)



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