打开CV水彩滤镜。 (遍历图像的像素)

时间:2016-03-30 14:47:13

标签: c++ opencv

我试图按照这个伪代码在Open CV中实现水彩滤镜。 http://supercomputingblog.com/graphics/oil-painting-algorithm/

我之前使用此方法在带有画布的javascript中实现了效果,因为我可以迭代像素但是我不知道如何使用Open CV来做到这一点。

Mat im = imread(...); //input image
Mat paint; // output after processing
for(int i = 0; i < im.rows; i++)
{
    for (int j = 0; j < im.cols; j++) //for each pixel
    {
        //here I need a reference to the pixel colour from im
    }
}

我试图使用:

im.at<uchar>(i,j)

然而,这给了我大约350的值,这对我来说是rgb通道的累积(我认为是一个多通道阵列)。所以我试着像这样分开它:

vector<Mat> three_channels;
split(im, three_channels);

但它只给了我3次相同的价值。有什么建议吗?

2 个答案:

答案 0 :(得分:0)

我最终只是访问它们,因此:

int r = im.at<cv::Vec3b>(y,x)[0];
int g = im.at<cv::Vec3b>(y,x)[1];
int b = im.at<cv::Vec3b>(y,x)[2];
正如上一个问题的答案中提到的那样。

答案 1 :(得分:-1)

大多数情况下,颜色只是8位组合而不是数组,因此您需要使用蒙版来操作它们。

short red = (color >> 16) & 0xFF;
short green = (color >> 8) & 0xFF;
short blue = (color) & 0xFF;

(通过how to color mask in c