c++ - 分离颜色成分

标签 c++ c opencv

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

相关文章:

c++ - 如何为我的 C++/Win32 程序禁用程序兼容性助手?

C++风格: Stroustrup' s placement of pointer asterisks

c - STM32F407 SPI 仅接收 0xFF (255) 或 0

python - 使用opencv检测角的角度

xml - OpenCV级联性能: valid XML error

c++ - 如何使用 C++ 从 HTML 中提取文本?

c++ - Python C++ API : How to access public class attribute?

c - 使用gdb调试时未找到调试符号

c - K&R 练习 1.9 - 无限循环编程

linux - 使用 ubuntu 12.04 LTS 和 opencv 获取 kinect 深度图像的距离