두 개의 폴더 (각각 1000 개의 파일)의 이미지 파일을 일부 논리 인 (see this SO question)과 비교하는 프로그램을 작성했습니다.연결 (.)에서 XXXX 내의 초기화되지 않은 값 또는 image_magick.pl에서 문자열 사용 XX
는 이미지 (900)까지 성공적 비교 되나 그럼 Use of uninitialized value within @tfiles2 in concatenation (.) or string at C:\dropbox\Image_Compare\image_magick.pl line 55
(# 3)와 같은 오류를 범 실행 동안. 그리고 나서 Perl Command Line Interpreter has stopped working
과 같은 팝업 오류가 발생하여 프로그램을 닫습니다. 내가 실수를하고있는 중이 야 어디
#!/usr/bin/perl
use Image::Magick;
no warnings 'uninitialized';
use warnings;
use diagnostics;
#use strict;
use List::Util qw(first);
my $directory1="C:/dropbox/Image_Compare/folder1";
opendir(DIR, $directory1) or die "couldn't open $directory1: $!\n";
my @files1 = grep { (!/^\./) && -f "$directory1/$_" } readdir(DIR);
closedir DIR;
print @files1;
print 'end of files1';
my $directory2="C:/dropbox/Image_Compare/folder2";
opendir(DIR, $directory2) or die "couldn't open $directory2: $!\n";
my @files2= grep { (!/^\./) && -f "$directory2/$_" } readdir(DIR);
closedir DIR;
print @files2;
print 'end of files2';
print $files1[0];
foreach my $fils2 (@files2)
{
$g1 = Image::Magick->new;
$g2 = Image::Magick->new;
$temp1 = $g1->Read(filename=>"C:/dropbox/Image_Compare/folder1/".$files1[0]."");
$temp1 = $g2->Read(filename=>"C:/dropbox/Image_Compare/folder2/".$fils2."");
$g3 = $g1->Compare(image=>$g2, metric=>'AE'); # compare
$error1 = $g3->Get('error');
#print $error1;
if ($error1 == '0')
{
print "Matching image is:";
print $fils2 . "\n";
my $tdirectory2="C:/dropbox/Image_Compare/folder2";
opendir(DIR, $tdirectory2) or die "couldn't open $directory2: $!\n";
my @tfiles2 = grep { (!/^\./) && -f "$tdirectory2/$_" } readdir(DIR);
closedir DIR;
#my $index = firstidx { $_ eq'"' .$fils2.'"' } @tfiles2;
my $index = first { $tfiles2[$_] eq $fils2} 0..$#tfiles2;
#print $fils2;
print $index;
my $i=0;
foreach my $fils1 (@files1)
{
print 'ganesh';
print $files1[$i];
print $tfiles2[$index];
print 'gowtham'; print "<br />";
#print @tfiles2;
$g4 = Image::Magick->new;
$g5 = Image::Magick->new;
$temp2 = $g4->Read(filename=>"C:/dropbox/Image_Compare/folder1/".$files1[$i]."");
$temp2 = $g5->Read(filename=>"C:/dropbox/Image_Compare/folder2/".$tfiles2[$index]."");
$g6 = $g4->Compare(image=>$g5, metric=>'AE'); # compare
$error2 = $g6->Get('error');
$i++;
$index++;
if ($error2 == '0') {}
else {print "Image not matching:"; print $tfiles2[$index]; last;}
#if ($i == '800') {last;}
}
last
}
}
사람이 도와 주시겠습니까 다음과 같이
내 코드입니다.
폴더 (1) 파일 이름 : 0025.bmp이 1051.bmp하는 단계;
폴더 2 파일 이름 : 0000.bmp이 1008.bmp하는 단계;
감사 가네
첫 인상 : 잉어 :: 항상을 사용하여, 당신이 손상된 이미지 파일이있을 수 있습니다 – gaussblurinc
:) 도움을 도와 드릴까요? 다른 이미지 세트로 시도해 보셨습니까? 항상 정확히 같은 장소에서 멈추는가? – foundry
이 코드는 일부 리팩터링을 사용할 수 있습니다. 코드를 쉽게 테스트 할 수있는 서브 루틴으로 분리하면 가독성과 테스트 가능성이 향상되고 간단한 오타가 발생할 수 있습니다.두 이미지를로드하고 비교하면 오류를 가져 오는 것이 일반적인 작업이며 디렉토리를로드하는 것과 같습니다. 또한 'strict'를 다시 켜십시오. – amon