错误图像::比较(jpg文件)

时间:2014-10-19 08:26:23

标签: image perl compare jpeg

我尝试在perl中使用Image::Compare来根据图片中使用的颜色比较两个图像。以下是我使用的代码:

#!/usr/bin/perl
use strict;
use warnings;
use Image::Compare;
my ($cmp) = Image::Compare->new();
$cmp->set_image1(
    img  => "$ARGV[0]",
    type => 'jpg',
);
$cmp->set_image2(
    img  => "$ARGV[1]",
    type => 'jpg',
);
$cmp->set_method(
    method => &Image::Compare::THRESHOLD,
    args   => 70,
);

if ( $cmp->compare() ) {
    print "same \n";
} else {
    print "not same\n";
}

运行时,它给出了错误:

  

Unable to read image data from file 'test_002.jpg': 'format 'jpg' not supported - formats bmp, ico, pnm, raw, sgi, tga available for reading - Can't locate Imager/File/JPG.pm or Imager/File/JPGReader.pm' at /usr/local/share/perl/5.18.2/Image/Compare.pm line 162.

我已尝试安装Imager::File::JPEG,但也给了我错误:

  

$ cpan install Imager::File::JPEG Reading '/home/b0y/.cpan/Metadata'
Database was generated on Sat, 18 Oct 2014 07:05:12 GMT Running install for module 'Imager::File::JPEG' Running make for T/TO/TONYC/Imager-File-JPEG-0.88.tar.gz Checksum for /home/b0y/.cpan/sources/authors/id/T/TO/TONYC/Imager-File-JPEG-0.88.tar.gz ok

     

CPAN.pm: Building T/TO/TONYC/Imager-File-JPEG-0.88.tar.gz

     

JPEG: building independently JPEG: main: includes not found - libraries found JPEG: Checking if the compiler can find them on its own JPEG: Test code failed: Can't link/include 'jpeglib.h', 'jpeg' OS unsupported: JPEG libraries or headers not found Warning: No success on command[/usr/bin/perl Makefile.PL INSTALLDIRS=site]
TONYC/Imager-File-JPEG-0.88.tar.gz /usr/bin/perl Makefile.PL INSTALLDIRS=site -- NOT OK Running make test Make had some problems, won't test Running make install Make had some problems, won't install Could not read metadata file. Falling back to other methods to determine prerequisites

非常感谢。

2 个答案:

答案 0 :(得分:2)

您需要安装“libjpeg-dev”,

sudo apt-get install libjpeg-dev

答案 1 :(得分:0)

您的错误:

  "JPEG: building independently JPEG: main: includes not found -
  libraries found JPEG: Checking if the compiler can find them on its
  own JPEG: Test code failed: Can't link/include 'jpeglib.h', 'jpeg' OS
  unsupported: JPEG libraries or headers not found Warning: No success
  on command[/usr/bin/perl Makefile.PL INSTALLDIRS=site]"

你的标题" jpeglib.h"在你的PATH中,这意味着你的编译器无法找到它。如果您使用的是类似操作系统的Debian,您可以按照以下说明操作:

  echo "export LD_LIBRARY_PATH=/path to your lib/lib" >> ~/.bashrc
  echo "export C_INCLUDE_PATH="/path to your include/include" >> ~/.basrc
  $. ~/.basrc
  $cpan install Imager::File::JPEG

如果不起作用,

$cpan 
>look Imager::File::JPEG
$LD_LIBRARY_PATH="/path to your lib/lib" C_INCLUDE_PATH="/path to your include/include" perl Makefile.PL
$make test
$make install
$exit