【发布时间】:2019-06-15 14:27:51
【问题描述】:
我尝试为 libtiff 使用 nuget 包:=> Package <=
为了读取多帧图像 tif 文件,我编写了一小段代码。
vector<Mat> LibTiffReader::ReadMultiframeTiff(std::string FilePath)
{
vector<Mat> Result;
TIFF* tif = TIFFOpen(FilePath.c_str(), "r");
if (tif)
{
//Si le tif est ouvert, on itère sur ce qu'il y'a dedans...
do
{
Mat Image;
unsigned int width, height;
uint32* raster;
// On récupère la taille du tiff..
TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &width);
TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &height);
uint npixels = width*height; // get the total number of pixels
raster = (uint32*)_TIFFmalloc(npixels * sizeof(uint32)); // allocate temp memory (must use the tiff library malloc)
if (raster == NULL) // check the raster's memory was allocaed
{
TIFFClose(tif);
cerr << "Could not allocate memory for raster of TIFF image" << endl;
return vector<Mat>();
}
if (!TIFFReadRGBAImage(tif, width, height, raster, 0))
{
TIFFClose(tif);
cerr << "Could not read raster of TIFF image" << endl;
return vector<Mat>();
}
Image = Mat(width, height, CV_8UC3); // create a new matrix of w x h with 8 bits per channel and 3 channels (RGBA)
// itterate through all the pixels of the tif
for (uint x = 0; x < width; x++)
for (uint y = 0; y < height; y++)
{
uint32& TiffPixel = raster[y*width + x]; // read the current pixel of the TIF
Vec3b& pixel = Image.at<Vec3b>(Point(y, x)); // read the current pixel of the matrix
pixel[0] = TIFFGetB(TiffPixel); // Set the pixel values as BGR
pixel[1] = TIFFGetG(TiffPixel);
pixel[2] = TIFFGetR(TiffPixel);
}
_TIFFfree(raster);
Result.push_back(Image);
} while (TIFFReadDirectory(tif));
}
return Result;
}
我需要使用 libtiff,因为我需要用我的图像的 exif 数据做一些 OpenCV 不允许我做的事情。
问题是当我想编译时,我有链接器错误:
Error LNK2001 unresolved external symbol inflateInit_ SIA <Path>\tiff.lib(tif_zip.obj) 1
Error LNK2001 LNK2001 unresolved external symbol inflateInit_ SIA <Path>\tiff.lib(tif_pixarlog.obj) 1
我的 package.config 文件是这样的:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="libtiff-msvc-x64" version="4.0.7.8808" targetFramework="native" />
</packages>
当我继续我的项目属性时,我看不到任何包参数。 我尝试将手动链接器选项添加到 .lib 文件,但我遇到了同样的问题。
【问题讨论】:
-
inflateInit看起来像来自 zlib 的符号。手动构建 libtiff 而不是使用该包也是一个好主意 -
链接器问题可能与链接器设置有关,但也与您尝试编译的内容与您正在链接的库有关,即您的项目是 64 位构建但您要链接的库是32 位,或动态与静态库。所以检查这些很重要。有时我发现在设置中使用绝对路径也有助于解决这些问题。
-
可以确定的是,我使用的是 x64 软件包,而我的软件也是 x64。只是我不知道如何管理包的配置。你知道我在哪里可以检查路径吗?
标签: c++ visual-studio 64-bit linker-errors libtiff