gpt4 book ai didi

C++ 取消引用字符指针(图像数组)非常慢

转载 作者:行者123 更新时间:2023-11-28 08:23:30 24 4
gpt4 key购买 nike

我在快速访问无符号字符数组时遇到一些问题。

我实际上想将 BGRABGRA....BGRABGRA.... 行编码图像数组复制到使用三层的 OpenCV 版本。下面的代码工作正常,但速度非常慢(640*480 图像大约需要 0.5 秒)。我指出取消引用运算符 * 会使它变慢。你有任何计划如何解决这个问题吗? (提示:BYTE 是一个无符号字符)

// run thorugh all pixels and copy image data
for (int y = 0; y<imHeight; y++){
BYTE* pLine= vrIm->mp_buffer + y * vrIm->m_pitch;
for (int x = 0; x<imWidth; x++){
BYTE* b= pLine++; // fast pointer operation
BYTE* g= pLine++;
BYTE* r= pLine++;
BYTE* a= pLine++; // (alpha)
BYTE bc = *b; // this is really slow!
BYTE gc = *g; // this is really slow!
BYTE rc = *r; // this is really slow!

}
}

谢谢!

最佳答案

不应该 - 除非您在 8086 上执行此操作,否则 640x480 不可能花费 0.5 秒。是否有其他代码没有显示?目标内存目前没有去任何地方

ps 看一下 cvCvtColor() 它使用优化的 SSE2/SIMD 指令来执行此操作

关于C++ 取消引用字符指针(图像数组)非常慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4948215/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com