• OpenCV学习笔记7_ImageToBGR_彩色图像三通道转化成BGR3幅单通道图像


    ImageToBGR_彩色图像三通道转化成BGR3幅单通道图像

    ImageToBGR.c  采用指针偏移

    #include "stdafx.h"
    
    #include "cv.h"
    #include "highgui.h"
    #include "cxcore.h"
    
    int main()
    {
        IplImage* img;
        img = cvLoadImage("E:\\TempDataForDebug\\tomato.jpg");
    
        IplImage* b_img;
        IplImage* g_img;
        IplImage* r_img;
    
        b_img = cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,1);
        g_img = cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,1);
        r_img = cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,1);
    
    
        int y,x;
    
        for (y = 0; y<img->height; y++)
        {
            unsigned char* prow = (unsigned char*)(img->imageData+y*img->widthStep);
            unsigned char* brow = (unsigned char*)(b_img->imageData+y*b_img->widthStep);
            unsigned char* grow = (unsigned char*)(g_img->imageData+y*g_img->widthStep);
            unsigned char* rrow = (unsigned char*)(r_img->imageData+y*r_img->widthStep);
    
            for (x = 0; x<img->width; x++)
            {
                brow[x] = prow[3*x + 0];
                grow[x] = prow[3*x + 1];
                rrow[x] = prow[3*x + 2];
            }
        }
        cvNamedWindow("1");
        cvShowImage("1",img);
    
        cvNamedWindow("b");
        cvShowImage("b",b_img);
        cvNamedWindow("g");
        cvShowImage("g",g_img);
        cvNamedWindow("r");
        cvShowImage("r",r_img);
    
        cvWaitKey(0);
    
        return 0;
    }

  • 相关阅读:
    hadoop编程问题
    poj2760:数字三角形
    poj1201:Intervals
    差分约束
    poj1033:Defragment
    poj1089:Intervals
    poj2251:Dungeon Master
    天天向上的力量 III
    整数逆位运算
    星号三角形 I
  • 原文地址:https://www.cnblogs.com/gaoquanning/p/3071007.html
Copyright © 2020-2023  润新知