OpenCV遍历访问图像的每一个元素

本文介绍使用C++和OpenCV进行图像处理的基本方法,包括加载图像、显示图像、修改图像像素等操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

// my8.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include "highgui.h"
#include "cv.h"
#include <iostream>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{

 IplImage* image = cvLoadImage("e:\\wali2.jpg");

 cvNamedWindow("s");

 //用指针指向图像的数据区头部
 uchar* pchar;
 int width = image->width; cout<<width<<endl;
 int heigh = image->height; cout<<heigh<<endl;
 int channel = image->nChannels;  cout<<channel<<endl;
 int widthStep = image->widthStep;  cout<<widthStep<<endl;


 int i,j;

 for(i=0; i<heigh; i++)
 {
  pchar = (uchar*) image->imageData +  i*widthStep;
        for (j=0; j<width; j++)
        {
   uchar* temp = pchar +j*channel;
   temp[0] -= 10; //通道B
      temp[1] -= 10; //通道G
   temp[2] -= 10; //通道R
        }
 }

 

    cvShowImage("s",image);
 cvWaitKey(0);
 cvReleaseImage(&image);
 cvDestroyWindow("s");
 
 

 return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值