我正在关注 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
我哪里错了?
最佳答案
使用 C++:
cv::Mat myImage;
myImage=imread("myImage.jpg");
std::vector<cv::Mat> channels;
cv::split(myImage,channels);
imshow("Red Channel",channels[2]);
关于c++ - 分离颜色成分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21183766/