图像镜像

来源:互联网 发布:百度云 for mac 编辑:程序博客网 时间:2024/05/01 04:55
/************************************************************************
* 对图像做镜像
* 2013/12/11
/************************************************************************/


#include "opencv2/imgproc/imgproc.hpp"
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/core.hpp>
#include <stdio.h>
#include <iostream>


using namespace cv;
using namespace std;




#define  CAPTURE


int main()
{
#ifdef CAPTURE
IplImage* left_frame;//左边图像
//IplImage* right_frame;//右边图像


CvCapture* capture0 = cvCreateCameraCapture( 0 );
//CvCapture* capture1 = cvCreateCameraCapture( 1 );  


for (int i=0;i<30;i++)
{
left_frame = cvQueryFrame( capture0 );
}

int width = left_frame->width;
int height = left_frame->height;


#else
Mat img = imread("m1.jpg");
int width = img.cols;
int height = img.rows;
#endif


Mat img;
int64 t;
while (1)
{
t = getTickCount();
left_frame = cvQueryFrame( capture0 );
img = left_frame;


imshow("init",img);


//src = src*1.3;
//right_frame = cvQueryFrame(capture1);
//Mat src2(right_frame);




//两个图像融合为一个
//Mat sss(MAX(left_frame->height,right_frame->height),right_frame->width+left_frame->width,CV_8UC3);
//cv::Mat half(sss,cv::Rect(0,0,left_frame->width,left_frame->height));
//src.copyTo(half);
//cv::Mat right_half(sss,cv::Rect(src.cols,0,src2.cols,src2.rows));
//src2.copyTo(right_half);


//int centerX=width>>1;
//int centerY=heigh>>1;


int tempb,tempg,tempr;




for (int y=1;y<height-1;y++)
{
uchar* imgP=img.ptr<uchar>(y);


for (int x=0;x<width/2;x++)
{
tempb=imgP[3*x];
tempg=imgP[3*x+1];
tempr=imgP[3*x+2];




imgP[3*x] = imgP[3*(width-x)];
imgP[3*x+1] = imgP[3*(width-x)+1];
imgP[3*x+2] = imgP[3*(width-x)+2];


imgP[3*(width-x)] = (uchar)tempb;
imgP[3*(width-x)+1] = (uchar)tempg;
imgP[3*(width-x)+2] = (uchar)tempr;


}
}


imshow("result",img);


cout << (getTickCount()-t)*1.0/getTickFrequency() << endl;
waitKey(33);
}


}
0 0
原创粉丝点击