OpenCV中使用forEach进行并行像素访问
之前对forEach用法一直不懂,后来发现Mat类的forEach方法接受一个函数操作符。
void cv::Mat::forEach (const Functor &operation)
需要先定义一个函数对象:
struct RGB2LABOperator
{
void operator()(Pixel &pixel, const int* position)const
{
RGB2LAB(pixel,position);
}
};
直接调用结构体函数:
typedef Point3_<uchar> Pixel;
Mat pic = imread("1.jpg");
pic.forEach<Pixel>(RGB2LABOperator());