[chronojump] kneeAngle: a point is hip, knee or toe depending on distance between old



commit 12aad21b52e8204c73e066beae78a9aae39585cb
Author: Xavier de Blas <xaviblas gmail com>
Date:   Mon Mar 29 20:37:37 2010 +0800

    kneeAngle: a point is hip, knee or toe depending on distance between old

 src/angle/kneeAngle.cpp               |   19 ++++++++--
 src/angle/kneeAngleFunctions.cpp      |   61 ++++++++++++++++++++++++++++++---
 src/angle/kneeAngleGlobal.cpp         |    2 +-
 src/angle/kneeAngle_black_contour.png |  Bin 45421 -> 45734 bytes
 src/angle/kneeAngle_black_contour.svg |    6 ++--
 5 files changed, 75 insertions(+), 13 deletions(-)
---
diff --git a/src/angle/kneeAngle.cpp b/src/angle/kneeAngle.cpp
index cee8322..fb1507d 100644
--- a/src/angle/kneeAngle.cpp
+++ b/src/angle/kneeAngle.cpp
@@ -436,6 +436,7 @@ int main(int argc,char **argv)
 				eraseGuiResult(gui, true);
 				sprintf(label, "frame: %d... (%d%%)", framesCount, 100*framesCount/startAt);
 				imageGuiResult(gui, label, font);
+				printf("%s\n", label);
 				cvWaitKey(25); //to allow gui image be shown
 				framesCountShowMessage = 0;
 			}
@@ -604,7 +605,17 @@ int main(int argc,char **argv)
 					usingContour = false;
 					gui = cvLoadImage("kneeAngle_black.png");
 					cvCopy(frame_copyTemp,frame_copy);
+
+//testing stuff
+cvShowImage("threshold",output);
+//cvShowImage("toClick", frame_copy);
+imageGuiResult(gui, "going", font);
+//printf("threshold :%d\n", threshold);
+//printf("thresholdLC :%d\n", thresholdLargestContour);
+//cvWaitKey(500); //to allow messages be shown
 					seqHolesEnd = findHolesSkin(output, frame_copy, hipMarked, kneeMarked, toeMarked, font);
+imageGuiResult(gui, "returned", font);
+//cvWaitKey(500); //to allow gui image be shown
 				}
 			}
 			cvShowImage("threshold", output);
@@ -1316,9 +1327,9 @@ int main(int argc,char **argv)
 			//if a threshold button is pushed, force a pause
 			forcePause = true;
 		}
-		else if(key == 'm') {
+		else if(key == 'v') {
 			forcePause = true;
-			mouseClicked = MINIMUMFRAMESHOW;
+			mouseClicked = MINIMUMFRAMEVIEW;
 		}
 		else if(key == 'd') {
 			forcePause = true;
@@ -1388,7 +1399,7 @@ int main(int argc,char **argv)
 					done = true;
 				}
 				
-				else if(mouseClicked == MINIMUMFRAMESHOW || key == 'm') {
+				else if(mouseClicked == MINIMUMFRAMEVIEW || key == 'v') {
 					cvShowImage("Minimum Frame", result);
 					imageGuiResult(gui, "Shown minimum frame. Paused.", font);
 				}
@@ -1542,7 +1553,7 @@ int main(int argc,char **argv)
 					cvThreshold(gray,segmented,thresholdLargestContour,thresholdMax,CV_THRESH_BINARY_INV);
 
 					maxrect = findLargestContour(segmented, outputTemp, showContour);
-					frame_copyTemp = cvCreateImage( cvSize(frame->width,frame->height),IPL_DEPTH_8U, frame->nChannels );
+					//frame_copyTemp = cvCreateImage( cvSize(frame->width,frame->height),IPL_DEPTH_8U, frame->nChannels );
 					findHoles(
 							outputTemp, segmented, foundHoles, frame_copyTemp,  
 							maxrect, hipOld, kneeOld, toeOld, font);
diff --git a/src/angle/kneeAngleFunctions.cpp b/src/angle/kneeAngleFunctions.cpp
index 39ccca2..ab09fa5 100644
--- a/src/angle/kneeAngleFunctions.cpp
+++ b/src/angle/kneeAngleFunctions.cpp
@@ -526,7 +526,43 @@ CvSeq* findHoles(IplImage *imgC, IplImage *imgH, IplImage *foundHoles, IplImage
 
 		if(validSure) {
 			CvPoint center = *CV_GET_SEQ_ELEM( CvPoint, seqHolesCenter, i ); 
-			if(hipPoint.x == 0) {
+
+			//the point will be hip knee or toe depending on the distance betwee old hipe, knee & toe
+			//but give preference to the top (<=) because will be the first to be found (top to bottom)
+			int pointIs = TOGGLENOTHING;
+			if(!pointIsNull(hipOld) && !pointIsNull(kneeOld) && !pointIsNull(toeOld)) {
+				int hipDist = getDistance(center, hipOld);
+				int kneeDist = getDistance(center, kneeOld);
+				int toeDist = getDistance(center, toeOld);
+				if(hipPoint.x == 0) {
+					if(hipDist <= kneeDist) {
+						if(hipDist <= toeDist)
+							pointIs = TOGGLEHIP;
+						else
+							pointIs = TOGGLETOE;
+					} else {
+						if(kneeDist <= toeDist)
+							pointIs = TOGGLEKNEE;
+						else
+							pointIs = TOGGLETOE;
+					}
+				} else if(kneePoint.x == 0) {
+					if(kneeDist <= toeDist)
+						pointIs = TOGGLEKNEE;
+					else
+						pointIs = TOGGLETOE;
+				} else if(toePoint.x == 0) 
+					pointIs = TOGGLETOE;
+			} else {
+				if(hipPoint.x == 0)
+					pointIs = TOGGLEHIP;
+				else if(kneePoint.x == 0) 
+					pointIs = TOGGLEKNEE;
+				else // if(toePoint.x == 0) 
+					pointIs = TOGGLETOE;
+			}
+
+			if(pointIs == TOGGLEHIP) {
 				color = RED; 
 				cvRectangle(imgMain, 
 						cvPoint(sp1.x-1,sp1.y-1),
@@ -535,7 +571,7 @@ CvSeq* findHoles(IplImage *imgC, IplImage *imgH, IplImage *foundHoles, IplImage
 				hipPoint.x = center.x; hipPoint.y = center.y;
 				sprintf(labelShort,"H");
 			} 
-			else if(kneePoint.x == 0) {
+			else if(pointIs == TOGGLEKNEE) {
 				color = GREEN; 
 				cvRectangle(imgMain, 
 						cvPoint(sp1.x-1,sp1.y-1),
@@ -617,6 +653,7 @@ CvSeq* findHolesSkin(IplImage *imgThresh, IplImage *imgColor, CvPoint hipOld, Cv
 	CvSeq* seqPoints = cvCreateSeq( CV_SEQ_KIND_GENERIC|CV_32SC2, sizeof(CvSeq), sizeof(CvPoint), storage );
 	CvSeq* seqGroups = cvCreateSeq( 0, sizeof(CvSeq), sizeof(0), storage );
 
+	//printf("entering bucle");
 	
 	//put all hole points on seqAllHoles
 	for(int y=0;y<endy;y++)
@@ -634,6 +671,21 @@ CvSeq* findHolesSkin(IplImage *imgThresh, IplImage *imgColor, CvPoint hipOld, Cv
 		}
 	}
 
+	//printf("points: %d", seqPoints->total);
+	//cvWaitKey(500); //to allow points num to be shown
+	CvSeq* seqHolesEnd = cvCreateSeq( CV_SEQ_KIND_GENERIC|CV_32SC2, sizeof(CvSeq), sizeof(CvPoint), storage );
+	
+	if(seqPoints->total > 50000) {
+		CvPoint ptNull;
+		ptNull.x = 0;
+		ptNull.y = 0;
+		cvSeqPush( seqHolesEnd, &ptNull );
+		cvSeqPush( seqHolesEnd, &ptNull );
+		cvSeqPush( seqHolesEnd, &ptNull );
+		return seqHolesEnd;
+	}
+
+
 	//assign each point to a group (a hole)
 	for( int i = 0; i < seqPoints->total; i++ ) {
 		CvPoint pt = *CV_GET_SEQ_ELEM( CvPoint, seqPoints, i ); 
@@ -650,7 +702,6 @@ CvSeq* findHolesSkin(IplImage *imgThresh, IplImage *imgColor, CvPoint hipOld, Cv
 	CvSeq* seqHolesSize = cvCreateSeq( 0, sizeof(CvSeq), sizeof(0), storage );
 	
 
-
 	for( int i = 0; i <= getMaxValue(seqGroups); i++ ) {
 		int maxX = -1;
 		int minX = 10000;
@@ -844,7 +895,7 @@ CvSeq* findHolesSkin(IplImage *imgThresh, IplImage *imgColor, CvPoint hipOld, Cv
 	CvPoint notFoundPoint;
 	notFoundPoint.x = 0; notFoundPoint.y = 0;
 
-	CvSeq* seqHolesEnd = cvCreateSeq( CV_SEQ_KIND_GENERIC|CV_32SC2, sizeof(CvSeq), sizeof(CvPoint), storage );
+//	CvSeq* seqHolesEnd = cvCreateSeq( CV_SEQ_KIND_GENERIC|CV_32SC2, sizeof(CvSeq), sizeof(CvPoint), storage );
 
 	if(hipPoint.x > 0) 
 		cvSeqPush( seqHolesEnd, &hipPoint );
@@ -1197,7 +1248,7 @@ int calculateThresholdStart(IplImage * gray, bool pantsOrPoints)
 	int thresMin = 10;
 	if(!pantsOrPoints) { //threshold for points
 		thresMax = 190;
-		thresMin = 85;
+		thresMin = 100;
 	}
 
 	if(brightness >= briMax) 
diff --git a/src/angle/kneeAngleGlobal.cpp b/src/angle/kneeAngleGlobal.cpp
index 0c6178d..12073e6 100644
--- a/src/angle/kneeAngleGlobal.cpp
+++ b/src/angle/kneeAngleGlobal.cpp
@@ -101,7 +101,7 @@ enum {
 	STOEMORE = 25, STOELESS = 26,
 	TCONTOURMORE = 27, TCONTOURLESS = 28,
 	BACKTOCONTOUR = 29,
-	MINIMUMFRAMESHOW = 30, MINIMUMFRAMEDELETE = 31
+	MINIMUMFRAMEVIEW = 30, MINIMUMFRAMEDELETE = 31
 }; 
 
 enum { TOGGLENOTHING = -1, TOGGLEHIP = 0, TOGGLEKNEE = 1, TOGGLETOE = 2};
diff --git a/src/angle/kneeAngle_black_contour.png b/src/angle/kneeAngle_black_contour.png
index f540d0d..a9218f6 100644
Binary files a/src/angle/kneeAngle_black_contour.png and b/src/angle/kneeAngle_black_contour.png differ
diff --git a/src/angle/kneeAngle_black_contour.svg b/src/angle/kneeAngle_black_contour.svg
index 8e2464f..7b8bc29 100644
--- a/src/angle/kneeAngle_black_contour.svg
+++ b/src/angle/kneeAngle_black_contour.svg
@@ -4752,7 +4752,7 @@
      inkscape:pageshadow="2"
      inkscape:zoom="1.3066933"
      inkscape:cx="250.99475"
-     inkscape:cy="147.78232"
+     inkscape:cy="146.63438"
      inkscape:document-units="px"
      inkscape:current-layer="capa1"
      showgrid="false"
@@ -4829,7 +4829,7 @@
         <dc:format>image/svg+xml</dc:format>
         <dc:type
            rdf:resource="http://purl.org/dc/dcmitype/StillImage"; />
-        <dc:title />
+        <dc:title></dc:title>
       </cc:Work>
     </rdf:RDF>
   </metadata>
@@ -5736,7 +5736,7 @@
          x="153.44901"
          y="184.78506"
          id="tspan3718-2"
-         style="font-size:12px;font-family:FreeMono;-inkscape-font-specification:FreeMono">m: See Minimum angle stored</tspan><tspan
+         style="font-size:12px;font-family:FreeMono;-inkscape-font-specification:FreeMono">v: View updated minimum angle</tspan><tspan
          sodipodi:role="line"
          x="153.44901"
          y="199.78506"



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