OpenCV图像操作,缩放,旋转等

#include  <cv.h>
#include  <highgui.h>
#include  <stdio.h>
#pragma comment(lib, "cv.lib")
#pragma comment(lib, "cxcore.lib")
#pragma comment(lib, "highgui.lib")

char name0[] = "lena.bmp";

int main_1()
{
	IplImage* imagen = NULL;
	imagen = cvLoadImage(name0,1);
	int px = 200;
	int py = 400;
	IplImage *resized = cvCreateImage(cvSize(px, py),IPL_DEPTH_8U, 3);
	cvResize(imagen, resized, CV_INTER_LINEAR);
	cvNamedWindow("test");
	cvShowImage("test", resized);
	cvWaitKey(0);
	cvDestroyAllWindows();
	cvReleaseImage(&imagen);
	cvReleaseImage(&resized);
	return 0;
}
int main_2()
{
	IplImage* imagen = NULL;
	imagen = cvLoadImage(name0,1);
	IplImage *rotated = cvCreateImage(cvGetSize(imagen), IPL_DEPTH_8U, imagen->nChannels);
	CvPoint2D32f center;
	int angle = 30;
	CvMat *mapMatrix = cvCreateMat(2,3,CV_32FC1);
	center.x=160;
	center.y=120;
	cv2DRotationMatrix(center,angle,1.0,mapMatrix);
	cvWarpAffine(imagen, rotated, mapMatrix, CV_INTER_LINEAR + CV_WARP_FILL_OUTLIERS, cvScalarAll(0));
	cvNamedWindow("origen");
	cvShowImage("origen", imagen);
	cvNamedWindow("resultado");
	cvShowImage("resultado",rotated);
	cvWaitKey(0);
	cvDestroyAllWindows();
	cvReleaseImage(&imagen);
	cvReleaseImage(&rotated);
	cvReleaseMat(&mapMatrix);
	return 0;
}
int main_3(int argc, char** argv)
{
	IplImage* src;
	src = cvLoadImage(name0);
	IplImage* dst = cvCloneImage(src);
	int angle = -25;
	float m[6];
	CvMat M = cvMat(2, 3, CV_32F, m);
	int w = src->width;
	int h = src->height;
	m[0] = (float)(cos(-angle*2*CV_PI/180.));
	m[1] = (float)(sin(-angle*2*CV_PI/180.));
	m[2] = w * 0.5f;
	m[3] = -m[1];
	m[4] = m[0];
	m[5] = h*0.5f;
	cvGetQuadrangleSubPix(src, dst, &M);
	cvNamedWindow("origen");
	cvShowImage("origen", src);
	cvNamedWindow("resultado");
	cvShowImage("resultado", dst);
	cvWaitKey(0);
	cvDestroyAllWindows();
	cvReleaseImage(&dst);

	cvReleaseImage(&src);
	return 0;
}

int main()
{
	IplImage* src;
	IplImage* colorThresh;
	IplImage* gray;
	IplImage* grayThresh;

	int threshold = 120;
	int maxValue = 255;
	int thresholdType = CV_THRESH_BINARY;

	src = cvLoadImage(name0, 1);
	colorThresh = cvCloneImage( src );
	gray=cvCreateImage( cvSize(src->width, src->height), IPL_DEPTH_8U, 1 );

	cvCvtColor( src, gray, CV_BGR2GRAY );

	grayThresh = cvCloneImage( gray );

	cvNamedWindow( "src", 1 );
	cvShowImage( "src", src );
	cvNamedWindow( "gray", 1 );
	cvShowImage( "gray", gray );
	cvThreshold(src, colorThresh, threshold, maxValue, thresholdType); 

	cvThreshold(gray, grayThresh, threshold, maxValue, thresholdType);

	cvNamedWindow( "colorThresh", 1 );

	cvShowImage( "colorThresh", colorThresh );
	cvNamedWindow( "grayThresh", 1 );

	cvShowImage( "grayThresh", grayThresh );
	cvWaitKey(0);
	cvDestroyWindow( "src" );
	cvDestroyWindow( "colorThresh" );
	cvDestroyWindow( "gray" );
	cvDestroyWindow( "grayThresh" );
	cvReleaseImage( &src );
	cvReleaseImage( &colorThresh );
	cvReleaseImage( &gray ); 
	cvReleaseImage( &grayThresh ); 
	return 0;
}

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值