C++ jpeg\u解压缩\u结构大小不匹配
我正在尝试使用Visual Studio Community 2017上的版本9b来解码编码图像缓冲区(我从openCV获得) 我遵循并编写了自己的函数,该函数调用C++ jpeg\u解压缩\u结构大小不匹配,c++,c,struct,decode,libjpeg,C++,C,Struct,Decode,Libjpeg,我正在尝试使用Visual Studio Community 2017上的版本9b来解码编码图像缓冲区(我从openCV获得) 我遵循并编写了自己的函数,该函数调用jpeg\u create\u decompress,指针指向jpeg\u decompress\u struct 我的函数总是在 if (structsize != SIZEOF(struct jpeg_decompress_struct)) ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
jpeg\u create\u decompress
,指针指向jpeg\u decompress\u struct
我的函数总是在
if (structsize != SIZEOF(struct jpeg_decompress_struct))
ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
(int) SIZEOF(struct jpeg_decompress_struct), (int) structsize);
在jdapimin.c中的jpeg\u CreateDecompress(j\u decompress\u ptr cinfo,int version,size\u t structsize)
方法中
我写了不同的代码,只是在网上尝试了不同的例子,遇到了同样的问题
Mat readFile = imread("ottawa.jpg", IMREAD_COLOR);
cout << "Read Matrix size: " << readFile.size() << endl;
vector<uchar> encodedBuffer; // output buffer to store compressed image
vector<int> compression_params;
int jpegqual = ENCODE_QUALITY; // Compression Parameter
compression_params.push_back(CV_IMWRITE_JPEG_QUALITY);
compression_params.push_back(jpegqual);
imencode(".jpg", readFile, encodedBuffer, compression_params); // compress the image
cout << "Encoding with OpenCV complete..." << endl;
int matSize = encodedBuffer.size();
cout << "Size of matrix: " << matSize << endl;
// Variables for the decompressor itself
struct jpeg_decompress_struct cinfo;
struct jpeg_error_mgr jerr;
unsigned long jpg_size = encodedBuffer.size();
unsigned char *jpg_buffer = &encodedBuffer.front();
cinfo.err = jpeg_std_error(&jerr);
cout << endl << "In decode function:" << endl;
cout << "cinfo size: " << sizeof(cinfo) << endl;
cout << "jpeg_decompress_struct size: " << sizeof(struct jpeg_decompress_struct) << endl;
jpeg_create_decompress(&cinfo);
这是输出:
这完全是我的问题。我无法理解同一个sizeof函数返回不同值的可能性!为什么相差32?我试过按尺寸浇铸,移除了浇铸。我一点也不知道这会出什么问题
很抱歉,我的帖子太长,如果有任何线索,我将不胜感激。谢谢
编辑:我检查了,但我自己编译了库并在VisualStudio中链接了.lib。所以不确定如何检查是否安装了多个libjpeg。问题已解决:
我打开了两个文件中的jpeglib.h
,并检查了位置。jdapimin.c
和我的程序中包含的jpeglib.h
文件位于不同的位置。在我的项目目录中有一个副本,我的程序正在使用它。我删除了那些.h
文件,现在它们都在使用include目录路径中的文件。这解决了问题,所有值现在都是632
感谢@LPs在评论中的建议。你在哪里给structsize赋值的?我没有,它是在jpeglib.h
\define jpeg\u create\u decompress(cinfo)\jpeg\u CreateDecompress((cinfo),jpeg\u LIB\u VERSION,\(size\u t)sizeof(struct jpeg\u decompress\u struct))EXTERN(void)jpeg\u CreateCompress JPP((j_compress_ptr cinfo,int version,size_t structsize));EXTERN(void)jpeg_CreateDecompress JPP((j_decompress_ptr cinfo,int version,size_t structsize));
但是structsize在这两种情况下在664处是相等的,所以我认为这是正确的给出了不同的值。但在这一点上,我不确定发生了什么!我在jpeglib.h
中看到了一些定义缓冲区大小的定义。你确定lib项目指向的.h
与应用程序项目使用的数字相同吗?你是对的!我打开了我包含的jpeglib.hn都是,而且位置不同。在我的项目目录中还有一个副本。现在所有内容都等于632。非常感谢!!
printf("\nIn jdapimin.c:\n");
printf("Structsize: %zd\n", structsize);
printf("jpeg_decompress_struct: %zd\n", sizeof(struct jpeg_decompress_struct));