Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/157.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 在opencv(c+;+;)中的所有像素上运行方法的最快方法是什么_C++_Opencv - Fatal编程技术网

C++ 在opencv(c+;+;)中的所有像素上运行方法的最快方法是什么

C++ 在opencv(c+;+;)中的所有像素上运行方法的最快方法是什么,c++,opencv,C++,Opencv,我在opencv中的每个像素上都有几个任务要做。我使用的构造如下: for(int row = 0; row < inputImage.rows; ++row) { uchar* p = inputImage.ptr(row); for(int col = 0; col < inputImage.cols*3; col+=3) { int blue=*(p+col); //points to each

我在opencv中的每个像素上都有几个任务要做。我使用的构造如下:

for(int row = 0; row < inputImage.rows; ++row)
    {
        uchar* p = inputImage.ptr(row);
        for(int col = 0; col < inputImage.cols*3; col+=3)
        {
            int blue=*(p+col);  //points to each pixel B,G,R value in turn assuming a CV_8UC3 colour image
            int green=*(p+col+1);
            int red=*(p+col+2);
            // process pixel            }

    }
const uchar *ptr = inputImage.ptr<uchar>(0);

for (size_t i=0; i<inputImage.rows*inputImage.cols; ++i){
    int blue  = ptr[3*i];
    int green = ptr[3*i+1];
    int red   = ptr[3*i+2];

    // process pixel 
}
for(int行=0;行
这是工作,但我想知道是否有任何更快的方法来做到这一点?此解决方案不使用任何SIMD或OpenCV的任何并行处理


在opencv中对图像的所有像素运行方法的最佳方式是什么?

如果
Mat
是连续的,即矩阵元素连续存储,每行末尾没有间隙,可以使用
Mat::isContinuous()
引用,则可以将它们视为长行。因此,您可以这样做:

for(int row = 0; row < inputImage.rows; ++row)
    {
        uchar* p = inputImage.ptr(row);
        for(int col = 0; col < inputImage.cols*3; col+=3)
        {
            int blue=*(p+col);  //points to each pixel B,G,R value in turn assuming a CV_8UC3 colour image
            int green=*(p+col+1);
            int red=*(p+col+2);
            // process pixel            }

    }
const uchar *ptr = inputImage.ptr<uchar>(0);

for (size_t i=0; i<inputImage.rows*inputImage.cols; ++i){
    int blue  = ptr[3*i];
    int green = ptr[3*i+1];
    int red   = ptr[3*i+2];

    // process pixel 
}
constuchar*ptr=inputImage.ptr(0);

对于(size_t i=0;我编写一个gpu函数来处理gpu内的曲面?