使用opencV从RGB图像中提取一通道图像
我正在使用 QT 和 OpenCV,我有一个需要提取的正方形,但我需要使用从 RGB 到一个通道(基本上是红色)的转换。我们非常欢迎任何建议,请随时建议使用哪些功能。提前致谢。
I'm working with QT and OpenCV, I have this square that I need to extract but I need to use conversion from RGB to one channel (RED basically). Any advice will be more than welcome, please feel free to advice which functions to use. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
另一种方法是使用 extractChannel:
这将提取来自
图像
的第三个通道并将结果保存在通道
中。也可以使用extractImageCOI
和mixChannels
提取特定通道。Another way is to use extractChannel:
This will extract the 3rd channel from
image
and save the result inchannel
. A particular channel can be extracted as well withextractImageCOI
andmixChannels
.我认为
cvSplit
就是您正在寻找的(文档)。例如,您可以使用它将 RGB 拆分为 R、G 和 B:请注意,您需要注意顺序;确保原始图像实际上按 R、G、B 顺序排列(很有可能是 B、G、R)。
I think
cvSplit
is what you're looking for (docs). You can use it, for example, to split RGB into R, G, and B:Note you'll need to be careful about the ordering; make sure that the original image is actually ordered as R, G, B (there's a decent chance it's B, G, R).
由于它被标记为
qt
我将给出一个 C++ 答案。在 OpenCV 2.4.5 上测试
Since this is tagged
qt
I'll give a C++ answer.Tested on OpenCV 2.4.5
据我所知,
可以调用,其中 src 是多通道源图像,第三个参数表示目标中的通道数。因此,您可以在 OpenCV 中执行此操作并在 Qt 界面上显示图像。
另一方面,您可以使用适当的 split() 方法将通道拆分为单独的单通道数组。
http://opencv.willowgarage.com/documentation/cpp/core_operations_on_arrays.html#split
As far as I know a call to,
Can do that, where src is the multi channel source image and the third parameter represents the number of channels in the destination. So, you can do that in OpenCV and display the image on your Qt interface.
On the other hand, you can split the channels into separate single channel arrays using appropriate split() method.
http://opencv.willowgarage.com/documentation/cpp/core_operations_on_arrays.html#split