zoukankan      html  css  js  c++  java
  • 【学习opencv第六篇】图像的反转操作

    考试终于完了,现在终于有时间可以继续学习这个了。写这篇博客主要是因为以前一直搞不清楚图像数据到底是怎么存储的,以及这个step到底是什么,后来查了一下才知道原来step就是数据行的长度。。

    #include "stdafx.h"
    #include <highgui.h>
    #include <math.h>
    #include <cv.h>
    using namespace std;
    int main()
    {
    	IplImage* sourceImage;     
    	sourceImage= cvLoadImage("Hough.jpg",0);   
    	/*以灰度图像读入	*/
    	if(!sourceImage)
    		return -1;
    	//cout<<"successfully"<<endl;
    	cvNamedWindow("sourceImage",0);
    	cvShowImage("sourceImage",sourceImage);
    	char* data;
    	int step= sourceImage->widthStep;
    	int channels = sourceImage->nChannels;
    	data = (char*)sourceImage->imageData;
    	for(int i=0;i<sourceImage->height;i++)
    		for(int j=0;j<sourceImage->width;j++)
    			for(int h=0;h<channels;h++)
    			data[i*step+j*channels+h]=255-data[i*step+j*channels+h];
    	cvNamedWindow("Reverse",0);
    	cvShowImage("Reverse",sourceImage);
    	cvWaitKey(-1);
    	cvDestroyWindow("Reverse");
    	cvDestroyWindow("sourceImage");
    	return 0;
    }

    Reference:

    《学习opencv》

  • 相关阅读:
    linux学习之uniq
    hive学习05 参数设置
    【python】调用sm.ms图床api接口,实现上传图片并返回url
    【python】列表与数组之间的相互转换
    更新yum源
    要把RAID5创建卷组
    named-checkconf -z /etc/named.conf
    function_exists
    trigger_error
    命名空间
  • 原文地址:https://www.cnblogs.com/snake-hand/p/3151257.html
Copyright © 2011-2022 走看看