summary27 opencv入门

1.opencv入门

安装和配置环境:

opencv下载后,解压到一个目录下。

在系统环境变量中path中添加opencv安装路径:C:\opencv\opencv\build\x64\vc15\bin;

在vs2017中配置:(Debug 条件下)

项目-->属性-->VC++ Directories--> include Directories : C:\opencv\opencv\build\include;

-->library Directories:C:\opencv\opencv\build\x64\vc15\lib;-->Linker-->Input-->Additional Dependencies: opencv_world401d.lib;

(Release条件下):

先按照上面的debug配置,将Linker里的配置改一下:Linker-->Input-->Additional Dependencies: opencv_world401.lib;

测试程序:

#include <iostream>
#include <stdio.h>
#include "stdlib.h"
#include <tchar.h>
#include <opencv2/opencv.hpp>

using namespace std;
using namespace cv;

int main()
{
	const char* imagename = "1.jpg";

	//从文件中读入图像
	Mat img = imread(imagename);

	//如果读入图像失败
	if (img.empty())
	{
		fprintf(stderr, "Can not load image %s\n", imagename);
		return -1;
	}

	//显示图像
	imshow("image", img);

	//此函数等待按键,按键盘任意键就返回
	waitKey();

	return 0;
}

 运行:

 2.opencv有些函数:

cv::normalize():归一化

函数原型:

void normalize(InputArray src, OutputArray dst, double alpha=1, double beta=0, int norm_type=NORM_L2, int dtype=-1, InputArray mask=noArray() )

该函数归一化输入数组使它的范数或者数值范围在一定的范围内。

Parameters:

src : 输入数组

dst :输出数组,支持原地运算

alpha:

    range normalization模式的最小值

beta:

    range normalization模式的最大值,不用于norm normalization(范数归一化)模式。

normType:

    归一化的类型,可以有以下的取值:

    NORM_MINMAX:数组的数值被平移或缩放到一个指定的范围,线性归一化,一般较常用。

    NORM_INF: 此类型的定义没有查到,根据OpenCV 1的对应项,可能是归一化数组的C-范数(绝对值的最大值)

    NORM_L1 :  归一化数组的L1-范数(绝对值的和)

    NORM_L2: 归一化数组的(欧几里德)L2-范数

dtype:

    dtype为负数时,输出数组的type与输入数组的type相同;

否则,输出数组与输入数组只是通道数相同,而tpye=CV_MAT_DEPTH(dtype).

mask:

    操作掩膜,用于指示函数是否仅仅对指定的元素进行操作。
 

cv::imread():读入图像

函数原型:

Mat imread( const String& filename, int flags = IMREAD_COLOR );

第一个参数是图片的绝对地址 

第二个参数表示图片读入的方式(flags可以缺省,缺省时flags=1,表示以彩色图片方式读入图片)

 flags>0时表示以彩色方式读入图片

flags=0时表示以灰度图方式读入图片

flags<0时表示以图片的本来的格式读入图片

 

cv::getOptimalDFTSize():

函数原型:

int cv::getOptimalDFTSize (int vecsize)

#include <opencv2/core.hpp>

Returns the optimal DFT size for a given vector size.

 

cv::copyMakeBorder():

void cv::copyMakeBorder(InputArray src,

                                          OutputArray dst,

                                           int top,

                                           int bottom,

                                           int left,

                                           int right,

                                           int borderType,

                                            const Scalar & value=scalar()

                                       )

#include <opencv2/core.hpp>

Forms a border around an image.

Parameters:

srcSource image.
dstDestination image of the same type as src and the size Size(src.cols+left+right, src.rows+top+bottom) .
top 
bottom 
left 
rightParameter specifying how many pixels in each direction from the source image rectangle to extrapolate. For example, top=1, bottom=1, left=1, right=1 mean that 1 pixel-wide border needs to be built.
borderTypeBorder type. See borderInterpolate for details.
valueBorder value if borderType==BORDER_CONSTANT

 cv::waitKey():

Waits for a pressed key.

函数原型:

int cv::waitKey (int delay = 0)

参数:

delay

Delay in milliseconds. 0 is the special value that means "forever".

头文件:

#include <opencv2/highgui.hpp>

The function waitKey waits for a key event infinitely (when delay≤0 ) or for delay milliseconds, when it is positive. Since the OS has a minimum time between switching threads, the function will not wait exactly delay ms, it will wait at least delay ms, depending on what else is running on your computer at that time. It returns the code of the pressed key or -1 if no key was pressed before the specified time had elapsed.

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值