From 194f4c9d2c9d91daa7343fa48260fe22388944ac Mon Sep 17 00:00:00 2001 From: mutantturkey Date: Thu, 26 Jul 2012 14:16:52 -0400 Subject: created a new logging system --- fly-tools/FlyTrackingMain.cpp | 490 ++++++++++++++++++++---------------------- 1 file changed, 238 insertions(+), 252 deletions(-) diff --git a/fly-tools/FlyTrackingMain.cpp b/fly-tools/FlyTrackingMain.cpp index 4a33178..75098a8 100644 --- a/fly-tools/FlyTrackingMain.cpp +++ b/fly-tools/FlyTrackingMain.cpp @@ -21,23 +21,14 @@ using namespace Magick; using namespace std; +ofstream nullLog; +ostream* output; + const double PI = atan(1.0)*4.0; const double FACTOR_EIGEN = 100; const int STUCKING_TO_A_SINGLE_BLOB = 1; const int SEPARATING_FROM_SINGLE_BLOB = 2; - -typedef void (*loggerfunc) (const string&); - -void logOn(const string& toprint){ - cout << toprint << endl; -} - -void logOff(const string& toprint){ -} - -loggerfunc vlog = NULL; - Image* residual; vector fOVector; @@ -134,10 +125,11 @@ void bubbleSort(vector & fov) { void writeHist(const char* filename, map dataMap) { - vlog("In the beginning of the write hist\n"); - vlog("dataMap size "+ dataMap.size()); + *output << "In the beginning of the write hist" << endl; + *output << "dataMap size " << dataMap.size() << endl; + if (dataMap.size() == 0) { - vlog("Empty histogram"); + *output << "Empty histogram" << endl; ofstream fout(filename); fout <<"No entry in the histogram and size is " << dataMap.size() << endl; fout.close(); @@ -151,11 +143,11 @@ void writeHist(const char* filename, map dataMap) unsigned int first = front->first, last = back->first; - cout << "Min: " << first << endl<< "Max: " << last << endl<< "Count: " << last-first << endl; + *output << "Min: " << first << " " << "Max: " << last << " " << "Count: " << last-first << endl; //vector hist(last-first, 0); vector hist(last+1, 0); - cout << "hist size: " << hist.size() << endl; +// *output << "hist size: " << hist.size() << endl; try{ for(unsigned int j = 0; j cLREV(-cLEV.first, -cLEV.second); //double largerDotProdPrevHeadAndCLREV = calculateDotProduct(pLH, clREV); if (largerDotProdPrevHeadAndCLEV >=0) { - cout << "Current eigen is in direction with the historical head"<= 0) { - cout<<"Larger Dot prod is positive"< cSREV(-cSEV.first, -cSEV.second); if (smallerDotProdPrevHeadAndCSEV >=0) { - cout << "Current eigen is in direction with the historical head for the smaller fly object"<= 0) { - cout << "Smaller dot product is positive"< tempFIFOVector = tempFI.getFOVector(); // FlyObject tempFILFO = tempFIFOVector[0]; // FlyObject tempFISFO = tempFIFOVector[1]; // pair tempFILFOVV = tempFILFO.getVelocityV(); -// cout << "Large object velocity vector "< tempFISFOVV = tempFISFO.getVelocityV(); -// cout << "Small object velocity vector "< t(x,y); bresenhamLine.push_back(t); } @@ -687,28 +677,28 @@ int draw_line_bm(Image* maskImage, int x0, int y0, int x1, int y1) { int octant = -1; if (( m >= 0 and m <= 1) and x0 < x1 ) { - cout << "Octant 1"< 1) and (y0 < y1)) { - cout << "Octant 2"<= -1) and (x0 > x1)) { - cout << "Octant 4"< 0 and m <=1) and (x0 > x1) ) { - cout << "Octant 5"< 1) and (y0 > y1) ) { - cout << "Octant 6"< y1) ) { - cout << "Octant 7"<= -1) and (x0 < x1) ) { - cout << "Octant 8"<>fileName; - //inputFileName = "output/identified/"+fileName; + //inputFileName = "*output/identified/"+fileName; FrameInfo prevFI = fIVector[startIndex]; - cout << "Extracting information for image "<< fnVector[startIndex] << endl; - cout << "----------------------------------------\n"; - cout<>fileName; fileName = fnVector[i]; - // inputFileName = "output/identified/"+fileName; + // inputFileName = "*output/identified/"+fileName; drawTheFlyObject(nextFI, fileName, isFirst, singleBlob, unprocessed); } @@ -1055,7 +1043,7 @@ void objectHeadDirection(FlyObject prevFO, FlyObject ¤tFO) { double dotProdEVAndHH = calculateDotProduct(cFOEV, pFHH); if (dotProdEVAndHH > 0 ) { - cout << "Current head is in direction with the Previous frame Head(which is the historical head from the maxDistIndex)"< newHead(newHeadX, newHeadY); @@ -1063,7 +1051,7 @@ void objectHeadDirection(FlyObject prevFO, FlyObject ¤tFO) { currentFO.setHeadIsInDirectionMAEV(true); } else { - cout << "Current head is in direction with the previous frame head"< newHead(newHeadX, newHeadY); @@ -1094,7 +1082,7 @@ void objectHeadDirection(FlyObject prevFO, FlyObject ¤tFO, bool prevFFOHD) double dotProdEVAndHD = calculateDotProduct(cFOEV, pFHeadDir); if (dotProdEVAndHD > 0 ) { - cout << "Current head is in direction with the Previous frame Head direction"< newHead(newHeadX, newHeadY); @@ -1105,7 +1093,7 @@ void objectHeadDirection(FlyObject prevFO, FlyObject ¤tFO, bool prevFFOHD) currentFO.setHeadIsInDirectionMAEV(true); } else { - cout << "Current head is in reverse direction with the previous frame head direction"< newHead(newHeadX, newHeadY); @@ -1136,29 +1124,29 @@ void objectHeadDirection(FlyObject ¤tFO, int saveEV=0) { double dotProdVVAndEV = calculateDotProduct(cFOEV, cFOVV); if (dotProdVVAndEV > 0 ) { - cout << "Current head is in direction with the velocity vector\n"; + *output << "Current head is in direction with the velocity vector\n"; // set the head to the eigen vector currentFO.setHead(cFOEV); currentFO.setHeadIsInDirectionMAEV(true); if (saveEV == 1) { - cout << "saving the eigen vector for the first object"< zero(0.0,0.0); if (saveEV == 1) { - cout << "saving the zero eigen vector for the first object"< cFV) { double dotProdVVAndEV = calculateDotProduct(cFOEV, cFV); if (dotProdVVAndEV > 0 ) { - cout << "Current head is in direction with the vector used\n"; + *output << "Current head is in direction with the vector used\n"; // set the head to the eigen vector currentFO.setHead(cFOEV); currentFO.setHeadIsInDirectionMAEV(true); } else { - cout << "Current head is in reverse direction with the vector used"< cFV) { void velocityDirection(int st, int end, pair &velDirectionF, pair&velDirectionS) { // find the average velocity vector - cout << "Finding average velocity vector from "< pFOVector = prevFI.getFOVector(); FlyObject pFFirstFO = pFOVector[0]; @@ -1232,9 +1220,9 @@ void velocityDirection(int st, int end, pair &velDirectionF, pa int velXSecond = cFSCentroid.first - pFSCentroid.first; int velYSecond = cFSCentroid.second - pFSCentroid.second; - cout << "Velocity vector"< cFVV(static_cast (velXFirst), static_cast (velYFirst)); pair cSVV(static_cast (velXSecond), static_cast (velYSecond)); @@ -1255,17 +1243,16 @@ double getSpeed(pair vector) { } - void velocityDirections(int stIndex, int endIndex) { velocityDirectionsF.clear(); velocityDirectionsS.clear(); - + int i = 0; //int intervalLength = 5; - cout << "Initial velocity direction calculation"< velDirectionF; pair velDirectionS; @@ -1298,20 +1285,20 @@ void velocityDirections(int stIndex, int endIndex) { normalizeVector(velDirectionS); velocityDirectionsS.push_back(velDirectionS); - cout << "Normalized velocity"< > veloci st = j; positiveVelSeqSize++; flag = true; - //cout << "In first if positiveSize "< 0 && flag == true) { positiveVelSeqSize++; - //cout << "In second if positive "< > veloci maxSeqSize = positiveVelSeqSize; startIndex = st; endIndex = st+positiveVelSeqSize; - //cout << "maxseq updated \npositiveSize "< > veloci } if (zero != true) { - cout << "All directions zero"< > veloci void propagateDirections(int object, int s, int e, int origStart, int origEnd) { if (object == 1) { - cout << "For first"< cFOVector = currentFI.getFOVector(); FlyObject cFFO = cFOVector[object-1]; pair cFVV = cFFO.getVelocityV(); - //cout << "Velocity before normalization "< cFEV = cFFO.getMajorAxisEV(); - cout << "Eigen vector before normalization "< maxVelValue) { maxVelValue = velValue; maxVelValIndex = i; @@ -1447,7 +1434,7 @@ void propagateDirections(int object, int s, int e, int origStart, int origEnd) { } - cout << "Maximum speed is chosen for for frame "< cFOVector = currentFI.getFOVector(); FlyObject cFFirstFO = cFOVector[0]; FlyObject cFSecondFO = cFOVector[1]; - cout << "Setting representative head direction of frame "< tempVelocity = cFSecondFO.getVelocityV(); - //cout << "Velocity was "< intervalLength) { - cout << "Propagating in the longest positive frame interval starting the direction from the frame "< pFOVector = prevFI.getFOVector(); FlyObject pFFirstFO = pFOVector[0]; @@ -1504,21 +1491,21 @@ void propagateDirections(int object, int s, int e, int origStart, int origEnd) { FlyObject cFSecondFO = cFOVector[1]; if (object == 1) { - //cout << "First object extract"< tempVelocity = cFSecondFO.getVelocityV(); - //cout << "Velocity was "< origStart ) { - cout << "Propagating down wards from "<=origStart; i--) { FrameInfo currentFI = fIVector[i]; vector cFOVector = currentFI.getFOVector(); @@ -1626,17 +1613,17 @@ void propagateDirections(int object, int s, int e, int origStart, int origEnd) { FlyObject cFSecondFO = cFOVector[1]; if (object == 1) { - //cout << "First object extract"< z = velocityDirectionsF[a]; pair zEV = evDirectionF[a]; - cout <<" First object velocity = "< w = velocityDirectionsS[a]; pair wEV = evDirectionS[a]; - cout << "Second object velocity = "< aCentroid = a.getCentroid(); pair bCentroid = b.getCentroid(); - //cout << "Distance from "< (aCentroid.first)-static_cast (bCentroid.first)), 2.0); double y2 = pow((static_cast (aCentroid.second)-static_cast (bCentroid.second)), 2.0); double dist = sqrt((x2+y2)); - cout << dist< maxDist) { maxDist = currDist; maxDistIndex = i; - cout << "New max distance" << maxDist << " at the frame number "<=startOfATrackSequence; i--) { @@ -1820,13 +1807,13 @@ void processASequence(int startOfATrackSequence, int endOfATrackSequence) { prevFI = currentFI; } - cout << "Assigning object correspondance between maxDistIndex+1 "<<(maxDistIndex+1)<<" to endIndex "< sequenceSecondAverage) { foutLPS << "First object is the female and avg size is "< sequenceSecondAverage) { - cout << "First sequence is the object A"<columns(),height = img->rows(); diagLength= static_cast ( sqrt( (height*height) + (width*width) ) ); - //cout << "Diagonal length is "< 0 ) { - // cout << "size of the object is: " << s < eigenVal = covariantDecomposition(shape); { @@ -2071,7 +2060,7 @@ int main(int argc, char **argv) delete img; delete residual; - // cout<<"Sorting the objects according to size"< 15 when the size of the sequence is > 16. if ((endOfATrackSequence - startOfATrackSequence) >=15 ) { processASequence(startOfATrackSequence, endOfATrackSequence); - cout << "Done processing"< 15 ) { - cout << "Last sequence that does not stick to a single blob status startIndex "<pixelColor(x,y)); if (currPixelColor.mono() == true) { - cout << "Hit the target fly"<<" "< > foundShape; vector > shape; - cout<<"Detecting the male object for finding the start point"< 0 ) { - cout << "size of the object is: " << s < tmpCentroid = getCentroid(shape); foutDebugCen<<"tmpCentroid.first, tmpCentroid.second = ("< point = shape[l]; - cout << "point.first, point.second "< (ev_x); y1 = static_cast (ev_y); - cout<<"Endpoint: centroid (x0,y0)==("<draw(DrawableLine(x1, y1, x0, y0)); //maskImage->write("test.png"); - cout<<"BresenhamLine size is "< 0) { pair temp = bresenhamLine[bresenhamLine.size()-1]; - cout << "Finding the starting point: Hits source at "<pixelColor(temp.first, temp.second); //maleSP_x = prev_x; //maleSP_y = prev_y; if (c.mono() == true) { - cout << "start point from the source object should be black"< 0) { pair temp = bresenhamLine[bresenhamLine.size()-1]; - cout << "Finding the starting point: Hits source at "<pixelColor(temp.first, temp.second); //maleSP_x = prev_x; //maleSP_y = prev_y; if (c.mono() == true) { - cout << "start point from the source object should be black"<(dp)); - cout<<"Angle in radian "<(PI); - cout<<"Angle in deg "<(roundT(static_cast(deg))); - cout<<"Angle after rounding "< fOVector = currentFI.getFOVector(); - cout << "While drawing it found objects = "<draw(DrawableCircle(centroid.first, centroid.second, centroid.first+5, centroid.second)); img->pixelColor(prev_x, prev_y, "red"); } else if ( n == isFirst and n==1) { - cout << "Tracking the "<strokeColor("yellow"); img->fillColor("none"); img->pixelColor(prev_x, prev_y, "red"); @@ -2865,7 +2851,7 @@ void fourConnObj(Image* img, int x, int y, vector > & obj, bool c obj.push_back(p); // if (obj.size() > barrier) { - // //cout< > & obj, bool obj.push_back(p); // if (obj.size() > barrier) { - // //cout< covariantDecomposition(vector > & points) { // for (i=0; i<2; i++) { // gsl_vector_view evec_i = gsl_matrix_column (eigenVec, i); // //printf ("eigenvalue = %g\n", eval_i); - // cout<<"eigenvector = \n"; + // *output<<"eigenvector = \n"; // gsl_vector_fprintf (stdout, &evec_i.vector, "%g"); // } -- cgit v1.2.3