chronojump r427 - trunk/src/angle



Author: xaviblas
Date: Sun Nov  9 13:57:49 2008
New Revision: 427
URL: http://svn.gnome.org/viewvc/chronojump?rev=427&view=rev

Log:
some changes


Added:
   trunk/src/angle/kneeAngleGlobal.cpp
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	Sun Nov  9 13:57:49 2008
@@ -110,7 +110,16 @@
 /*
  * TODO:
  * -imprimeixi en arxiu xy de cada punt (6 columnes)
- *  -allow to go one frame foreward or backward
+ *  -implement adaptative threshold on skin only markers, to allow hip (pant bended) to be detected without having a threshold too low or too large on knee and toe
+ *  solve the problem with the cvCopy(frame_copy,result);
+ *  	on blackAndMarkers, minimumFrame is the marked or the expected?
+ * -on skin, when a point is lost, re-assign the other points depending on distance with previous frame marked points
+ *  -study kalman on openCV book (not interesting)
+ *  -calibration and undistortion (distorsions: radial, and tangential)
+ *     radial doesn't exist on image, because the line dividing floor and wall is straight from left to right (radial will make distort on places far from the center)
+ *     tangential (p376,377) seems also to not exist on used camera, but best to record a cheesboard or square object to check
+ *     maybe we can use opencv to paint the "claqueta" corners, and the use it as a chessboard, the problem is that this image is not always fully seen, but it doesn't need to be seen in all persons
+ *     but use calibration all the time is not nice, because we prefer to record best the person, and zoom in or out if necessary. if the camera has not considerable distorsion, is best to don't need to be all the time with the chessboard. maybe we can (in the software) test the camera one time to see its distorsion. A 398 diu que Ãs millor que es vegi el chessboard des de diferents llocs, sinà la solucià no serà bona. Aixà que millor oblidar-se de pintar la claqueta com a chessboard quan entra per la dreta. Pero sà que es podria calcular la distorsià de la cÃmera i provar un mateix salt (amb marcadors) amb undistort i sense. Val a dir tambà que els punts cercats de la imatge no sÃn a les cantonades, aixà que la radial distort afectarà poc; està per veure la tangencial, tot i que Ãs mÃs cosa de cheap cameres.
  */
 
 #include "opencv/cv.h"
@@ -123,6 +132,7 @@
 #include<vector>
 #include <string>
 
+#include "kneeAngleGlobal.cpp"
 #include "kneeAngleUtil.cpp"
 #include "kneeAngleFunctions.cpp"
 
@@ -130,37 +140,6 @@
 
 int menu(IplImage *, CvFont);
 
-//config variables
-bool showContour = true;
-bool debug = false;
-int playDelay = 10; //milliseconds between photogrammes wen playing. Used as a waitkey. 
-			//not put values lower than 5 or the enter when executing will be the first pause
-			//eg: 5 (fast) 1000 (one second each photogramme)
-//int playDelayFoundAngle = 150; //as above, but used when angle is found. 
-int playDelayFoundAngle = 50; //as above, but used when angle is found. 
-				//Useful to see better the detected angle when something is detected
-				//recommended values: 50 - 200
-
-//used for validating
-enum { markerColorBlue = 0, markerColorRed = 1, markerColorGreen = 2, markerColorYellow = 3 };
-
-
-
-/* recommended: 
-   showAtLinesPoints = true
-   ...DiffPoints = true
-   ...SamePoints = true
-   ...OnlyStartMinEnd = true;
-   */
-
-bool showStickThePoints = true;
-bool showStickTheLinesBetweenSamePoints = true;
-bool showStickTheLinesBetweenDifferentPoints = true;
-bool showStickOnlyStartMinEnd = true;
-bool mixStickWithMinAngleWindow = true;
-
-int startAt = 1;
-enum { blackAndMarkers = 0, blackOnlyMarkers = 1, skinOnlyMarkers = 2 };
 	
 int main(int argc,char **argv)
 {
@@ -261,7 +240,13 @@
 	int forwardSpeed = 50;
 	bool forwardSuper = false; 
 	int forwardSuperSpeed = 200;
-	int forwardCount = 0;
+	int forwardCount = 1;
+	bool backward = false;
+	int backwardSpeed = 50;
+	
+	bool jumping = false;
+
+
 
 	bool labelsAtLeft = true;
 		
@@ -282,22 +267,9 @@
 	int thresholdInc = 1;
 
 	int key;
-	bool jumpedFrames = false;
-	bool jumping = false;
+
 
 	//programMode == blackAndMarkers
-	/*
-	CvMemStorage* storage = cvCreateMemStorage(0);
-	CvSeq* kneeSeqFindNow = cvCreateSeq( 0, sizeof(CvSeq), sizeof(0), storage );
-	CvSeq* kneeSeqFindBefore = cvCreateSeq( 0, sizeof(CvSeq), sizeof(0), storage );
-	int kneeSeqFindCount = 0;
-	int kneeSeqFindStep = 10;
-	*/
-	/*
-	CvSeq* kneeSeq3 = cvCreateSeq( 0, sizeof(CvSeq), sizeof(0), storage );
-	CvSeq* kneeSeq4 = cvCreateSeq( 0, sizeof(CvSeq), sizeof(0), storage );
-	CvSeq* kneeSeq5 = cvCreateSeq( 0, sizeof(CvSeq), sizeof(0), storage );
-	*/
 	bool extensionCopyDone = false;
 	CvPoint kneeMarkedAtExtension = pointToZero();
 	CvPoint hipMarkedAtExtension = pointToZero();
@@ -306,14 +278,17 @@
 			
 	while(!shouldEnd) 
 	{
-		framesCount ++;
-				
 		/*
 		 * 1
 		 * GET FRAME AND FLOW CONTROL
 		 */
 
 		frame = cvQueryFrame(capture);
+		
+		//when we go back, we doesn't always land where we want, this is safe:
+		double capturedFrame = cvGetCaptureProperty( capture, CV_CAP_PROP_POS_FRAMES);
+		framesCount = capturedFrame +1;
+
 		if(!frame)
 			break;
 		if(startAt > framesCount) {
@@ -327,7 +302,7 @@
 				continue;
 			} else {
 				//end of forwarding
-				forwardCount = 0;
+				forwardCount = 1;
 				forward = false;
 				forwardSuper = false;
 
@@ -338,11 +313,12 @@
 				toeOld = pointToZero();
 			}
 		}
-		if(jumping) {
+		if(jumping || backward) {
 				hipOld = pointToZero();
 				kneeOld = pointToZero();
 				toeOld = pointToZero();
 				jumping = false;
+				backward = false;
 		}
 
 
@@ -406,7 +382,7 @@
 			toeOld = toeMarked;
 			*/
 				
-			CvSeq* seqHolesEnd = findHolesSkin(output, frame_copy, hipMarked, kneeMarked, toeMarked);
+			CvSeq* seqHolesEnd = findHolesSkin(output, frame_copy, hipMarked, kneeMarked, toeMarked, font);
 
 			hipMarked = *CV_GET_SEQ_ELEM( CvPoint, seqHolesEnd, 0); 
 			kneeMarked = *CV_GET_SEQ_ELEM( CvPoint, seqHolesEnd, 1 ); 
@@ -435,11 +411,13 @@
 				cvThreshold(gray, output, threshold, thresholdMax,CV_THRESH_BINARY_INV);
 				cvShowImage("skinOutput", output);
 					
-				printf("\nFrame: %d H(%d,%d), K(%d,%d), T(%d,%d)\n", framesCount, hipMarked.x, hipMarked.y, 
-						kneeMarked.x, kneeMarked.y, toeMarked.x, toeMarked.y);
+				//printf("\nFrame: %d H(%d,%d), K(%d,%d), T(%d,%d)\n", framesCount, hipMarked.x, hipMarked.y, 
+				//		kneeMarked.x, kneeMarked.y, toeMarked.x, toeMarked.y);
 
 
+				/*
 				if(pointIsNull(hipMarked) || pointIsNull(kneeMarked) || pointIsNull(toeMarked)) {
+					sprintf(label, "Please mark");
 					printf("** Please mark:");
 					if(pointIsNull(hipMarked))
 						printf(" HIP ");
@@ -449,20 +427,34 @@
 						printf(" TOE ");
 					printf("on 'toClick' window **\n");
 				}
-				
-				printf("Press 'p' when done.\n");
-				printf("Optionally:\n");
-				printf("\tReMark hip 'h', knee 'k', toe 't'\n"); 
-				printf("\tChange threshold: %d ('+' increase, '-' decrease)\n", threshold); 
-				printf("\tOthers: Zoom 'z', forward 'f', Forward 'F', jump 'j', quit program 'q'\n\n"); 
+				*/
+			
+				/*	
+				printf("Mark: hip 'h', knee 'k', toe 't' on 'toClick' window if needed\n"); 
+				printf("Change threshold: %d ('+' increase, '-' decrease)\n", threshold); 
+				printf("Others: Zoom 'z', forward 'f', Forward 'F', jump 'j', quit program 'q'\n\n"); 
+				printf("\tPress 'p' when done.\n");
+				*/
+				int row = 1;
+				int step = 16;
+				imagePrint(gui, cvPoint(10, step*row++), "Mark: hip 'h', knee 'k', toe 't' on 'toClick' window if needed", font, WHITE);
+				imagePrint(gui, cvPoint(10, step*row++), "Change threshold: %d ('+' increase, '-' decrease)", font, WHITE);
+				imagePrint(gui, cvPoint(10, step*row++), "Zoom 'z'", font, WHITE);
+				imagePrint(gui, cvPoint(10, step*row++), "forward 'f', Forward 'F', jump 'j'", font, WHITE);
+				imagePrint(gui, cvPoint(10, step*row++), "Quit program 'q'", font, WHITE);
+				row ++;
+				imagePrint(gui, cvPoint(10, step*row++), "Press 'p' when done.", font, WHITE);
+				cvShowImage("gui", gui);
 
 				bool done = false;
 				IplImage* imgZoom;
-				do {
-					cvCvtColor(frame_copy,output,CV_BGR2GRAY);
-					cvThreshold(gray, output, threshold, thresholdMax,CV_THRESH_BINARY_INV);
 					
-					key = (char) cvWaitKey(0);
+				cvCvtColor(frame_copy,output,CV_BGR2GRAY);
+				cvThreshold(gray, output, threshold, thresholdMax,CV_THRESH_BINARY_INV);
+						
+				bool thresholdChanged = false;
+				do {
+					key = (char) cvWaitKey(50);
 					if(key == 'p' )
 						done  = true;
 					else if(key == 'q') {
@@ -491,11 +483,15 @@
 					} else if(key == 't') {
 						forceMouseToe = true;
 						printf("Remark Toe: ");
-					} else if(key == '+')
+					} else if(key == '+') {
 						threshold ++;
-					else if(key == '-')
+						thresholdChanged = true;
+					} else if(key == '-') {
 						threshold --;
-					else if (key == 'f') {// 'FORWARD'
+						if(threshold < 0)
+							threshold = 0;
+						thresholdChanged = true;
+					} else if (key == 'f') {// 'FORWARD'
 						forward = true;
 						printf("forwarding ...\n");
 						done  = true;
@@ -519,25 +515,41 @@
 						kneeOld = pointToZero();
 						toeOld = pointToZero();
 
-						//when jumper is extending legs after maximal flexion, jump ends
-						//this jumped makes it didn't work, avoiding ending a jump
-						//when we have gone ('j') from a maximal flexion to the 1st frame again (extension)
-						jumpedFrames = true;
 						printf("jumping ...\n");
 						done = true;
 					}
 					
-					cvThreshold(gray, output, threshold, thresholdMax,CV_THRESH_BINARY_INV);
+					if(thresholdChanged)  {
+						cvThreshold(gray, output, threshold, thresholdMax,CV_THRESH_BINARY_INV);
 
-					sprintf(label, "frame: %d", framesCount);
-					//cvPutText(output, label, cvPoint(10,frame->height-40),&font,CV_RGB(0,0,0));
-					imagePrint(output, "skinOutput", cvPoint(10, frame->height-40), label, font, WHITE);
-
-					sprintf(label, "threshold: %d", threshold);
-					//cvPutText(output, label, cvPoint(10,frame->height-20),&font,CV_RGB(0,0,0));
-					imagePrint(output, "skinOutput", cvPoint(10, frame->height-20), label, font, WHITE);
+						sprintf(label, "frame: %d", framesCount);
+						imagePrint(output, cvPoint(10, frame->height-40), label, font, WHITE);
+
+						sprintf(label, "threshold: %d", threshold);
+						imagePrint(output, cvPoint(10, frame->height-20), label, font, WHITE);
 				
-					cvShowImage("skinOutput", output);
+						cvShowImage("skinOutput", output);
+						thresholdChanged = false;
+					}
+				
+					if(!pointIsEqual(hipMarked,hipMouse)) {
+						crossPoint(frame_copy, hipMouse, MAGENTA, BIG);
+						imagePrint(frame_copy, cvPoint(hipMouse.x -20, hipMouse.y), "H", font, MAGENTA);
+						hipMarked = hipMouse;
+						cvShowImage("toClick", frame_copy);
+					}
+					if(!pointIsEqual(kneeMarked,kneeMouse)) {
+						crossPoint(frame_copy, kneeMouse, MAGENTA, BIG);
+						imagePrint(frame_copy, cvPoint(kneeMouse.x -20, kneeMouse.y), "K", font, MAGENTA);
+						kneeMarked = kneeMouse;
+						cvShowImage("toClick", frame_copy);
+					}
+					if(!pointIsEqual(toeMarked,toeMouse)) {
+						crossPoint(frame_copy, toeMouse, MAGENTA, BIG);
+						imagePrint(frame_copy, cvPoint(toeMouse.x -20, toeMouse.y), "T", font, MAGENTA);
+						toeMarked = toeMouse;
+						cvShowImage("toClick", frame_copy);
+					}
 				} while(! done);
 				
 				hipMarked = hipMouse;
@@ -550,6 +562,7 @@
 					zoomed = false;
 				}
 				mouseCanMark = false;
+				eraseGuiWindow(gui);
 			}
 			
 		} 
@@ -583,45 +596,133 @@
 		kneeOld = kneeMarked;
 		toeOld = toeMarked;
 
-
-		CvPoint hipExpected;
-		CvPoint kneeExpected;
-		CvPoint toeExpected;
-
 		/*
 		 * 4
-		 * FIND POINTS ON BLACKANDMARKERS
+		 * PRINT MARKERS RELATED INFO AND DO CALCULATIONS LIKE ANGLE
 		 */
 
-		if(programMode == blackAndMarkers) {
-			/*
-			kneeSeqFindNow = GetRowsCenter(
-					segmented,
-					maxrect,	
-					//maxrect.y + maxrect.height*1/3, //start at 1/3 of the y rect
-					//maxrect.y + maxrect.height*2/3 	//end at 2/3 of the y rect
-					segmented->height*1/3, //start at 1/3 of the y rect
-					segmented->height*2/3 	//end at 2/3 of the y rect
+
+		if(pointIsNull(hipMarked) || pointIsNull(kneeMarked) || pointIsNull(toeMarked))
+			thetaMarked = -1;
+		else {
+			thetaMarked = findAngle2D(hipMarked, toeMarked, kneeMarked);
+			if(thetaMarked < minThetaMarked) 
+				minThetaMarked = thetaMarked;
+
+
+			if(programMode == blackAndMarkers)
+				cvRectangle(frame_copy,
+						cvPoint(maxrect.x,maxrect.y),
+						cvPoint(maxrect.x + maxrect.width, maxrect.y + maxrect.height),
+						CV_RGB(255,0,0),1,1);
+
+
+			upLegMarkedDist = getDistance(hipMarked, kneeMarked);
+			if(upLegMarkedDist > upLegMarkedDistMax)
+				upLegMarkedDistMax = upLegMarkedDist;
+			downLegMarkedDist = getDistance(toeMarked, kneeMarked);
+			if(downLegMarkedDist > downLegMarkedDistMax)
+				downLegMarkedDistMax = downLegMarkedDist;
+
+			CvPoint HT;
+			HT.y = kneeMarked.y;
+			HT.x = hipMarked.x;
+
+			double kneeZetaSide = sqrt( pow(upLegMarkedDistMax,2) - pow(upLegMarkedDist,2) );
+			double htKneeMarked = getDistance (HT, kneeMarked);
+
+			double thetaABD = (180.0/M_PI)*atan( kneeZetaSide / (double) htKneeMarked );
+
+			double thetaRealFlex = findAngle3D(hipMarked, toeMarked, kneeMarked, 0, 0, -kneeZetaSide);
+			if(thetaRealFlex < minThetaRealFlex) 
+				minThetaRealFlex = thetaRealFlex;
+
+
+			if(programMode == skinOnlyMarkers) {
+				printOnScreen(output, font, CV_RGB(0,0,0), labelsAtLeft,
+						framesCount, threshold, 
+						(double) upLegMarkedDist *100 /upLegMarkedDistMax, 
+						(double) downLegMarkedDist *100 /downLegMarkedDistMax,
+						thetaMarked, minThetaMarked,
+						thetaABD, thetaRealFlex, minThetaRealFlex
+						);
+				cvShowImage("toClick", frame_copy);
+				cvShowImage("skinOutput",output);
+			}
+
+			printOnScreen(frame_copy, font, CV_RGB(255,255,255), labelsAtLeft,
+					framesCount, threshold, 
+					(double) upLegMarkedDist *100 /upLegMarkedDistMax, 
+					(double) downLegMarkedDist *100 /downLegMarkedDistMax,
+					thetaMarked, minThetaMarked,
+					thetaABD, thetaRealFlex, minThetaRealFlex
 					);
-			kneeSeqFindCount ++;
-			if(kneeSeqFindCount == kneeSeqFindStep) {
-				kneeSeqFindCount = 0;
-				findKneeSeqDifferences(kneeSeqFindBefore, kneeSeqFindNow, 
-						frame_copy, segmented->height*1/3);
-				kneeSeqFindBefore = kneeSeqFindNow;
-				key = (char) cvWaitKey(0);
+
+			if(programMode == blackAndMarkers && foundAngle) {
+				/*
+				//print data
+				double thetaSup = findAngle2D(hipExpected, cvPoint(0,kneeExpected.y), kneeExpected);
+				double thetaMarkedSup = findAngle2D(hipMarked, cvPoint(0, kneeMarked.y), kneeMarked);
+
+				double thetaInf = findAngle2D(cvPoint(0,kneeExpected.y), toeExpected, kneeExpected);
+				double thetaMarkedInf = findAngle2D(cvPoint(0,kneeMarked.y), toeMarked, kneeMarked);
+
+				printf("%7d %7.2f %7.2f [%7.2f %7.2f] %7.2f %7.2f %7.2f [%7.2f %7.2f] [%7.2f] [%7.2f]\n", framesCount, thetaExpected, thetaMarked, 
+				thetaMarked-thetaExpected, relError(thetaExpected, thetaMarked), 
+				getDistance(kneeExpected, kneeMarked), 
+				thetaSup-thetaMarkedSup, thetaInf-thetaMarkedInf
+				, getDistance(kneeMarked, hipMarked), getDistance(kneeExpected, hipExpected)
+				, getDistance(kneeExpected, hipPointBack)
+				, getDistance(kneePointBack, hipPointBack)
+				);
+
+				avgThetaDiff += abs(thetaMarked-thetaExpected);
+				avgThetaDiffPercent += abs(relError(thetaExpected, thetaMarked));
+				avgKneeDistance += getDistance(kneePoint, kneeMarked);
+				*/
+				framesDetected ++;
+			}
+
+
+			if(programMode == blackAndMarkers || programMode == blackOnlyMarkers)
 				cvShowImage("result",frame_copy);
-				key = (char) cvWaitKey(0);
+
+
+			//Finds the minimum angle between Hip to Knee line and Knee to Toe line
+			if(thetaRealFlex == minThetaRealFlex) {
+				cvCopy(frame_copy,result);
+				lowestAngleFrame = framesCount;
 			}
-			*/
 
-			/*
-ENLLOC D'AIXO, FER QUE L'AMPLADA DE QUADRAT MINIMA PER A DETECTAR ANGLE SIGUI MES PETITA,
-       QUE CERQUI ANGLE GENOLL PEL CENTRE, I QUE QUAN EL TROBI, EL MARQUI I DIGUI "KNEE FRONT ACCEPT? (y/n)"
-	       SI S'ACCEPTA, LLAVORS ALLA TROBAR EL CENTRE GENOLL, I X CAP A ESQ TROBAR AMPLADA CUL
-	TAMBE QUE LE KNEEPOINT FRONT EL TROBI ENTRE 1/3 I 2/3 DE LA IMAGE 
-*/
+			//exit if we are going up and soon jumping.
+			//toe will be lost
+			//detected if minThetaMarked is littler than thetaMarked, when thetaMarked is big
+			if(thetaMarked > 140 && 
+					minThetaMarked +10 < thetaMarked)
+			{
+				imageGuiAsk(gui, "Minimal flexion reached before. Ending. Accept?", "'n'o, 'y'es", font);
+				int option = optionAccept(true);	
+				eraseGuiAsk(gui);
+				if(option==YES) {
+					printf("\ntm: %f, mtm: %f, frame: %d\n", thetaMarked, minThetaMarked, framesCount);
+					shouldEnd = true;
+				}
+			}
+		}
+
+
+		CvPoint hipExpected;
+		CvPoint kneeExpected;
+		CvPoint toeExpected;
+
+		/*
+		 * 5
+		 * IF BLACKANDMARKERS MODE,
+		 * FIND POINTS
+		 */
 
+		if(programMode == blackAndMarkers) 
+		{
 			CvPoint hipPointBack;
 			CvPoint kneePointBack;
 			CvPoint kneePointFront;
@@ -647,23 +748,16 @@
 			if(minwidth == 0)
 				minwidth = kneePointFront.x - hipPointBack.x;
 			else {
-				//if((double)(kneePointFront.x- hipPointBack.x) > 1.15*minwidth 
-				if((double)(kneePointFront.x- hipPointBack.x) > 1.05*minwidth 
-						&&
+				if((double)(kneePointFront.x- hipPointBack.x) > 1.15*minwidth && //or 1.05 or 1.15
 						upperSimilarThanLower(hipExpected, kneePointFront, toeExpected)
 						&& !pointIsNull(hipMarked) && !pointIsNull(kneeMarked) && 
-						!pointIsNull(toeMarked)
-				  )
+						!pointIsNull(toeMarked))
 				{
 					if(foundAngleOneTime) {
 						foundAngle = true;
-					} else {
-
-
-//QUE NO ES FACI FINS QUE NO ESTIGUI EL EXTENSION ACCEPTAT
-
-
-
+					} 
+					else if(extensionCopyDone) 
+					{
 						/* 
 						 * first time, confirm we found knee ok (and angle)
 						 * maybe is too early
@@ -672,9 +766,9 @@
 						crossPoint(frame_copy, kneePointBack, GREY, MID);
 
 						cvShowImage("result",frame_copy);
-						imageGuiAsk(gui, "knee point front. Accept?", "'n', 'y', 'f', 'F', 'q'", font);
+						imageGuiAsk(gui, "knee found. Accept?", "'n'o, 'y'es, 'f'orward, super'F'orward, 'b'ackward, 'q'uit", font);
 					
-						int option = optionAccept();	
+						int option = optionAccept(false);	
 						eraseGuiAsk(gui);
 
 						if(option==YES) {
@@ -697,15 +791,16 @@
 
 							double kneeCenterExtX = rectExt.x + (double)(rectExt.width /2 );
 							double kneeCenterExtY = rectExt.y + (double)(rectExt.height /2 );
-							double kneeCenterExtXPercent = 100 * (double)(kneeCenterExtX - rectExt.x) / rectExt.width;
-							double kneeCenterExtYPercent = 100 * (double)(kneeCenterExtY - rectExt.y) / rectExt.height;
+
+							double kneeCenterExtXPercent = 100 * (double)(kneeCenterExtX - rectExt.x) / rectExt.width; //aprox 50%
+							double kneeCenterExtYPercent = 100 * (double)(kneeCenterExtY - rectExt.y) / rectExt.height; //aprox 50%
 							
 							printf("kneeCenterExtX,Y: %.1f(%.1f%%) %.1f(%.1f%%)\n", 
 									kneeCenterExtX, 
 									kneeCenterExtXPercent, 
 									kneeCenterExtY, 
 									kneeCenterExtYPercent 
-									);
+									);				//debug
 							
 							/*
 							 * now print differences between:
@@ -715,7 +810,6 @@
 
 							//see the % of rectangle where kneeMarked is (at extension)
 							double kneeMarkedXPercent = 100 * (double)(kneeMarkedAtExtension.x - rectExt.x) / rectExt.width;
-							//double kneeMarkedYPercent = 100 * (double)(kneeMarkedAtExtension.y - kneePointFront.y) / rectExt.height;
 							double kneeMarkedYPercent = 100 * (double)(kneeMarkedAtExtension.y - rectExt.y) / rectExt.height;
 
 
@@ -737,8 +831,8 @@
 							
 							cvLine(extension,
 									kneeMarkedAtExtension,
-									cvPoint(kneeCenterExtX, kneePointFront.y),
-									CV_RGB(128,128,128),1,1);
+									cvPoint(kneeCenterExtX, kneeCenterExtY),
+									WHITE,1,1);
 							
 							//hip
 							double hipMarkedX = hipMarkedAtExtension.x - kneeCenterExtX;
@@ -765,24 +859,7 @@
 									CV_RGB(128,128,128),1,1);
 							
 							cvShowImage("Extension Frame", extension);
-
-
-
-							/*
-							 * find at extension:
-							 * knee x
-							 * hip x
-							 * back x length
-							 */
-
-							/*
-							cvSetCaptureProperty( capture, CV_CAP_PROP_POS_FRAMES, 
-									framesCount - jumpBackToExtension );
-							getKneeAtExtension = true;
-							continue;
-							*/
 						} else {
-							printf("Denied\n");
 							foundAngle = false;
 							
 							if(option==FORWARD) {
@@ -791,6 +868,15 @@
 							} else if(option==SUPERFORWARD) {
 								forwardSuper = true;
 								printf("super forwarding ...\n");
+							} else if(option==BACKWARD) {
+								backward = true;
+
+								//try to go to previous (backwardspeed) frame
+								cvSetCaptureProperty( capture, CV_CAP_PROP_POS_FRAMES, 
+										framesCount - backwardSpeed -1 );
+									
+								printf("backwarding ...\n");
+								continue;
 							} else if(option==QUIT) {
 								shouldEnd = true;
 								printf("exiting ...\n");
@@ -913,19 +999,16 @@
 				 */
 				if(! foundAngleOneTime && ! extensionCopyDone) {
 					cvShowImage("result",frame_copy);
-					imageGuiAsk(gui, "Extension copy. Accept?", "'n', 'y', 'f', 'F', 'q'", font);
-					int option = optionAccept();
+					imageGuiAsk(gui, "Extension copy. Accept?", "'n'o, 'y'es, 'f'orward, super'F'orward, 'b'ackward, 'q'uit", font);
+					int option = optionAccept(false);
 					eraseGuiAsk(gui);
 
 					if(option==YES) {
 						cvCopy(frame_copy, extension);
 						
-						
 						//cvCopy(segmented, extensionSeg);
 						cvCopy(output, extensionSeg);
 
-
-
 						//cvCopy(segmentedValidationHoles, extensionSegHoles);
 						//printf("\nhere: x: %d, y: %d\n", kneeMarked.x, kneeMarked.y);
 						kneeMarkedAtExtension = kneeMarked;
@@ -937,14 +1020,21 @@
 						
 						extensionCopyDone = true;
 					} else {
-						printf("Denied\n");
-
 						if(option==FORWARD) {
 							forward = true;
 							printf("forwarding ...\n");
 						} else if(option==SUPERFORWARD) {
 							forwardSuper = true;
 							printf("super forwarding ...\n");
+						} else if(option==BACKWARD) {
+							backward = true;
+							
+							//try to go to previous (backwardspeed) frame
+							cvSetCaptureProperty( capture, CV_CAP_PROP_POS_FRAMES, 
+									framesCount - backwardSpeed -1 );
+							
+							printf("backwarding ...\n");
+							continue;
 						} else if(option==QUIT) {
 							shouldEnd = true;
 							printf("exiting ...\n");
@@ -952,125 +1042,11 @@
 					}
 				}
 			}
+				
+			cvShowImage("result",frame_copy);
 		}
 
 
-		/*
-		 * 5
-		 * PRINT MARKERS RELATED INFO AND DO CALCULATIONS LIKE ANGLE
-		 */
-
-
-		if(pointIsNull(hipMarked) || pointIsNull(kneeMarked) || pointIsNull(toeMarked))
-			thetaMarked = -1;
-		else {
-			thetaMarked = findAngle2D(hipMarked, toeMarked, kneeMarked);
-			if(thetaMarked < minThetaMarked) 
-				minThetaMarked = thetaMarked;
-
-
-			if(programMode == blackAndMarkers)
-				cvRectangle(frame_copy,
-						cvPoint(maxrect.x,maxrect.y),
-						cvPoint(maxrect.x + maxrect.width, maxrect.y + maxrect.height),
-						CV_RGB(255,0,0),1,1);
-
-
-			/*
-			//print frame variation of distances of leg
-			//soon find abduction, and then real flexion angle
-			*/
-			upLegMarkedDist = getDistance(hipMarked, kneeMarked);
-			if(upLegMarkedDist > upLegMarkedDistMax)
-				upLegMarkedDistMax = upLegMarkedDist;
-			downLegMarkedDist = getDistance(toeMarked, kneeMarked);
-			if(downLegMarkedDist > downLegMarkedDistMax)
-				downLegMarkedDistMax = downLegMarkedDist;
-
-			CvPoint HT;
-			HT.y = kneeMarked.y;
-			HT.x = hipMarked.x;
-			//double verticalKVersusHT = (kneeMarked.y - toeMarked.y) / (double) (hipMarked.y-toeMarked.y) ;
-			//HT.x = ((hipMarked.x - toeMarked.x) * verticalKVersusHT ) + toeMarked.x;
-
-			double kneeZetaSide = sqrt( pow(upLegMarkedDistMax,2) - pow(upLegMarkedDist,2) );
-			double htKneeMarked = getDistance (HT, kneeMarked);
-
-			double thetaABD = (180.0/M_PI)*atan( kneeZetaSide / (double) htKneeMarked );
-
-			double thetaRealFlex = findAngle3D(hipMarked, toeMarked, kneeMarked, 0, 0, -kneeZetaSide);
-			if(thetaRealFlex < minThetaRealFlex) 
-				minThetaRealFlex = thetaRealFlex;
-
-
-			if(programMode == skinOnlyMarkers) {
-				printOnScreen(output, font, CV_RGB(0,0,0), labelsAtLeft,
-						framesCount, threshold, 
-						(double) upLegMarkedDist *100 /upLegMarkedDistMax, 
-						(double) downLegMarkedDist *100 /downLegMarkedDistMax,
-						thetaMarked, minThetaMarked,
-						thetaABD, thetaRealFlex, minThetaRealFlex
-						);
-				cvShowImage("toClick", frame_copy);
-				cvShowImage("skinOutput",output);
-			}
-
-			printOnScreen(frame_copy, font, CV_RGB(255,255,255), labelsAtLeft,
-					framesCount, threshold, 
-					(double) upLegMarkedDist *100 /upLegMarkedDistMax, 
-					(double) downLegMarkedDist *100 /downLegMarkedDistMax,
-					thetaMarked, minThetaMarked,
-					thetaABD, thetaRealFlex, minThetaRealFlex
-					);
-
-			if(programMode == blackAndMarkers && foundAngle) {
-				/*
-				//print data
-				double thetaSup = findAngle2D(hipExpected, cvPoint(0,kneeExpected.y), kneeExpected);
-				double thetaMarkedSup = findAngle2D(hipMarked, cvPoint(0, kneeMarked.y), kneeMarked);
-
-				double thetaInf = findAngle2D(cvPoint(0,kneeExpected.y), toeExpected, kneeExpected);
-				double thetaMarkedInf = findAngle2D(cvPoint(0,kneeMarked.y), toeMarked, kneeMarked);
-
-				printf("%7d %7.2f %7.2f [%7.2f %7.2f] %7.2f %7.2f %7.2f [%7.2f %7.2f] [%7.2f] [%7.2f]\n", framesCount, thetaExpected, thetaMarked, 
-				thetaMarked-thetaExpected, relError(thetaExpected, thetaMarked), 
-				getDistance(kneeExpected, kneeMarked), 
-				thetaSup-thetaMarkedSup, thetaInf-thetaMarkedInf
-				, getDistance(kneeMarked, hipMarked), getDistance(kneeExpected, hipExpected)
-				, getDistance(kneeExpected, hipPointBack)
-				, getDistance(kneePointBack, hipPointBack)
-				);
-
-				avgThetaDiff += abs(thetaMarked-thetaExpected);
-				avgThetaDiffPercent += abs(relError(thetaExpected, thetaMarked));
-				avgKneeDistance += getDistance(kneePoint, kneeMarked);
-				*/
-				framesDetected ++;
-			}
-
-
-			if(programMode == blackAndMarkers || programMode == blackOnlyMarkers)
-				cvShowImage("result",frame_copy);
-
-
-			//Finds the minimum angle between Hip to Knee line and Knee to Toe line
-			if(thetaRealFlex == minThetaRealFlex) {
-				cvCopy(frame_copy,result);
-				lowestAngleFrame = framesCount;
-			}
-
-			//exit if we are going up and soon jumping.
-			//toe will be lost
-			//detected if minThetaMarked is littler than thetaMarked, when thetaMarked is big
-			if(thetaMarked > 140 && 
-					minThetaMarked +10 < thetaMarked &&
-					! jumpedFrames)
-			{
-				printf("\ntm: %f, mtm: %f, frame: %d\n", thetaMarked, minThetaMarked, framesCount);
-				shouldEnd = true;
-			}
-		}
-
 
 		/* 
 		 * 6
@@ -1087,9 +1063,11 @@
 			shouldEnd = true;
 		else if (key == '+')  
 			threshold += thresholdInc;
-		else if (key == '-') 
+		else if (key == '-') { 
 			threshold -= thresholdInc;
-		else if (key == 'l') 
+			if(threshold < 0)
+				threshold = 0;
+		} else if (key == 'l') 
 			labelsAtLeft = ! labelsAtLeft;
 		else if (key == 'r') { //reset legs length
 			upLegMarkedDistMax = 0;
@@ -1113,31 +1091,13 @@
 			
 			framesCount = jump;
 
-			//when jumper is extending legs after maximal flexion, jump ends
-			//this jumped makes it didn't work, avoiding ending a jump
-			//when we have gone ('j') from a maximal flexion to the 1st frame again (extension)
-			jumpedFrames = true;
-			
 			//hlps to know when we jumped and we have to initialize hipOld, kneeOld, toOld
 			jumping = true;
 			printf("jumping ...\n");
 		}
 		else if (key == 'p')
 		{
-			//if paused, print "pause"
-			/*
-			sprintf(label,"Pause");
-			if(programMode == skinOnlyMarkers) {
-				cvPutText(output, label,cvPoint(output->width-100, 25),&font,cvScalar(128,128,128));
-				cvShowImage("skinOutput",output);
-			} else {
-				cvPutText(frame_copy, label,cvPoint(frame_copy->width-100, 25),&font,cvScalar(0,0,255));
-				cvShowImage("result",frame_copy);
-			}
-			*/
-			//imagePrint(gui, "gui", cvPoint(gui->width-100, 25), "Pause", font, WHITE, true);
 			imageGuiAsk(gui, "Pause", "'p', '+', '-'", font);
-
 			bool done = false;
 			do{
 				key = (char) cvWaitKey(0);
@@ -1152,8 +1112,11 @@
 				else if(key =='+' || key == '-') {  
 					if(key =='+')  
 						threshold += thresholdInc;
-					else if(key =='-') 
+					else if(key =='-') {
 						threshold -= thresholdInc;
+						if(threshold < 0)
+							threshold = 0;
+					}
 		
 					if(programMode == skinOnlyMarkers) {
 						cvThreshold(gray, output, threshold, thresholdMax,CV_THRESH_BINARY_INV);
@@ -1166,12 +1129,16 @@
 						cvShowImage("skinOutput", output);
 					}
 					else {		
+						eraseGuiResult(gui);
 						cvThreshold(gray,segmentedValidationHoles, threshold, thresholdMax,CV_THRESH_BINARY_INV);
 						//create the largest contour image (stored on temp)
 						cvThreshold(gray,segmented,threshold,thresholdMax,CV_THRESH_BINARY_INV);
 						maxrect = findLargestContour(segmented, output, showContour);
 
 						updateHolesWin(segmentedValidationHoles);
+						
+						sprintf(label, "threshold: %d", threshold);
+						imageGuiResult(gui, label, font);
 					}
 				}
 
@@ -1195,42 +1162,6 @@
 		avgThetaDiff = (double) avgThetaDiff / framesDetected;
 		avgThetaDiffPercent = (double) avgThetaDiffPercent / framesDetected;
 		avgKneeDistance = (double) avgKneeDistance / framesDetected;
-
-		//printf("\n[%f %f] %f\n", avgThetaDiff, avgThetaDiffPercent, avgKneeDistance);
-
-		// do this on R
-		/*
-		if(showStickThePoints || 
-				showStickTheLinesBetweenDifferentPoints ||
-				showStickTheLinesBetweenSamePoints) {
-
-			//remove unfound points at end (useful to paint end point)
-			CvPoint hipLast = *CV_GET_SEQ_ELEM( CvPoint, hipSeq, hipSeq->total-1);
-			do {
-				if(pointIsNull(hipLast)) {
-					cvSeqPop( hipSeq );
-					cvSeqPop( kneeSeq );
-					cvSeqPop( toeSeq );
-				}
-
-				hipLast = *CV_GET_SEQ_ELEM( CvPoint, hipSeq, hipSeq->total-1);
-			} while(pointIsNull(hipLast) );
-
-			if(mixStickWithMinAngleWindow) {
-				paintStick(result, lowestAngleFrame, hipSeq, kneeSeq, toeSeq, 
-						showStickThePoints, showStickTheLinesBetweenDifferentPoints,
-						showStickTheLinesBetweenSamePoints, showStickOnlyStartMinEnd, font);
-				cvNamedWindow("Minimum Frame",1);
-				cvShowImage("Minimum Frame", result);
-			} else {
-				paintStick(resultStick, lowestAngleFrame, hipSeq, kneeSeq, toeSeq, 
-						showStickThePoints, showStickTheLinesBetweenDifferentPoints,
-						showStickTheLinesBetweenSamePoints, showStickOnlyStartMinEnd, font);
-				cvNamedWindow("Stick Figure",1);
-				cvShowImage("Stick Figure", resultStick);
-			}
-		}
-		*/
 			
 		cvNamedWindow("Minimum Frame",1);
 		cvShowImage("Minimum Frame", result);
@@ -1252,21 +1183,6 @@
 		cvWaitKey(0);
 	}
 
-	/* show all windows*/	
-	/*
-	   cvNamedWindow("gray",1);
-	   cvShowImage("gray", gray);
-	   cvNamedWindow("segmented",1);
-	   cvShowImage("segmented", segmented);
-	   cvNamedWindow("edge",1);
-	   cvShowImage("edge", edge);
-	   cvNamedWindow("temp",1);
-	   cvShowImage("temp", temp);
-	   cvNamedWindow("output",1);
-	   cvShowImage("output", output);
-	   */
-
-
 	cvClearMemStorage( stickStorage );
 
 	cvDestroyAllWindows();
@@ -1283,14 +1199,6 @@
 		cvReleaseImage(&resultStick);
 }
 
-/*
-void on_trackbar(int h)
-{
-printf("h: %d\n",h);
-}
-*/
-		
-
 int menu(IplImage * gui, CvFont font) 
 {
 	/* initial menu */
@@ -1298,16 +1206,16 @@
 	int row = 1;
 	int step = 16;
 	char *label = new char[150];
-	imagePrint(gui, "gui", cvPoint(10, step*row++), "Use:", font, WHITE);
-	imagePrint(gui, "gui", cvPoint(20, step*row++), "b - change mode to black long pants and marker validation", font, WHITE);
-	imagePrint(gui, "gui", cvPoint(20, step*row++), "B - change mode to Black long pants (only markers)", font, WHITE);
-	imagePrint(gui, "gui", cvPoint(20, step*row++), "s - change mode to Skin (short pants) (only markers)", font, WHITE);
-	//imagePrint(gui, "gui", cvPoint(20, step*row++), "j - Jump at selected frame", font, WHITE);
-	imagePrint(gui, "gui", cvPoint(20, step*row++), "i - Init the program", font, WHITE);
-	imagePrint(gui, "gui", cvPoint(20, step*row++), "q - quit program", font, WHITE);
+	imagePrint(gui, cvPoint(10, step*row++), "Use:", font, WHITE);
+	imagePrint(gui, cvPoint(20, step*row++), "b - change mode to black long pants and marker validation", font, WHITE);
+	imagePrint(gui, cvPoint(20, step*row++), "B - change mode to Black long pants (only markers)", font, WHITE);
+	imagePrint(gui, cvPoint(20, step*row++), "s - change mode to Skin (short pants) (only markers)", font, WHITE);
+	//imagePrint(gui, cvPoint(20, step*row++), "j - Jump at selected frame", font, WHITE);
+	imagePrint(gui, cvPoint(20, step*row++), "i - Init the program", font, WHITE);
+	imagePrint(gui, cvPoint(20, step*row++), "q - quit program", font, WHITE);
 		
 	row ++;
-	imagePrint(gui, "gui", cvPoint(10, step*row++), "Current option:", font, WHITE);
+	imagePrint(gui, cvPoint(10, step*row++), "Current option:", font, WHITE);
 	row ++;
 
 	int key;
@@ -1321,11 +1229,11 @@
 		cvRectangle(gui, cvPoint(10, step*(row-1)), cvPoint(gui->width, gui->height), CV_RGB(0,0,0),CV_FILLED,8,0);
 
 		if(programMode == blackAndMarkers)
-			imagePrint(gui, "gui", cvPoint(20, step*row++), "Black long pants and marker validation", font, WHITE);
+			imagePrint(gui, cvPoint(20, step*row++), "Black long pants and marker validation", font, WHITE);
 		else if(programMode == blackOnlyMarkers)
-			imagePrint(gui, "gui", cvPoint(20, step*row++), "Black long pants (only markers)", font, WHITE);
+			imagePrint(gui, cvPoint(20, step*row++), "Black long pants (only markers)", font, WHITE);
 		else
-			imagePrint(gui, "gui", cvPoint(20, step*row++), "Skin (short pants) (only markers)", font, WHITE);
+			imagePrint(gui, cvPoint(20, step*row++), "Skin (short pants) (only markers)", font, WHITE);
 
 		//sprintf(label, "start at frame: %d", startAt);
 		//imagePrint(gui, cvPoint(20, step*row++), label, font);

Modified: trunk/src/angle/kneeAngleFunctions.cpp
==============================================================================
--- trunk/src/angle/kneeAngleFunctions.cpp	(original)
+++ trunk/src/angle/kneeAngleFunctions.cpp	Sun Nov  9 13:57:49 2008
@@ -212,13 +212,13 @@
 	int maxx = 0;
 	int maxy = 0;
 	
-	//use to fount the lowest consecutive point (under the maxx, maxy)
+	//use to found 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++)
+	for(int y=starty; y<endy; y++)
 	{
 		uchar *srcdataptr = srcdata + y*img->width;
 		for(int x=0; x < kneePointFrontX; x++)
@@ -230,6 +230,30 @@
 					maxx = x;
 					maxy = y;
 					foundNow = true;
+					/*
+					 * TODO: improve this, 
+					 * check as a sample:
+					 * ~/Desktop/opencv_validacio_blanquerna/tarda/38_xxx_salt5_m.MOV 
+					 * or apply also in above:
+					 * else if(foundNow && x==maxx) 
+
+					//search for a hidden upperRight popliteo (flexion of 50Â aprox)
+					//going up
+					int xSearch = x;
+					int ySearch = y-1;
+					uchar *srcdataptr2 = srcdata + ySearch*img->width;
+					while (srcdataptr2[xSearch] == 0) { //while there's white space up
+						//found air, at right there must be pants
+						while(srcdataptr2[xSearch ++] == 0) {
+							if(xSearch > x) {
+								maxx = xSearch;
+								maxy = ySearch;
+							}
+						}
+						ySearch --;
+						srcdataptr2 = srcdata + ySearch*img->width;
+					}
+					*/
 				}
 				else if(foundNow && x==maxx) {
 					maxx2 = x;
@@ -241,6 +265,8 @@
 			}
 		}
 	}
+
+
 	pt.x = maxx;
 	if(maxy2 != -1 && maxx == maxx2)
 		pt.y = (maxy2+maxy)/2;
@@ -575,7 +601,7 @@
  * this function is realy similiar to findHoles
  * try to do only a function
  */
-CvSeq* findHolesSkin(IplImage *imgThresh, IplImage *imgColor, CvPoint hipOld, CvPoint kneeOld, CvPoint toeOld)
+CvSeq* findHolesSkin(IplImage *imgThresh, IplImage *imgColor, CvPoint hipOld, CvPoint kneeOld, CvPoint toeOld, CvFont font)
 {
 	CvPoint pt;
 	pt.x =0;pt.y=0;
@@ -594,7 +620,6 @@
 	CvSeq* seqPoints = cvCreateSeq( CV_SEQ_KIND_GENERIC|CV_32SC2, sizeof(CvSeq), sizeof(CvPoint), storage );
 	CvSeq* seqGroups = cvCreateSeq( 0, sizeof(CvSeq), sizeof(0), storage );
 
-//exit(0); //desp
 	//put all hole points on seqAllHoles
 	for(int y=0;y<endy;y++)
 	{
@@ -665,7 +690,7 @@
 	
 	CvSeq* seqIsValidSize = cvCreateSeq( 0, sizeof(CvSeq), sizeof(0), storage ); //'1' if is valid
 
-	int minSide = 6;
+	int minSide = 2;
 	int maxSize = 200;
 	int validValue = 1;
 	int nonValidValue = 0;
@@ -678,7 +703,7 @@
 				size >= minSide && //size is higher than minSide (obvious)
 				size <= maxSize	&& //size is lowerr than maxSize (obvious)
 		//		sp2.x-sp1.x > minSide && sp2.y-sp1.y > minSide && //every side is bigger or equal to minSide
-				! (sp2.x-sp1.x > 3*(sp2.y-sp1.y)) && ! (3*(sp2.x-sp1.x) < (sp2.y-sp1.y)) //a side is not 3 times bigger than other (helps to delete shoes if appear)
+				! (sp2.x-sp1.x > 4*(sp2.y-sp1.y)) && ! (4*(sp2.x-sp1.x) < (sp2.y-sp1.y)) //a side is not 4 times bigger than other (helps to delete shoes if appear)
 		  ) {
 			cvSeqPush( seqIsValidSize, &validValue);
 		} else {
@@ -710,6 +735,8 @@
 	CvPoint kneePoint;
 	CvPoint toePoint;
 	hipPoint.x=0; kneePoint.x=0; toePoint.x=0;
+	
+	char *labelShort = new char[2];
 
 	for( int i = 0; i < seqHolesSize->total; i++ ) 
 	{
@@ -734,18 +761,20 @@
 					if(hipPoint.x == 0) {
 						hipPoint.x = center.x; 
 						hipPoint.y = center.y;
-					color = CV_RGB(255, 0, 0 );
-
-					} else if(kneePoint.x == 0) {
+						color = CV_RGB(255, 0, 0 );
+						sprintf(labelShort,"H");
+					} 
+					else if(kneePoint.x == 0) {
 						kneePoint.x = center.x; 
 						kneePoint.y = center.y;
 						color = CV_RGB(0, 255, 0 );
-
-					} else {
+						sprintf(labelShort,"K");
+					} 
+					else {
 						toePoint.x = center.x; 
 						toePoint.y = center.y;
 						color = CV_RGB(0, 0, 255 );
-
+						sprintf(labelShort,"T");
 					}
 				}
 			}
@@ -757,18 +786,20 @@
 					hipPoint.x = center.x; 
 					hipPoint.y = center.y;
 					color = CV_RGB(255, 0, 0 );
-
-				} else if(pointInside(kneeOld, sp1,sp2)) {
+					sprintf(labelShort,"H");
+				} 
+				else if(pointInside(kneeOld, sp1,sp2)) {
 					kneePoint.x = center.x; 
 					kneePoint.y = center.y;
 					color = CV_RGB(0, 255, 0 );
-
-				} else if(pointInside(toeOld, sp1,sp2)) {
+					sprintf(labelShort,"K");
+				} 
+				else if(pointInside(toeOld, sp1,sp2)) {
 					toePoint.x = center.x; 
 					toePoint.y = center.y;
 					color = CV_RGB(0, 0, 255);
-
-				}else 
+					sprintf(labelShort,"T");
+				} else 
 					validSure = false;
 			}
 		}
@@ -781,7 +812,26 @@
 				cvPoint(sp1.x-1,sp1.y-1),
 				cvPoint(sp2.x+1, sp2.y+1),
 				color,1,1);
+		if(validSure)
+			imagePrint(imgColor, cvPoint(center.x + 20, center.y), labelShort, font, color);
+	}
+
+
+	/* maybe a point is missing, then this can happen:
+	 * (this happens when above:
+	 * 	(pointIsNull(hipOld) && pointIsNull(kneeOld) && pointIsNull(toeOld)) is not true
+	 * 	(er arenot jumping, or forwarding)
+	 * if real hip is missing , then hipPoint is assigned to real knee, and kneePoint is assigned to realToe
+	 * if real knee is missing , then hip is ok, and kneePoint is assigned to realToe
+	 * if real toe is missing, all is ok
+	 * if real hip and real knee are missing, hipPoint is assigned to real toe
+	 */
+	/*
+	if(hipPoint.x == 0 || kneePoint.x == 0 || toePoint.x == 0) {
+		if(
 	}
+	*/
+
 
 	if(kneePoint.x > 0) {
 		if(hipPoint.x > 0) {
@@ -879,9 +929,6 @@
 //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
@@ -894,16 +941,11 @@
 		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;
 }
@@ -1169,8 +1211,6 @@
 	return thresholdStart;
 }
 
-double zoomScale = 2;
-
 IplImage * zoomImage(IplImage *img) {
 	IplImage* imgZoom = cvCreateImage( cvSize( cvRound (img->width*zoomScale), 
 				cvRound (img->height*zoomScale)), 8, 3 );
@@ -1178,18 +1218,6 @@
 	return imgZoom;
 }
 
-CvPoint hipMouse;
-CvPoint kneeMouse;
-CvPoint toeMouse;
-
-bool forceMouseHip = false;
-bool forceMouseKnee = false;
-bool forceMouseToe = false;
-
-bool zoomed = false;
-
-bool mouseCanMark = false;
-
 void on_mouse( int event, int x, int y, int flags, void* param )
 {
 	if(! mouseCanMark)
@@ -1207,35 +1235,17 @@
 				{
 					hipMouse = cvPoint(x,y);
 					forceMouseHip = false;
-					printf("H x:%d, y:%d\n", x, y);
 				} 
 				else if(forceMouseKnee) 
 				{
 					kneeMouse = cvPoint(x,y);
 					forceMouseKnee = false;
-					printf("K x:%d, y:%d\n", x, y);
 				} 
 				else if(forceMouseToe) 
 				{
 					toeMouse = cvPoint(x,y);
 					forceMouseToe = false;
-					printf("T x:%d, y:%d\n", x, y);
 				} 
-				else if(hipMouse.x == 0)
-				{
-					hipMouse = cvPoint(x,y);
-					printf("H x:%d, y:%d\n", x, y);
-				}
-				else if(kneeMouse.x == 0)
-				{
-					kneeMouse = cvPoint(x,y);
-					printf("K x:%d, y:%d\n", x, y);
-				}
-				else 
-				{
-					toeMouse = cvPoint(x,y);
-					printf("T x:%d, y:%d\n", x, y);
-				}
 			}
 			break;
 	}

Added: trunk/src/angle/kneeAngleGlobal.cpp
==============================================================================
--- (empty file)
+++ trunk/src/angle/kneeAngleGlobal.cpp	Sun Nov  9 13:57:49 2008
@@ -0,0 +1,86 @@
+/*
+ * This file is part of ChronoJump
+ *
+ * ChronoJump is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or   
+ *    (at your option) any later version.
+ *    
+ * ChronoJump is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
+ *    GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Initally coded by (v.1.0):
+ * Sharad Shankar & Onkar Nath Mishra
+ * http://www.logicbrick.com/
+ * 
+ * Updated by:
+ * Xavier de Blas 
+ * xaviblas gmail com
+ *
+ *
+ */
+
+//config variables
+bool showContour = true;
+bool debug = false;
+int playDelay = 10; //milliseconds between photogrammes wen playing. Used as a waitkey.
+//not put values lower than 5 or the enter when executing will be the first pause
+//eg: 5 (fast) 1000 (one second each photogramme)
+//int playDelayFoundAngle = 150; //as above, but used when angle is found.
+int playDelayFoundAngle = 50; //as above, but used when angle is found.
+//Useful to see better the detected angle when something is detected
+//recommended values: 50 - 200
+
+
+
+/* recommended:
+	   showAtLinesPoints = true
+	   ...DiffPoints = true
+	   ...SamePoints = true
+	   ...OnlyStartMinEnd = true;
+	   */
+
+bool showStickThePoints = true;
+bool showStickTheLinesBetweenSamePoints = true;
+bool showStickTheLinesBetweenDifferentPoints = true;
+bool showStickOnlyStartMinEnd = true;
+bool mixStickWithMinAngleWindow = true;
+
+int startAt = 1;
+
+
+CvScalar WHITE = CV_RGB(255,255,255);
+CvScalar BLACK = CV_RGB(0 ,0 , 0);
+CvScalar RED = CV_RGB(255, 0, 0);
+CvScalar GREEN = CV_RGB(0 ,255, 0);
+CvScalar BLUE = CV_RGB(0 ,0 ,255);
+CvScalar GREY = CV_RGB(128,128,128);
+CvScalar YELLOW = CV_RGB(255,255, 0);
+CvScalar MAGENTA = CV_RGB(255, 0,255);
+CvScalar CYAN = CV_RGB( 0,255,255); //check
+
+enum { blackAndMarkers = 0, blackOnlyMarkers = 1, skinOnlyMarkers = 2 }; 
+enum { SMALL = 1, MID = 2, BIG = 3 }; 
+enum { NO = 0, YES = 1, FORWARD = 2, SUPERFORWARD = 3, BACKWARD = 4, QUIT = 5 }; 
+
+double zoomScale = 2; 
+
+CvPoint hipMouse;
+CvPoint kneeMouse;
+CvPoint toeMouse;
+
+bool forceMouseHip = false;
+bool forceMouseKnee = false;
+bool forceMouseToe = false;
+
+bool zoomed = false;
+
+bool mouseCanMark = false; 
+
+

Modified: trunk/src/angle/kneeAngleUtil.cpp
==============================================================================
--- trunk/src/angle/kneeAngleUtil.cpp	(original)
+++ trunk/src/angle/kneeAngleUtil.cpp	Sun Nov  9 13:57:49 2008
@@ -41,19 +41,6 @@
 using namespace std;
 
 
-CvScalar WHITE = 	CV_RGB(255,255,255);
-CvScalar BLACK = 	CV_RGB(0  ,0  ,  0);
-CvScalar RED =		CV_RGB(255,  0,  0);
-CvScalar GREEN = 	CV_RGB(0  ,255,  0);
-CvScalar BLUE = 	CV_RGB(0  ,0  ,255);
-CvScalar GREY = 	CV_RGB(128,128,128);
-CvScalar YELLOW = 	CV_RGB(255,255,  0);
-CvScalar MAGENTA = 	CV_RGB(255,  0,255);
-CvScalar CYAN = 	CV_RGB(  0,255,255); //check
-
-enum { SMALL = 1, MID = 2, BIG = 3 };
-
-
 CvPoint findMiddle(CvPoint pt1, CvPoint pt2)
 {
 	return cvPoint((pt1.x+pt2.x)/2, (pt1.y+pt2.y)/2);
@@ -249,6 +236,14 @@
 	return false;
 }
 
+bool pointIsEqual(CvPoint pt1, CvPoint pt2 ) {
+	if(pt1.x == pt2.x && pt1.y == pt2.y)
+		return true;
+	else
+		return false;
+}
+
+
 double findAngle2D(CvPoint p1, CvPoint p2, CvPoint pa) //pa is the point at the angle
 {
 	CvPoint d1, d2;
@@ -336,13 +331,17 @@
 	return point;
 }
 
-enum { NO = 0, YES = 1, FORWARD = 2, SUPERFORWARD = 3, QUIT = 4 };
-
-int optionAccept() {
+int optionAccept(bool onlyYesNo) {
 	int key;
-	do {
-		key = (char) cvWaitKey(0);
-	} while(key != 'n' && key != 'y' && key != 'f' && key != 'F' && key != 'q');
+	if(onlyYesNo) {
+		do {
+			key = (char) cvWaitKey(0);
+		} while(key != 'n' && key != 'y');
+	} else {
+		do {
+			key = (char) cvWaitKey(0);
+		} while(key != 'n' && key != 'y' && key != 'f' && key != 'F' && key != 'b' && key != 'q');
+	}
 
 	if(key == 'n') 
 		return NO;
@@ -352,23 +351,35 @@
 		return FORWARD;
 	else if(key == 'F') 
 		return SUPERFORWARD;
+	else if(key == 'b') 
+		return BACKWARD;
 	else if(key == 'q') 
 		return QUIT;
 }
 
-void imagePrint(IplImage *img, const char * imgName, CvPoint point, const char *label, CvFont font, CvScalar color) {
+void imagePrint(IplImage *img, CvPoint point, const char *label, CvFont font, CvScalar color) {
 	cvPutText(img, label, point, &font, color);
 }
 
 void imageGuiAsk(IplImage *gui, const char *labelQuestion, const char * labelOptions, CvFont font) {
-	imagePrint(gui, "gui", cvPoint(25, gui->height-40), labelQuestion, font, WHITE);
-	imagePrint(gui, "gui", cvPoint(25, gui->height-20), labelOptions, font, WHITE);
-	
+	imagePrint(gui, cvPoint(25, gui->height-60), labelQuestion, font, WHITE);
+	imagePrint(gui, cvPoint(25, gui->height-40), labelOptions, font, WHITE);
+	cvShowImage("gui", gui);
+}
+
+void imageGuiResult(IplImage *gui, const char *label, CvFont font) {
+	imagePrint(gui, cvPoint((gui->width)/2 +10, gui->height-20), label, font, MAGENTA);
+	cvShowImage("gui", gui);
+}
+
+
+void eraseGuiResult(IplImage * gui) {
+	cvRectangle(gui, cvPoint((gui->width)/2, gui->height-30), cvPoint(gui->width, gui->height), CV_RGB(0,0,0),CV_FILLED,8,0);
 	cvShowImage("gui", gui);
 }
 
 void eraseGuiAsk(IplImage * gui) {
-	cvRectangle(gui, cvPoint(0, gui->height-50), cvPoint(gui->width, gui->height), CV_RGB(0,0,0),CV_FILLED,8,0);
+	cvRectangle(gui, cvPoint(0, gui->height-70), cvPoint(gui->width, gui->height), CV_RGB(0,0,0),CV_FILLED,8,0);
 	cvShowImage("gui", gui);
 }
 



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