Changeset 57
- Timestamp:
- 24.11.2006 17:03:27 (2 years ago)
- Files:
-
- trunk/devel/FuzzyOcr.pm (modified) (12 diffs)
- trunk/devel/FuzzyOcr/Deanimate.pm (modified) (3 diffs)
- trunk/devel/FuzzyOcr/Hashing.pm (modified) (1 diff)
- trunk/devel/FuzzyOcr/Misc.pm (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/devel/FuzzyOcr.pm
r55 r57 51 51 52 52 my $end; 53 my @time; 54 $time[0] = [gettimeofday]; 53 my $begin = [gettimeofday]; 55 54 if ($conf->{focr_global_timeout}) { 56 55 my $t = get_timeout(); … … 75 74 $end = fuzzyocr_do( $conf, $pms ); 76 75 } 77 $time[1] = [gettimeofday]; 78 debuglog("Processed in ".tv_interval(@time)." sec."); 76 debuglog("Processed in ". 77 sprintf("%.6f",tv_interval($begin, [gettimeofday])) 78 ." sec."); 79 79 return $end; 80 80 } … … 313 313 ">>$imgdir/giftext.err", 1); 314 314 315 if ($retcode ) {315 if ($retcode<0) { # only care if we timed out 316 316 chomp $retcode; 317 317 debuglog("$conf->{focr_bin_giftext} Timed out [$retcode], skipping..."); … … 338 338 $retcode = save_execute("$conf->{focr_bin_giffix} $file", ">$tfile", ">>$efile"); 339 339 340 if ($retcode ) {340 if ($retcode<0) { # only care if we timed out 341 341 chomp $retcode; 342 342 debuglog("$conf->{focr_bin_giffix}: Timed out [$retcode], skipping..."); … … 388 388 $retcode = save_execute("$conf->{focr_bin_gifinter} $cfile", ">$tfile", ">>$efile"); 389 389 390 if ($retcode ) {390 if ($retcode<0) { 391 391 chomp $retcode; 392 392 printf RAWERR "?? Timed out > $retcode\n" if ($haserr>0); 393 393 debuglog("$conf->{focr_bin_gifinter}: Timed out [$retcode], skipping..."); 394 394 ++$imgerr if $conf->{focr_keep_bad_images}>0; next; 395 } elsif ($retcode>0) { 396 chomp $retcode; 397 printf RAWERR "?? [$retcode] returned from $conf->{focr_bin_gifinter}\n" if ($haserr>0); 398 debuglog("$conf->{focr_bin_gifinter}: Returned [$retcode], skipping..."); 399 ++$imgerr if $conf->{focr_keep_bad_images}>0; next; 395 400 } 396 401 } … … 399 404 $retcode = save_execute("$conf->{focr_bin_giftopnm} $tfile", ">$pfile", ">>$efile"); 400 405 401 if ($retcode ) {406 if ($retcode<0) { 402 407 chomp $retcode; 403 408 printf RAWERR "?? Timed out > $retcode\n" if ($haserr>0); 404 409 debuglog("$conf->{focr_bin_giftopnm}: Timed out [$retcode], skipping..."); 410 ++$imgerr if $conf->{focr_keep_bad_images}>0; next; 411 } elsif ($retcode>0) { 412 chomp $retcode; 413 printf RAWERR "?? [$retcode] returned from $conf->{focr_bin_giftopnm}\n" if ($haserr>0); 414 debuglog("$conf->{focr_bin_giftopnm}: Returned [$retcode], skipping..."); 405 415 ++$imgerr if $conf->{focr_keep_bad_images}>0; next; 406 416 } … … 429 439 my $retcode = save_execute("$conf->{focr_bin_jpegtopnm} $file", ">$pfile", ">>$efile"); 430 440 431 if ($retcode ) {441 if ($retcode<0) { 432 442 chomp $retcode; 433 443 printf RAWERR "?? Timed out > $retcode\n" if ($haserr>0); 434 444 debuglog("$conf->{focr_bin_jpegtopnm}: Timed out [$retcode], skipping..."); 445 ++$imgerr if $conf->{focr_keep_bad_images}>0; next; 446 } elsif ($retcode>0) { 447 chomp $retcode; 448 printf RAWERR "?? [$retcode] returned from $conf->{focr_bin_jpegtopnm}\n" if ($haserr>0); 449 debuglog("$conf->{focr_bin_jpegtopnm}: Returned [$retcode], skipping..."); 435 450 ++$imgerr if $conf->{focr_keep_bad_images}>0; next; 436 451 } … … 459 474 my $retcode = save_execute("$conf->{focr_bin_pngtopnm} $file", ">$pfile", ">>$efile"); 460 475 461 if ($retcode ) {476 if ($retcode<0) { 462 477 chomp $retcode; 463 478 printf RAWERR "?? Timed out > $retcode\n" if ($haserr>0); 464 479 debuglog("$conf->{focr_bin_pngtopnm}: Timed out [$retcode], skipping..."); 480 ++$imgerr if $conf->{focr_keep_bad_images}>0; next; 481 } elsif ($retcode>0) { 482 chomp $retcode; 483 printf RAWERR "?? [$retcode] returned from $conf->{focr_bin_pngtopnm}\n" if ($haserr>0); 484 debuglog("$conf->{focr_bin_pngtopnm}: Returned [$retcode], skipping..."); 465 485 ++$imgerr if $conf->{focr_keep_bad_images}>0; next; 466 486 } … … 488 508 489 509 my $retcode = save_execute("$conf->{focr_bin_bmptopnm} $file", ">$pfile", ">>$efile"); 490 if ($retcode ) {510 if ($retcode<0) { 491 511 chomp $retcode; 492 512 printf RAWERR "?? Timed out > $retcode\n" if ($haserr>0); 493 513 debuglog("$conf->{focr_bin_bmptopnm}: Timed out [$retcode], skipping..."); 514 ++$imgerr if $conf->{focr_keep_bad_images}>0; next; 515 } elsif ($retcode>0) { 516 chomp $retcode; 517 printf RAWERR "?? [$retcode] returned from $conf->{focr_bin_bmptopnm}\n" if ($haserr>0); 518 debuglog("$conf->{focr_bin_bmptopnm}: Returned [$retcode], skipping..."); 494 519 ++$imgerr if $conf->{focr_keep_bad_images}>0; next; 495 520 } … … 518 543 my $retcode = save_execute("$conf->{focr_bin_tifftopnm} $file", ">$pfile", ">>$efile"); 519 544 520 if ($retcode ) {545 if ($retcode<0) { 521 546 chomp $retcode; 522 547 printf RAWERR "?? Timed out > $retcode\n" if ($haserr>0); 523 548 debuglog("$conf->{focr_bin_tifftopnm}: Timed out [$retcode], skipping..."); 549 ++$imgerr if $conf->{focr_keep_bad_images}>0; next; 550 } elsif ($retcode>0) { 551 chomp $retcode; 552 printf RAWERR "?? [$retcode] returned from $conf->{focr_bin_tifftopnm}\n" if ($haserr>0); 553 debuglog("$conf->{focr_bin_tifftopnm}: Returned [$retcode], skipping..."); 524 554 ++$imgerr if $conf->{focr_keep_bad_images}>0; next; 525 555 } … … 576 606 577 607 my ($retcode, @ocrdata) = save_execute("$scan", ">$imgdir/ocr.temp", ">>$efile",1); 578 if ($retcode) { 608 if ($retcode<0) { 609 debuglog("Timeout: \"$scanset\" took more than $conf->{focr_timeout} sec."); 610 debuglog("Skipping scanset due to timeout, trying next..."); 611 printf RAWERR qq(Timeout[$conf->{focr_timeout}]: $scanset\n) if ($haserr>0); 612 next; 613 } elsif ($retcode>0) { 579 614 chomp $retcode; 580 615 open ERR,$efile; … … 582 617 close ERR; 583 618 my $errstr = join( '', $retcode,@stderr ); 619 debuglog("Errors in \"$scanset\""); 584 620 debuglog($errstr); 621 debuglog("Skipping scanset because of errors, trying next..."); 585 622 printf RAWERR qq($errstr\n) if ($haserr>0); 586 debuglog("Skipping scanset \"$scanset\" because of errors, trying next...");587 623 next; 588 624 } trunk/devel/FuzzyOcr/Deanimate.pm
r55 r57 37 37 ">$tfile3", 38 38 ">>$efile"); 39 if ($retcode ) {40 debuglog("$conf->{'focr_bin_gifsicle'}: Timed out [$retcode], image not reduced!");39 if ($retcode == 0) { 40 $tfile = $tfile3; 41 41 } else { 42 $tfile = $tfile3; 42 debuglog("$conf->{'focr_bin_gifsicle'}: ". 43 ($retcode<0) ? 'Timed out' : 'Error' 44 ." [$retcode], image not reduced!"); 43 45 } 44 46 } … … 47 49 ">$tfile2", 48 50 ">>$efile"); 49 if ($retcode) { 50 debuglog("$conf->{focr_bin_gifsicle}: cannot extract image#${index}"); 51 return $tfile; 52 } 53 return $tfile2; 51 return $tfile2 if ($retcode == 0); 52 debuglog("$conf->{focr_bin_gifsicle}: cannot extract image#${index}"); 53 return $tfile; 54 54 } 55 55 … … 79 79 80 80 if ($retcode) { 81 debuglog("$conf->{'focr_bin_gifsicle'}: Timed out [$retcode], data unavailable..."); 81 debuglog("$conf->{'focr_bin_gifsicle'}: ". 82 ($retcode<0) ? 'Timed out' : 'Error' 83 ." [$retcode], data unavailable..."); 82 84 return \%info; 83 85 } trunk/devel/FuzzyOcr/Hashing.pm
r55 r57 339 339 if ($r) { 340 340 chomp $r; 341 debuglog("$conf->{focr_bin_ppmhist}: Timed out [$r], skipping..."); 341 debuglog("$conf->{focr_bin_ppmhist}: ". 342 ($r<0) ? 'Timed out' : 'Error' 343 ." [$r], skipping..."); 342 344 return (1, ''); 343 345 } trunk/devel/FuzzyOcr/Misc.pm
r55 r57 7 7 use lib "../"; 8 8 use FuzzyOcr::Config qw(set_pid unset_pid get_timeout get_pms get_config set_config debuglog logfile);; 9 use Time::HiRes qw( time usleep ualarm gettimeofday tv_interval ); 9 10 10 11 # Provide some misc helper functions … … 44 45 $stdout = '>/dev/null' unless $stdout; 45 46 $stderr = '>/dev/null' unless $stderr; 46 debuglog("Exec: $cmd $stdout $stderr");47 47 my $retcode; 48 48 if ($conf->{'focr_global_timeout'}) { … … 58 58 } else { 59 59 set_pid($pid); 60 wait(); $retcode = $?>>8; 60 wait(); 61 $retcode = $?; 61 62 unset_pid(); 62 63 if ($return_stdout and $stdout !~ m,/dev/null,i) { … … 73 74 my $pid; 74 75 $t->run_and_catch(sub { 76 my $begin = [gettimeofday]; 75 77 $pid = fork(); 76 78 if (not defined $pid) { … … 78 80 return -1; 79 81 } elsif (not $pid) { 82 debuglog("Exec: $cmd $stdout $stderr"); 80 83 open(STDOUT, $stdout); 81 84 open(STDERR, $stderr); … … 84 87 } else { 85 88 set_pid($pid); 86 wait(); $retcode = $?>>8; 89 my $wpid = wait(); $retcode = $? >>8; 90 debuglog("Elapsed: ". 91 sprintf ("%.6f",tv_interval($begin, [gettimeofday])) 92 ." sec. ($cmd)"); 87 93 unset_pid(); 88 94 if ($return_stdout and $stdout !~ m,/dev/null,i) {
