我正在关注this发布以查找图像的颜色分量。我想我会从红色组件开始,然后着手其他组件。我写的代码如下。我没有使用Linux,我正在使用Windows。分离颜色分量
#include <opencv\cv.h>
#include <opencv2\imgproc\imgproc.hpp>
#include <opencv2\highgui\highgui.hpp>
#include <iostream>
#include <stdio.h>
using namespace std;
using namespace cv;
int main(int argc, char**argv)
{
IplImage* image=cvLoadImage("C:/Users/Administrator/Desktop/sample.png",1);
IplImage* red=cvCreateImage(cvSize(image->width, image->height), image->depth,image->nChannels);
uchar *pImg =(uchar*)image->imageData;
uchar *pRed=(uchar*)red->imageData;
for(int i=0;i<image->height;i++)
{
for(int j=0;j<image->width;j++)
{
red=pImg[i*image->widthStep + j*image->nChannels + 2];
pRed[i*image->widthStep + j*image->nChannels + 2]=red;
}
}
namedWindow("Display",1);
cvShowImage("Display",red);
waitKey(0);
return 0;
}
线条
red=pImg[i*image->widthStep + j*image->nChannels + 2];
pRed[i*image->widthStep + j*image->nChannels + 2]=red;
都出现了这样的错误:
A value of type uchar cannot be assigned to an entity of the type IplImage
我要去哪里错了?
什么将split()返回?例如,我在图像中有2个方格,一个是红色,另一个是蓝色。现在我想要输出只有红色可见。将split()能够做到这一点?我真的不知道这个功能。你能回答并给我一个能给我结果的图像吗? –
对不起,我删除了评论,并给出了如何拆分频道的答案。 – William