Matlab与Opencv的通道数
我使用的是一幅图像,我在matlab中使用imfinfo获得的图像细节如下:Matlab与Opencv的通道数,opencv,Opencv,我使用的是一幅图像,我在matlab中使用imfinfo获得的图像细节如下: Filename: 'dog.jpg' FileModDate: '25-Mar-2011 15:54:00' FileSize: 8491 Format: 'jpg' FormatVersion: '' Width:
Filename: 'dog.jpg'
FileModDate: '25-Mar-2011 15:54:00'
FileSize: 8491
Format: 'jpg'
FormatVersion: ''
Width: 194
Height: 206
BitDepth: 24
ColorType: 'truecolor'
FormatSignature: ''
NumberOfSamples: 3
CodingMethod: 'Huffman'
CodingProcess: 'Sequential'
Comment: {}
NewSubFileType: 0
BitsPerSample: [8 8 8]
PhotometricInterpretation: 'RGB'
ImageDescription: [1x13 char]
StripOffsets: 154
SamplesPerPixel: 3
RowsPerStrip: 206
StripByteCounts: 119892
它显示通道数=3(NumberOfSamples:3),但当我使用下面的代码在opencv中找到通道数时,我得到通道数=1
Mat img = imread("dog.jpg", 0);
printf("No. of Channels = %d\n", img.channels());
为什么会这样??请解释。正如@berak所评论的,通过使用
0
作为的第二个参数,您正在将其作为灰度图像加载。尝试通过向其传递负值0
来加载它,以返回3通道彩色图像
比如:
Mat img=imread(“dog.jpg”,-1);//imread(“dog.jpg”,0);//末端的0强制8位灰度。请尝试使用1强制执行bgr,或使用-1表示“原样”,谢谢你,贝拉克。我是初学者,今天刚刚开始使用Opencv,非常感谢您的帮助。再次感谢,不客气。只需保留一个指向handy的链接;)
Mat img = imread("dog.jpg", -1); // <0 Return the loaded image as is
^^