in reply to need logic, police edited video

Reading your description, here is my *UNTESTED* code that I think (minus the possibility of small typos) to do what you are requesting:

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; use File:Basename; use File::Spec; use Getopt::Long; $| = 1; # Next 3 lines are my preference for debugging srand(); $Data::Dumper::Deepcopy = 1; $Data::Dumper::Sortkeys = 1; my %configuration = ( x => 0, y => 0, data_directory => q{g:/Frames as bitmap/}, file_extension => q{txt}, output_file => $0 . q{.output}, delimiter => q{,}, ); GetOptions( q{x_coordinate:s} => \$configuration{x}, q{y_coordinate:s} => \$configuration{y}, q{data_directory:s} => \$configuration{data_directory}, q{file_extension:s} => \$configuration{file_extension}, q{output_file:s} => \$configuration{output_file}, q{help} => \&help_output, ); sub help_output { print qq{Usage:\n\t$0 } . qq{--x_coordinate=nnn --y_coordinate=nnn } . qq{--data_directory=path/to/data/files } . qq{--file_extension=file.extension.to.match } . qq{--output_file=output.file.name\n\n} . qq{\t\t--x_coordinate, --y_coordinate } . qq{\t\t\t- pixel coordinate to match\n} . qq{\t\t--data_directory} . qq{\t\t\t- directory containing data files\n} . qq{\t\t--file_extension } . qq{\t\t\t- file extension to glob(), such as 'txt'\n} . qq{\t\t\t\t(assumes leading '.')\n} . qq{\t\t--output_file - file name to write data to\n\n}; exit; } my @files = sort { $a cmp $b } glob File::Spec->catfile( $configuration{data_directory}, q{*} . q{.} $configuration{file_extension}, ); open my $outf, q{>}, $configuration{output_file} or die $!; my $format_string = join( $configuration{delimiter}, q{%s}, q{%d}, q{%d}, q{%d} ) . qq{\n}; foreach my $fn ( @files ) { my $f_id = File::Basename::basename $fn; $f_id =~ s/\.$configuration{file_extension}.*$//g; open my $inf, q{<}, $fn or die $!; while ( my $line = <$inf> ) { chomp $line; my @data = split /\s+/, $line; # Example input data (x y r g b): # 0 0 113 0 255 next if ( $data[0] != $configuration{x_coordinate} ); next if ( $data[1] != $configuration{y_coordinate} ); # Example output data: nnnnn,nnn,nnn,nnn # 12345,255,032,127 print $outf sprintf $format_string, $f_id, @data[2-4]; last; } close $inf; } close $outf;

Please comment if that does indeed do so, or if your expectations differed from those I understood.

Hope that helps.

Replies are listed 'Best First'.
Re^2: need logic, police edited video
by AwsedreswA (Initiate) on Feb 01, 2014 at 05:53 UTC

    Had to track down one of my old professors.

    Here is what we came up with

    ##This script is for use with rgb tuple files created through ImageJ.e +xe's xy coordinate extractor ##With RGB tuple files for each frame of a video, this script will ext +ract the RGB values for one pixel location. ##Each line of the new file has file name(= frame number), x, y, R, G, + B. $out_file="C:\\perl\\scripts\\bluetime.txt"; # out_file is the output file name, created by extracting the RGB valu +es from one coordinate unlink $out_file; # erased (deletes) the output file FIRST, otherwise it will continue t +o append to it! open ($output_file,">>",$out_file) or die "Could not open output_file! +!!"; #open file for append for ($i=1;$i<=60075;$i++) # files 00000.txt thru 60075.txt { $output_name = sprintf("%05d",$i); # first field in bluetime, 5 digits $input_file = sprintf("G:\\Frames_as_RGB_Tuples\\%05d.txt",$i); + # FQ input filename open ($infile, "<",$input_file) or die "Could not open input file +$input_file!!!"; ## "<" means read from, ">>" means append to, ">" means write to! # printf("G:\\Frames_as_RGB_Tuples\\%s.txt\n", $result); #For testing while(<$infile>) # read one line from infile, put in $_ { if($_ =~ /^390\t379/) #for each line, if "390(tab)379" is on the line then... { print $output_file sprintf("%s\t%s",$output_name,$_); #write to ouput_file #5 digits of filename plus the line where coordinate was f +ound } } close $infile; } close $output_file; ## by PK Birkmeyer and Ben Gregory one fine afternoon.

    I would like if it gave me some feedback as to its progress, if anyone can help there.

    This script worked, need help with next hurdle. Posted my pseudo code on this forum here.

    http://www.perlmonks.org/?node_id=1072419