Batch Processor Invalid Frame Range

Post Reply
lschutz
Posts: 4
Joined: Wed Feb 14, 2018 4:29 pm

Batch Processor Invalid Frame Range

Post by lschutz »

Hello,

For a study, I am recording multiple trials in a single .tak. For data cleaning and csv export, I then trim the .tak file maintaining the original frame numbers to combine with .tak start time and generate timestamps. I am having trouble using the batch exporter with .tak files that are in this format.

I have attached a screenshot of the error message and the batch processing script I am using is copied below. For now, I can avoid the error by manually entering the start frame and end frame in the script as I have commented out, but with this fix I am only able to process one .tak at a time, avoiding the main benefit of using the batch processing script. Is there a way to code into the script an automatic determination of start and end frame?

Lauren

using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using NMotive;

public class MarkerFilterScript : ITakeProcessingScript
{
public Result ProcessTake(Take takeToProcess, ProgressIndicator progress )
{
// Ignore unlabeled markers with no segments of length of at
// at least 1200 frames, i.e. 1s.
//
// A segment is a continuous set of frames that have data.
int minSegmentSize = 1200;

// Update the message area of the progress indicator.
progress.SetMessage( string.Format( @"Finding all unlabeled markers which do not have a segment longer than {0} frames.", minSegmentSize ) );

NodeWarehouse nodes = takeToProcess.Scene;
List<RealMarker> unlabeledMarkers =
nodes.AllMarkers().FindAll( m => !m.IsLabeled );

// Initialization.
// Create the result object that this function will return. Initialize the
// Success field to true. We'll set it to false if something goes wrong.
Result removeResult = new Result( true, "" );

List<RealMarker> badMarkersRemoved = new List<RealMarker>();
List<RealMarker> badMarkersNotRemoved = new List<RealMarker>();

int numUnlabeledMarkers = unlabeledMarkers.Count;
int numProcessed = 0;

FrameRange allFrames = takeToProcess.FullFrameRange;
foreach ( RealMarker marker in unlabeledMarkers )
{
List<FrameRange> segments = marker.TranslationChannel.Segments( allFrames );

bool deleteMarker = true;
foreach ( FrameRange seg in segments )
{
if ( seg.Length > minSegmentSize )
{
deleteMarker = false;
break;
}
}

if ( deleteMarker )
{
if ( nodes.RemoveNode( marker.ID ) )
{
badMarkersRemoved.Add( marker );
}
else
{
badMarkersNotRemoved.Add( marker );
}
}

++numProcessed;
if ( numProcessed % 100 == 0 )
{
progress.SetProgress( (float)numProcessed / (float)numUnlabeledMarkers * (float)0.9);
// progress.SetMessage( string.Format( @"Processed {0}/{1} unlabeled markers.", numProcessed, numUnlabeledMarkers ) );

}
}

progress.SetMessage( string.Format( @"Outputting counts of removed markers.") );

StringBuilder resultMessage = new StringBuilder();

resultMessage.AppendLine( string.Format( @"Removing unlabeled markers without segments longer than {0} frames...", minSegmentSize ) );
resultMessage.AppendLine( string.Format( @"No. of unlabeled markers: {0}", numUnlabeledMarkers ) );
resultMessage.AppendLine( string.Format( @"No. of bad unlabeled markers successfully removed: {0}", badMarkersRemoved.Count ) );
resultMessage.AppendLine( string.Format( @"No. of bad unlabeled markers that could not be removed: {0}", badMarkersNotRemoved.Count ) );

string outputFile = GetOutputFile( takeToProcess );
using ( StreamWriter writer = new StreamWriter( outputFile ) )
{
writer.WriteLine( resultMessage.ToString() );
}

// System.Threading.Thread.Sleep(5000);

if ( badMarkersNotRemoved.Count > 0 )
{
progress.SetMessage( string.Format( @"Failed to remove bad markers.") );
return new Result( false, "" );
}

progress.SetMessage( string.Format( @"Exporting tracking data CSV.") );

CSVExporter exporter = new CSVExporter
{
RotationType = Rotation.QuaternionFormat, // QuaternionFormat, XYZ, XZY, YXZ, YZX, ZXY, ZYX
Units = LengthUnits.Units_Millimeters,
UseWorldSapceCoordinates = true,
WriteBoneMarkers = false,
WriteBones = true,
WriteHeader = true,
WriteMarkers = true,
WriteQualityStats = false,
WriteRigidBodies = false,
WriteRigidBodyMarkers = false,
//-== Exporter Class ==-
//StartFrame = 191901,
//EndFrame = 235600,
//FrameRate = 120,
//Scale = 1
};

string csvOutputFileName = Path.GetFileNameWithoutExtension(takeToProcess.FileName) + ".csv";
string csvOutputFile = Path.Combine(Path.GetDirectoryName(takeToProcess.FileName), csvOutputFileName);

progress.SetMessage("Exporting tracking data CSV: " + takeToProcess.FileName);

return exporter.Export(takeToProcess, csvOutputFile, true);
}

#region Member Functions ---------------------------------------------

/// <summary>
/// Gets the name, including path to output the results of the filter
/// marker operation for a take file. The output directory is the
/// same directory where the take file is located and the output file
/// name is [take file name]_marker_filtered.txt
/// </summary>
/// <param name="t">The take file.</param>
/// <returns>The path for the file.</returns>
private string GetOutputFile(Take t)
{
string outputDirectory = Path.GetDirectoryName( t.FileName );
string filename = Path.GetFileNameWithoutExtension( t.FileName ) +
"_export_status.txt";
return Path.Combine( outputDirectory, filename );
}

#endregion Member Functions
}
Attachments
Error Message
Error Message
Invalid Frame Range.PNG (34.28 KiB) Viewed 1653 times
Post Reply