gpt4 book ai didi

c++ - 使用 Open CV 和 C++ 将彩色图像分成三个 channel ?

转载 作者:太空宇宙 更新时间:2023-11-03 22:29:25 26 4
gpt4 key购买 nike

我是 Open CV 的新手,所以如果我的问题听起来很愚蠢,请原谅我。因此,我正在研究使用 split 函数将 BGR channel 拆分为各个 channel 的新概念。我正在阅读这篇文章(http://answers.opencv.org/question/37132/i-want-to-split-and-show-r-b-g-pictures-why-does-it-not-work/),但我无法理解代码。所以,任何人都可以向我解释以下代码行,因为我真的很想了解这个概念。

create blue channel 部分我完全没看懂。谁能给我解释一下?

src = imread("pic.png");
vector<mat> spl(3);
split(src,spl);

Mat empty_image = Mat::zeros(src.rows, src.cols, CV_8UC1);


Mat result_blue(src.rows, src.cols, CV_8UC3); // notice the 3 channels here!

// Create blue channel
Mat in1[] = { spl[0], empty_image, empty_image };
int from_to1[] = { 0,0, 1,1, 2,2 };
mixChannels( in1, 3, &result_blue, 1, from_to1, 3 );

imshow("blue image", result_blue);

最佳答案

代码所做的是将彩色图像拆分为 3 个灰度图像,并保持红色、绿色和蓝色的强度。

然后代码采用蓝色 channel 并构建一个红色和绿色为零的彩色图像,这样当您显示它时,它会显示为蓝色,而不仅仅是灰度。

关于c++ - 使用 Open CV 和 C++ 将彩色图像分成三个 channel ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29417256/

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