Last updated on 2022年3月24日
联动
记录一下自己找颜色转换函数的过程
最开始找到颜色转换函数cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )是在文件modules\imgproc\src\color.cpp,相关部分代码如下
case COLOR_RGB2YUV_YV12: case COLOR_BGR2YUV_YV12: case COLOR_RGBA2YUV_YV12: case COLOR_BGRA2YUV_YV12:
case COLOR_RGB2YUV_IYUV: case COLOR_BGR2YUV_IYUV: case COLOR_RGBA2YUV_IYUV: case COLOR_BGRA2YUV_IYUV:
cvtColorBGR2ThreePlaneYUV(_src, _dst, swapBlue(code), uIndex(code));
break;
于是在modules\imgproc\src\color_yuv.dispatch.cpp找到函数cvtColorBGR2ThreePlaneYUV( InputArray _src, OutputArray _dst, bool swapb, int uidx)
void cvtColorBGR2ThreePlaneYUV( InputArray _src, OutputArray _dst, bool swapb, int uidx)
{
CvtHelper< Set<3, 4>, Set<1>, Set<CV_8U>, TO_YUV > h(_src, _dst, 1);
hal::cvtBGRtoThreePlaneYUV(h.src.data, h.src.step, h.dst.data, h.dst.step, h.src.cols, h.src.rows,
h.scn, swapb, uidx);
}
在同样的文件下面找到函数
void cvtBGRtoThreePlaneYUV(const uchar * src_data, size_t src_step,
uchar * dst_data, size_t dst_step,
int width, int height,
int scn, bool swapBlue, int uIdx)
{
CV_INSTRUMENT_REGION();
CALL_HAL(cvtBGRtoThreePlaneYUV, cv_hal_cvtBGRtoThreePlaneYUV, src_data, src_step, dst_data, dst_step, width, height, scn, swapBlue, uIdx);
CV_CPU_DISPATCH(cvtBGRtoThreePlaneYUV, (src_data, src_step, dst_data, dst_step, width, height, scn, swapBlue, uIdx),
CV_CPU_DISPATCH_MODES_ALL);
}
好家伙这么多层...然后在modules\imgproc\src\hal_replacement.hpp找到函数定义
#define cv_hal_cvtBGRtoThreePlaneYUV hal_ni_cvtBGRtoThreePlaneYUV
这是一个硬件交互的hal函数,我们无法对其进行修改
于是在本文章所指的目标项目中,我采取了绕过opencv的硬件函数,重写了颜色转换代码部分来达到这一目的。
具体的改写我放在了GitHub项目中。
Be First to Comment