opencv基本图像操作

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

#include "stdafx.h"
#include <iostream>
#include "cv.h"
#include "highgui.h"

using namespace std;

void SmoothImage(IplImage* image)//平滑函数
{
	cvNamedWindow("Smooth_in");
	cvNamedWindow("Smooth_out");
	cvShowImage("Smooth_in",image);

	IplImage* out = cvCreateImage(cvGetSize(image),IPL_DEPTH_8U,3);
	cvSmooth(image,out,CV_BLUR,32,32);//平滑函数,后面两个参数是窗口大小
	cvShowImage("Smooth_out",out);

	cvReleaseImage(&out);

	cvWaitKey(0);
	cvDestroyAllWindows();
}

void doPyrDown(IplImage* in, int filter = IPL_GAUSSIAN_5x5)//图像缩小为一半
{
	//Best to make sure input image is divisible by two.
	assert(in->width%2 == 0 && in->height%2 == 0);
	IplImage* out = cvCreateImage(cvSize(in->width/2 , in->height/2) , in->depth , in->nChannels);
	cvPyrDown(in , out);

	cvNamedWindow("PyrDown_out");
	cvShowImage("PyrDown_out",out);
	cvReleaseImage(&out);

	cvWaitKey(0);
	cvDestroyAllWindows();
	//return out;


}

void doCanny(IplImage* in , double lowThresh , double highThresh , double aperture)
{
	IplImage* out = cvCreateImage(cvSize(in->width,in->height) , IPL_DEPTH_8U , 1);
	if(in->nChannels != 1)
	{
		//cout<<"error! unsupported format or combination of formats() in unknown function"<<endl;
		//return;//canny only handles gray scale image

		//若不是灰度图,直接转化成灰度图
		IplImage* gray =  cvCreateImage(cvGetSize(in), IPL_DEPTH_8U, 1);  
	    cvCvtColor(in, gray, CV_BGR2GRAY);
		out = gray;
	}
		

	cvCanny(in , out , lowThresh , highThresh , aperture );

	cvNamedWindow("Canny_out");
	cvShowImage("Canny_out",out);
	cvReleaseImage(&out);

	cvWaitKey(0);
	cvDestroyAllWindows();


}

int _tmain(int argc, _TCHAR* argv[])
{
	IplImage* image = cvLoadImage("lena.jpg");
	//SmoothImage(image);
	//doPyrDown(image);
	doCanny(image ,10 , 100 , 3 );



	system("pause");
	return 0;
}


 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值