# HG changeset patch # User Nicolas Saunier # Date 1340696239 14400 # Node ID d4d3b1e8a9f1ff43bfd20c1039f8e1f3b84c567f # Parent 37a434fb848eab8467f3231294124520821c67f0 added code to process only needed frames based on saved features diff -r 37a434fb848e -r d4d3b1e8a9f1 c/Motion.cpp --- a/c/Motion.cpp Tue Jun 26 03:36:55 2012 -0400 +++ b/c/Motion.cpp Tue Jun 26 03:37:19 2012 -0400 @@ -101,8 +101,8 @@ if (frameNum > lastInstant) lastInstant = frameNum; computeMotionData(frameNum); - assert(positions.size() == displacementDistances.size()+1); - assert(positions.size() == velocities.size()+1); + assert(positions->size() == displacementDistances.size()+1); + assert(positions->size() == velocities->size()+1); } void FeatureTrajectory::shorten(void) { @@ -158,8 +158,8 @@ vi!=vertices(graph).second; ++vi) { // vi pointer to vertex_descriptor FeatureTrajectoryPtr ft2 = graph[*vi].feature; if (newVertex != *vi) { - int lastInstant = static_cast(min(ft->getLastInstant(), ft2->getLastInstant())); - int firstInstant = static_cast(max(ft->getFirstInstant(), ft2->getFirstInstant())); + int lastInstant = static_cast(MIN(ft->getLastInstant(), ft2->getLastInstant())); + int firstInstant = static_cast(MAX(ft->getFirstInstant(), ft2->getFirstInstant())); if (lastInstant-firstInstant > static_cast(minFeatureTime)) { // equivalent to lastInstant-firstInstant+1 >= minFeatureTime if (ft->minMaxSimilarity(*ft2, firstInstant, lastInstant, connectionDistance, segmentationDistance)) { UndirectedGraph::edge_descriptor e; @@ -211,8 +211,8 @@ unsigned int lastInstant = graph[objectHypotheses[i][0]].feature->getLastInstant(); for (unsigned int j=1; jlength(); - firstInstant = min(firstInstant, graph[objectHypotheses[i][j]].feature->getFirstInstant()); - lastInstant = max(lastInstant, graph[objectHypotheses[i][j]].feature->getLastInstant()); + firstInstant = MIN(firstInstant, graph[objectHypotheses[i][j]].feature->getFirstInstant()); + lastInstant = MAX(lastInstant, graph[objectHypotheses[i][j]].feature->getLastInstant()); } if (static_cast(totalFeatureTime)/static_cast(lastInstant-firstInstant+1) > minNFeaturesPerGroup) { #if DEBUG diff -r 37a434fb848e -r d4d3b1e8a9f1 c/feature-based-tracking.cpp --- a/c/feature-based-tracking.cpp Tue Jun 26 03:36:55 2012 -0400 +++ b/c/feature-based-tracking.cpp Tue Jun 26 03:37:19 2012 -0400 @@ -271,10 +271,14 @@ // c_end = std::clock(); // cout << "Loaded " << trajectories.size() << " trajectories one by one in " << 1000.0 * (c_end-c_start) / CLOCKS_PER_SEC << " CPU seconds" << endl; - trajectoryDB->createViewInstants("table"); + trajectoryDB->createInstants("table"); - unsigned int maxTrajectoryLength; - trajectoryDB->maxTrajectoryLength(maxTrajectoryLength); + unsigned int maxTrajectoryLength = 0; + success = trajectoryDB->maxTrajectoryLength(maxTrajectoryLength); + if (!success || maxTrajectoryLength == 0) { + cout << "problem with trajectory length " << success << endl; + exit(0); + } cout << "Longest trajectory: " << maxTrajectoryLength << endl; // alternative: read and load features in batches directly select * from positions where trajectory_id in select trajectory_id from positions where frame_number <100 and frame_number > 50 group by trajectory_id @@ -283,10 +287,17 @@ FeatureGraph featureGraph(params.mmConnectionDistance, params.mmSegmentationDistance, params.minFeatureTime, params.minNFeaturesPerGroup); // main loop - for (int frameNum = params.frame1; ((frameNum-params.frame1 < params.nFrames) || (params.nFrames < 0)); frameNum ++) { // frameNum += queryIntervalLength // interval = frameNum, min(frameNum+queryIntervalLength, frameNum+params.nFrames) // stop if no trajectory available ? problem if nothing moves, timeout, get max of trajectory frame numbers + int frameNum; + unsigned int firstFrameNum, lastFrameNum; + trajectoryDB->firstLastInstants(firstFrameNum, lastFrameNum); + firstFrameNum = MAX(firstFrameNum, params.frame1); + if (params.nFrames>0) + lastFrameNum = MIN(lastFrameNum,params.frame1+params.nFrames); + for (frameNum = firstFrameNum; frameNum trajectoryIds; success = trajectoryDB->trajectoryIdEndingAt(trajectoryIds, frameNum); // ending - cout << "frame " << frameNum << endl; + if (frameNum%100 ==0) + cout << "frame " << frameNum << endl; //success = trajectoryDB->trajectoryIdInInterval(trajectoryIds, frameNum, min(frameNum+queryIntervalLength-1, frameNum+params.nFrames)); // ending #if DEBUG cout << trajectoryIds.size() << " trajectories " << endl; @@ -307,14 +318,26 @@ } // check for connected components - featureGraph.connectedComponents(frameNum+params.minFeatureTime); - vector > featureGroups = featureGraph.getFeatureGroups(); - for (unsigned int i=0; iwriteObject(savedObjectId, featureGroups[i], -1, 1, string("objects"), string("objects_features")); - savedObjectId++; + int lastInstant = frameNum+params.minFeatureTime-maxTrajectoryLength; + if (lastInstant > 0) { + featureGraph.connectedComponents(lastInstant); + vector > featureGroups = featureGraph.getFeatureGroups(); + for (unsigned int i=0; iwriteObject(savedObjectId, featureGroups[i], -1, 1, string("objects"), string("objects_features")); + savedObjectId++; + } } - cout << featureGraph.informationString() << endl; + if (frameNum%100 ==0) + cout << featureGraph.informationString() << endl; + } + + // save remaining objects + featureGraph.connectedComponents(frameNum+maxTrajectoryLength+1); + vector > featureGroups = featureGraph.getFeatureGroups(); + for (unsigned int i=0; iwriteObject(savedObjectId, featureGroups[i], -1, 1, string("objects"), string("objects_features")); + savedObjectId++; } trajectoryDB->endTransaction();