2015-05-03 14:55 501人阅读 评论(6) 收藏 举报
 分类:
C#

版权声明:本文为博主原创文章,未经博主允许不得转载。

 

目录(?)[+]

 

前言

之前用OpenCV做过摄像机标定及矫正,现在平台换了,改用C#,就用EmguCV做一下,其实就是OpenCV的C#版。

在EmguCV中有两类摄像机标定的类,一个是CvInvoke类,一个是CameraCalibration类,两种标定效果差不多,只不过CvInvoke涉及的函数大多都是指针类型的,而C#对于指针的操作比较麻烦。本文是在CameraCalibration类的基础上完成摄像机标定,用CvInvoke类完成矫正图像。

函数说明

1、角点检测

  1. public static PointF[] FindChessboardCorners(
  2. Image<Gray, byte> image,
  3. Size patternSize,
  4. CALIB_CB_TYPE flags
  5. )


Parameters

image
Type: Emgu.CV.Image<Gray, Byte>Source chessboard view
patternSize
Type: System.Drawing.SizeThe number of inner corners per chessboard row and column
flags
Type: Emgu.CV.CvEnum.CALIB_CB_TYPEVarious operation flags

Return Value

Type: PointF[]The corners detected if the chess board pattern is found, otherwise null is returned

注:输入图像需是灰度图,检测之前角点需要开辟空间,如:

  1. cornersDetected = new PointF[nPoints];       //nPoints表示单幅图像角点总数
  2. cornersDetected = CameraCalibration.FindChessboardCorners(chessboardImage, patternSize,
  3. CALIB_CB_TYPE.ADAPTIVE_THRESH | CALIB_CB_TYPE.NORMALIZE_IMAGE);

2、标定函数

  1. public static double CalibrateCamera(
  2. MCvPoint3D32f[][] objectPoints,
  3. PointF[][] imagePoints,
  4. Size imageSize,
  5. IntrinsicCameraParameters intrinsicParam,
  6. CALIB_TYPE calibrationType,
  7. MCvTermCriteria termCriteria,
  8. out ExtrinsicCameraParameters[] extrinsicParams
  9. )




Parameters

objectPoints
Type: Emgu.CV.Structure.MCvPoint3D32f[][]The 3D location of the object points. The first index is the index of image, second index is the index of the point
imagePoints
Type: System.Drawing..::..PointF[][]The 2D image location of the points. The first index is the index of the image, second index is the index of the point
imageSize
Type: System.Drawing.SizeThe size of the image, used only to initialize intrinsic camera matrix
intrinsicParam
Type: Emgu.CV.IntrinsicCameraParametersThe intrisinc parameters, might contains some initial values. The values will be modified by this function.
calibrationType
Type: Emgu.CV.CvEnum.CALIB_TYPEcCalibration type
termCriteria
Type: Emgu.CV.Structure.MCvTermCriteriaThe termination criteria
extrinsicParams
Type: Emgu.CV.ExtrinsicCameraParameters[]The output array of extrinsic parameters.

Return Value

Type: DoubleThe final reprojection error注:objectPoints表示棋盘角点在世界坐标系下的坐标,有多少幅棋盘图像就应有多少角点坐标集,以物理尺寸为单位。imagePoints表示角点在图像中的坐标,以像素为单位。返回值是重投影误差。

3、映射矩阵求取

  1. public static void cvInitUndistortMap(
  2. IntPtr intrinsicMatrix,
  3. IntPtr distortionCoeffs,
  4. IntPtr mapx,
  5. IntPtr mapy
  6. )


Parameters

intrinsicMatrix
Type: System.IntPtrThe camera matrix (A) [fx 0 cx; 0 fy cy; 0 0 1]
distortionCoeffs
Type: System.ntPtrThe vector of distortion coefficients, 4x1 or 1x4 [k1, k2, p1, p2].
mapx
Type: System.IntPtrThe output array of x-coordinates of the map
mapy
Type: System.ntPtrThe output array of y-coordinates of the map

注:定义Matrix类的映射矩阵变量,其属性中包含Ptr,可以直接当指针用,如:

  1. private Matrix<float> mapx = new Matrix<float>(height, width);
  2. private Matrix<float> mapy = new Matrix<float>(height, width);

4、几何变换

  1. public static void cvRemap(
  2. IntPtr src,
  3. IntPtr dst,
  4. IntPtr mapx,
  5. IntPtr mapy,
  6. int flags,
  7. MCvScalar fillval
  8. )

Parameters

src
Type: System.ntPtr 
Source image
dst
Type: System.IntPtr 
Destination image
mapx
Type: System.IntPtr 
The map of x-coordinates (32fC1 image)
mapy
Type: System.ntPtr 
The map of y-coordinates (32fC1 image)
flags
Type: System.Int32 
A combination of interpolation method and the optional flag CV_WARP_FILL_OUTLIERS
fillval
Type: Emgu.CV.Structure.MCvScalar 
A value used to fill outliers

注:flags定义在 CvEnum下的 WARP枚举类型,调用: (int)WARP.CV_WARP_INVERSE_MAP

程序说明

基于EmguCV摄像机标定及矫正的软件界面如下:

如图所示,界面包含棋盘格信息设置,标定及矫正事件的实现等等。

矫正前后图像对比:

代码实现了从摄像头读取棋盘格图像或者从本地读取图像,图像个数有Imges指定,棋盘格大小有Square Size指定;然后成功检测到角点之后进行摄像头标定,保存角点值和摄像头内参数,通过Rectify按钮实现畸变矫正功能。为避免每次标定时都要检测角点,设置Read Corners按钮,读取角点(包含objectPoints和imagePoints),然后Start Calibrate实现标定。所有的数据都是保存到xml文件中,方便查看和提取。

基于EmguCV的摄像机标定及矫正的更多相关文章

  1. 机器视觉学习笔记(5)——基于OpenCV的单目摄像机标定

    本文CameraCalibrator类源代码来自于OpenCV2 计算机视觉编程手册(Robert Laganiere 著 张静 译) 强烈建议阅读机器视觉学习笔记(4)--单目摄像机标定参数说明之后 ...

  2. halcon摄像机标定

    摄像机标定程序: 注意:E:/calibration_image :为标定图像文件路径       'E:/calibration_description/caltab_123mm.descr:为标定 ...

  3. 相机标定过程(opencv) + matlab参数导入opencv + matlab标定和矫正

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 辛苦原创所得,转载请注明出处 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ...

  4. [zt]摄像机标定(Camera calibration)笔记

    http://www.cnblogs.com/mfryf/archive/2012/03/31/2426324.html 一 作用建立3D到2D的映射关系,一旦标定后,对于一个摄像机内部参数K(光心焦 ...

  5. [OpenCV-Python] OpenCV 中摄像机标定和 3D 重构 部分 VII

    部分 VII摄像机标定和 3D 重构 OpenCV-Python 中文教程(搬运)目录 42 摄像机标定 目标 • 学习摄像机畸变以及摄像机的内部参数和外部参数 • 学习找到这些参数,对畸变图像进行修 ...

  6. 【OpenCV】摄像机标定+畸变校正

      摄像机标定 本文目的在于记录如何使用MATLAB做摄像机标定,并通过OpenCV进行校正后的显示. 首先关于校正的基本知识通过OpenCV官网的介绍即可简单了解: http://docs.open ...

  7. 相机标定与矫正opencv+MATLAB

    博客转载自:http://blog.csdn.net/Loser__Wang/article/details/51811347 本文目的在于记录如何使用MATLAB做摄像机标定,并通过opencv进行 ...

  8. Matlab 摄像机标定+畸变校正

    博客转载自:http://blog.csdn.net/Loser__Wang/article/details/51811347 本文目的在于记录如何使用MATLAB做摄像机标定,并通过opencv进行 ...

  9. C#下的摄像机标定

    前言:计算机视觉的基本任务之一是从摄像机获取的图像信息出发计算三维空间中物体的几何信息,并由此重建和识别物体,而空间物体表面某点的三维几何位置与其在图像中对应点之间的相互关系是由摄像机成像的几何模型决 ...

随机推荐

  1. Linux 如何重新划分Swap交换分区

    SWAP分区是LINUX暂时存储数据的交换分区,它主要是把主内存上暂时不用得数据存起来,在需要的时候再调进内存内,且作为SWAP使用的分区不用指定“MoutPoint”(载入点)它至少要等于系统上实际 ...

  2. 利用Python网络爬虫抓取微信好友的签名及其可视化展示

    前几天给大家分享了如何利用Python词云和wordart可视化工具对朋友圈数据进行可视化,利用Python网络爬虫抓取微信好友数量以及微信好友的男女比例,以及利用Python网络爬虫抓取微信好友的所 ...

  3. Hexo High一下以及压缩排版问题

    背景介绍 集成Hight一下以及Gulp-html压缩之后出现的问题: High一下功能多次点击,会创建多个Audio对象,导致同时播放多次音乐,重音.解决办法:判断是否添加Audio对象,如果存在则 ...

  4. 数据持久化(六)之Using CoreData with MagicalRecord

    第五节里面,我介绍了CoreData的配置和主要的增删改查,可能非常多人会认为用它真繁琐.这里,我再介绍网上大神对它进行了人性化封装的第三方MagicalRecord,正如FMDB对sqlite进行了 ...

  5. colorscheme-如何vim颜色风格

    我们vim默认的风格是黑底的,如果我们想要更换其他的风格,比如字体高亮的颜色.注释的颜色等.这时候我们就需要一个属性了,如下 colorscheme darkblue 这个属性的值,其实是在 /usr ...

  6. 小项目: low版本的 员工信息程序:

    ### 附加两个文件1 user_info 和worker_info flag = False def logon(): #登录函数 global flag usr = input('Username ...

  7. mvc4 视图中的form如何获取

    public ActionResult Index(FormCollection form)         {             var Name = form["字段名" ...

  8. Kinect 开发 —— 杂一

    Kinect 提供了非托管(C++)和托管(.NET)两种开发方式的SDK,如果您用C++开发的话,需要安装Speech Runtime(V11),Kinect for Windows Runtime ...

  9. Dubbo简易学习

    0.  Dubbo简易介绍 DUBBO是一个分布式服务框架,致力于提供高性能和透明化的RPC远程服务调用方案,是阿里巴巴SOA服务化治理方案的核心框架,每天为2,000+个服务提供3,000,000, ...

  10. 18/9/22NOIP模拟考

    18/9/22NOIP模拟考 其实本来是有多组数据的,出题人忘记在题面上加了   斜眼笑 期望得分:100:实际得分:100 由于种种原因,拿到题的时候已经过去了0.5h+... 然后因为这道题数据范 ...