对cv :: imdecode的帮助很少 [英] Little help with cv::imdecode

查看:1816
本文介绍了对cv :: imdecode的帮助很少的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个jpeg图像缓冲区jpegBuffer。我试图将它传递给cv :: imdecode函数:

  Mat matrixJprg = imdecode(Mat(jpegBuffer),1) ; 

我收到此错误:

  /home/richard/Desktop/richard/client/src/main.cc:108:错误:没有匹配函数调用'cv :: Mat :: Mat(char *&)' 

这是我如何填充jpegBuffer:

  FILE * pFile; 
long lSize;
char * jpegBuffer;
pFile = fopen(img.jpg,rb);
if(pFile == NULL)
{
exit(1);
}

//获取文件大小。
fseek(pFile,0,SEEK_END);
lSize = ftell(pFile);
rewind(pFile);

//分配内存以包含整个文件。
jpegBuffer =(char *)malloc(lSize);
if(jpegBuffer == NULL)
{
exit(2);
}

//将文件复制到缓冲区中。
fread(jpegBuffer,1,lSize,pFile);

// terminate
fclose(pFile);


解决方案

Mat没有带有char *参数的构造函数。试试这个:

  std :: ifstream file(img.jpg); 
std :: vector< char>数据;

文件>> std :: noskipws;
std :: copy(std :: istream_iterator< char>(file),std :: istream_iterator< char>(),std :: back_inserter

Mat matrixJprg = imdecode(Mat(data),1);

编辑:



请参阅 LoadImageM



如果你的数据已经在char * buffer中,一种方法是将数据复制到std :: vector中。

  std :: vector< char>数据(buf,buf + size); 


I have a jpeg image in buffer jpegBuffer. I'm trying to pass it to cv::imdecode function:

Mat matrixJprg = imdecode(Mat(jpegBuffer), 1);

I get this error:

/home/richard/Desktop/richard/client/src/main.cc:108: error: no matching function for call to ‘cv::Mat::Mat(char*&)’

This is how I fill jpegBuffer:

FILE* pFile;
long lSize;
char * jpegBuffer;
pFile = fopen ("img.jpg", "rb");
if (pFile == NULL)
{
    exit (1);
}

// obtain file size.
fseek (pFile , 0 , SEEK_END);
lSize = ftell (pFile);
rewind (pFile);

// allocate memory to contain the whole file.
jpegBuffer = (char*) malloc (lSize);
if (jpegBuffer == NULL)
{
    exit (2);
}

// copy the file into the buffer.
fread (jpegBuffer, 1, lSize, pFile);

// terminate
fclose (pFile);

解决方案

Mat has no constructor that takes a char* argument. Try this instead:

std::ifstream file("img.jpg");
std::vector<char> data;

file >> std::noskipws;
std::copy(std::istream_iterator<char>(file), std::istream_iterator<char>(), std::back_inserter(data));

Mat matrixJprg = imdecode(Mat(data), 1);

EDIT:

You should also take a look at LoadImageM.

If you have your data already in a char* buffer one way is to copy the data into an std::vector.

std::vector<char> data(buf, buf + size);

这篇关于对cv :: imdecode的帮助很少的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆