OpenCV笔记(五)

一个颜色衰减的小程序:

#include<opencv2/opencv.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<iostream>
using namespace cv;
using namespace std;
int main(){
	double start1=static_cast<double>(getTickCount());
	Mat srcImage=imread("redflo.bmp");
	Mat dstImage=srcImage.clone();
	srcImage.copyTo(dstImage);
	//cout<<dstImage.isContinuous();
	for(int i=0;i<dstImage.rows;i++){
		for(int j=0;j<srcImage.cols;j++){
			dstImage.at<Vec3b>(i,j)[0]=dstImage.at<Vec3b>(i,j)[0]/60*60;
			dstImage.at<Vec3b>(i,j)[1]=dstImage.at<Vec3b>(i,j)[1]/60*60;
			dstImage.at<Vec3b>(i,j)[2]=dstImage.at<Vec3b>(i,j)[2]/60*60;
		}
	}
	imshow("1",srcImage);
	imshow("2",dstImage);
	cout<<(getTickCount()-start1)/getTickFrequency()<<"ms"<<endl;
	//利用LUT()查找表实现
	double start2=static_cast<double>(getTickCount());
	Mat lookUpTable(1,256,CV_8U);
	for(int value=0;value<256;value++){
		lookUpTable.at<uchar>(0,value)=value/60*60;
	}
	LUT(srcImage,lookUpTable,dstImage);
	imshow("3",srcImage);
	imshow("4",dstImage);
	cout<<(getTickCount()-start1)/getTickFrequency()<<"ms"<<endl;
	waitKey(0);
}

通道分离和合并:

#include<opencv2/opencv.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<iostream>
using namespace cv;
using namespace std;
int main(){
	Mat srcImage=imread("redflo.bmp");
	Mat dstImage;
	vector<Mat>channels;
	split(srcImage,channels);
	imshow("b",channels[0]);
	imshow("g",channels[1]);
	imshow("r",channels[2]);
	vector<Mat>channels2(3);
	channels2[0]=channels[0];
	channels2[1]=channels[1];
	channels2[2]=channels[0];
	merge(channels2,dstImage);
	imshow("rgb",dstImage);
	waitKey(0);
}
OpenCV笔记(五)_第1张图片

你可能感兴趣的:(OpenCV笔记(五))