小编Dun*_*ncs的帖子

有没有其他方法可以使用OpenCV的imdecode?太慢了

我创建了一个DLL,用户可以从文件名或流中读取图像,如下所示:

std::string filePath = "SomeImage.bmp";

// (1) Reading from a file
Image2D img1;
img1.readImage(filePath);

// (2) Reading from a stream
std::ifstream imgStream (filePath.c_str(), std::ios::binary);
Image2D img2;
img2.readImage(imgStream);
Run Code Online (Sandbox Code Playgroud)

第一个readImage(filePath)是使用cv::imread(filePath)合理快速实现的(对于600 x 900图像,平均为0.001秒).然而,第二版本readImage(fileStream)被实现使用cv::imdecode它是相当慢(平均2.5秒对于相同的图像).

是否有任何替代品cv::imdecode,我可以不考虑这么长的时间从存储器缓冲器的图像解码?这是经常使用的应用程序的核心组件,因此必须快速.

任何援助将不胜感激.提前致谢.

编辑:

我用计时器测量时间.这对我也没有意义.我不明白为什么时间上存在如此大的差距.Image2D只是一个OpenCV矩阵作为成员的类.readImage功能的实现简化如下:

int Image2D::readImage(std::ifstream& input)
{       
    input.seekg(0, std::ios::end);
    size_t fileSize = input.tellg();
    input.seekg(0, std::ios::beg);

    if (fileSize == 0) {
        return 1;
    }

    std::vector<unsigned char> data(fileSize);
    input.read(reinterpret_cast<char*>(&data[0]), sizeof(unsigned char) * fileSize);

    if (!input) …
Run Code Online (Sandbox Code Playgroud)

c++ opencv memory-management image

5
推荐指数
1
解决办法
2650
查看次数

标签 统计

c++ ×1

image ×1

memory-management ×1

opencv ×1