Saturday, May 27, 2006

Learning Perl

It took me quite a while to extract the number of keypoints detected and insert them into a spreadsheet. To make future tasks easier, I decided to learn PERL scripting. I read over some tutorials and books. From what I've learned about PERL, I created a script to remove keypoints and their corresponding images from the database it the number of keypoints detected in them is less than 3. This is accomplished by parsing the output text file from detecting keypoints in the database directory. Now that I can make PERL scripts, I should be able to accomplish many tasks faster by automating the more tedious work.

Here is a sample from the output file from creating database keypoints:

extracting keypoints: ./database/s06.pgm -> ./database/s06.key
Finding keypoints...
22 keypoints found.
extracting keypoints: ./database/ss01.pgm -> ./database/ss01.key
Finding keypoints...
2 keypoints found.
extracting keypoints: ./database/ss02.pgm -> ./database/ss02.key
Finding keypoints...
3 keypoints found.
extracting keypoints: ./database/ss03.pgm -> ./database/ss03.key
Finding keypoints...
0 keypoints found.


Here is the PERL script I wrote. It is called by passing in the name of the output text file ( a sample of which is above). The # signs represent comments:

#!usr/bin/perl
my $rmkp = ">./rmkp.txt";
my $line;
my $prevLine;
#@ARGV[0]: output text filename from keypoint detection.
open ( FILE, "@ARGV[0]") or
die "Cannot open input file: @ARGV[0] : $!\n";
while( $line = ) {
# i means case insensitive
# ([^>]*) match zero or more characters but not '>'
# if line matches regexp
if( $line =~ m/extracting keypoints:([^>]*)>/ ){
#removing words
$line =~ s/extracting keypoints:([^>]*)>//g;
#remove file extension
$line =~ s/.key//g;
#remove whitespace
$line =~ s/\s//g;
#store current line
$prevLine = $line;
}
#if number of keypoints found, store number
if($line =~ m/keypoints found./){
$line =~ s/keypoints found.//g;
$line =~ s/\n//g;
#if less than 3 keypoints
if($line <>


Here is the log file, rmkp.txt, generated by the PERL script. This shows the number of keypoints for the associated keypoint and image files that were deleted:

Files Deleted From Database:

2 ./database/ss01.key ./database/ss01.pgm
0 ./database/ss03.key ./database/ss03.pgm

5 Comments:

Blogger Randal L. Schwartz said...

It doesn't look to me like you're learning PERL, which is the nonprofit "Protecting Escarpment Rural Lands" (at perlofburlington.org). Looks to me like you're learning the computer language called Perl. And yes, it makes a difference... if you see a book that spells it as PERL, it's definitely not a good book, since the author isn't paying attention to detail.

6:57 AM  
Blogger Anna Roberts said...

Absolutely fabulous! Thanks for giving out excellent information. Your post is fascinating and I have forwarded it to some of my links.
buy book reports online

6:10 AM  
Blogger Angela Michael said...

Great article! This is the type of information that are meant to be public around the internet.
cheap term paper buy

11:44 PM  
Blogger sindhu said...

Excellent and very cool idea and the subject at the top of magnificence and I am happy to this post..Interesting post! Thanks for writing it. What's wrong with this kind of post exactly? It follows your previous guideline for post length as well as clarity..

CRO Agency in Chennai

1:45 AM  
Blogger deeksha said...

I think this is interesting articles and Business ethics for new information's, and i like that kind of information.So the i like that post,because all of given information was very excellent.

Best Android Training Institute in Chennai

11:32 PM  

Post a Comment

<< Home