opecv IplImage加载图像

<pre name="code" class="cpp">//
//  main.cpp
//  hw01
//  use OPENCV IplImage type to load and bright image.
//
//  Created by 李大龙 on 15/3/16.
//  Copyright (c) 2015年 李大龙. All rights reserved.
//

#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <fstream>
using namespace std;

//图片色彩明亮化:创建颜色查询列表
int a[256];
void brightness(int brightness_number){
    for (int i = 0; i<256; i++) {
        if (i + brightness_number < 256) {
            a[i] = i + 50;
        }else a[i] = 255;
    }
}

int main(int argc, const char * argv[])
{
    //get the image from the directed path
    IplImage* img = cvLoadImage("20131007102558_yYSNe.jpg", 1);
    brightness(70);
    IplImage *imgBuf = cvCreateImage(cvGetSize(img), IPL_DEPTH_8U, 3);   //通道为3
    for (int i = 0; i < img->height; i++)
    {
        for(int j = 0; j < img->width; j++)
        {
            int b = ((uchar *)(img->imageData +  i * img->widthStep ))[j * img->nChannels + 0];   //改变该像素B的颜色分量
            int g = ((uchar *)(img->imageData +  i * img->widthStep ))[j * img->nChannels + 1];   //改变该像素G的颜色分量
            int r = ((uchar *)(img->imageData +  i * img->widthStep ))[j * img->nChannels + 2];   //改变该像素R的颜色分量
            ((uchar *)(img->imageData +  i * img->widthStep ))[j * img->nChannels + 0] = a[b];
            ((uchar *)(img->imageData +  i * img->widthStep ))[j * img->nChannels + 1] = a[g];
            ((uchar *)(img->imageData +  i * img->widthStep ))[j * img->nChannels + 2] = a[r];
        }
    }
    cvSaveImage("test1.jpg", img);

    cvNamedWindow("picture",1);
    cvShowImage("picture", img);
    cvWaitKey(0);
    cvReleaseImage(&img);
    cvDestroyWindow("picture");
    return 0;
}


 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值