我正在關注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