opencv中Bayer 图像到RGB图像装换的问题

博客探讨了在OpenCV中如何将Bayer图像转换为RGB图像的问题。Bayer图像是单通道图像,通过设置imread参数为0或-1避免默认的三通道读取。cvtColor函数用于将单通道Bayer图像转换为三通道图像。文章介绍了Bayer图案的基本概念,包括图像传感器的工作原理,Bayer图案的排列方式,以及如何通过不同算法将Bayer图像转换为RGB图像。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在将bayer图像转换成为rgb的时候遇到的问题

Mat bayer = imread("/home/pan/Desktop/data/Testaufbau_Ecoflac153.tif",-1);
    Mat bayer2rgb;
    bayer2rgb.create(bayer.rows,bayer.cols,CV_8UC3);
    cvtColor(bayer,bayer2rgb,CV_BayerRG2BGR);
    vector<Mat> difChan;
    split(bayer2rgb,difChan);
//    imshow("Bayer Pattern",difChan[0]);
    imwrite("img_b.jpg",difChan[0]);
    imwrite("img_r.jpg",difChan[1]);
    imwrite("img_g.jpg",difChan[2]);

一直解决不了的问题出现在imread的使用上。

bayer图像是 one channel的图像,

如果简单的用imread,用defualt的参数的话,读出来的是3 channels的matrix。

而 cvtColor(source, destination, CV_BayerRG2BGR) 是将one channel 转换成 3 channel 图像的。

解决办法就是把imread 的参数设为0 或者 -1

此处的bayer pattern filter 需要从camera处获取


具体bayer pattern 介绍如下

copy 自:http://www.tldp.org/HOWTO/libdc1394-HOWTO/concepts.html

4.6. How to get color images: Bayer Pattern Concepts

The image grabbed by the sample code in the previous section is not colored (we have intentionally used the words "not colored," since the image is not gray-sc

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值