基于EmguCV的摄像机标定及矫正
2016-03-17 22:55
633 查看
标签: EmguCV摄像头标定C#
2015-05-03 14:55 501人阅读 评论(6) 收藏 举报
分类:
C#版权声明:本文为博主原创文章,未经博主允许不得转载。目录(?)[+]
ParametersimageType: Emgu.CV.Image<Gray, Byte>Source chessboard viewpatternSizeType: System.Drawing.SizeThe number of inner corners per chessboard row and columnflagsType: Emgu.CV.CvEnum.CALIB_CB_TYPEVarious operation flags
Return ValueType: PointF[]The corners detected if the chess board pattern is found, otherwise null is returned注:输入图像需是灰度图,检测之前角点需要开辟空间,如:[csharp] view plain copy print ?cornersDetected = new PointF[nPoints]; //nPoints表示单幅图像角点总数cornersDetected = CameraCalibration.FindChessboardCorners(chessboardImage, patternSize,CALIB_CB_TYPE.ADAPTIVE_THRESH | CALIB_CB_TYPE.NORMALIZE_IMAGE);
ParametersobjectPointsType: 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 pointimagePointsType: 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 pointimageSizeType: System.Drawing.SizeThe size of the image, used only to initialize intrinsic camera matrixintrinsicParamType: Emgu.CV.IntrinsicCameraParametersThe intrisinc parameters, might contains some initial values. The values will be modified by this function.calibrationTypeType: Emgu.CV.CvEnum.CALIB_TYPEcCalibration typetermCriteriaType: Emgu.CV.Structure.MCvTermCriteriaThe termination criteriaextrinsicParamsType: Emgu.CV.ExtrinsicCameraParameters[]The output array of extrinsic parameters.
Return ValueType: DoubleThe final reprojection error注:objectPoints表示棋盘角点在世界坐标系下的坐标,有多少幅棋盘图像就应有多少角点坐标集,以物理尺寸为单位。imagePoints表示角点在图像中的坐标,以像素为单位。返回值是重投影误差。
ParametersintrinsicMatrixType: System.IntPtrThe camera matrix (A) [fx 0 cx; 0 fy cy; 0 0 1]distortionCoeffsType: System.ntPtrThe vector of distortion coefficients, 4x1 or 1x4 [k1, k2, p1, p2].mapxType: System.IntPtrThe output array of x-coordinates of the mapmapyType: System.ntPtrThe output array of y-coordinates of the map注:定义Matrix类的映射矩阵变量,其属性中包含Ptr,可以直接当指针用,如:[csharp] view plain copy print ?private Matrix<float> mapx = new Matrix<float>(height, width);private Matrix<float> mapy = new Matrix<float>(height, width);4、几何变换[csharp]
view plain
copy
print
?public static void cvRemap(IntPtr src,IntPtr dst,IntPtr mapx,IntPtr mapy,int flags,MCvScalar fillval)ParameterssrcType: System.ntPtr
Source imagedstType: System.IntPtr
Destination imagemapxType: System.IntPtr
The map of x-coordinates (32fC1 image)mapyType: System.ntPtr
The map of y-coordinates (32fC1 image)flagsType: System.Int32
A combination of interpolation method and the optional flag CV_WARP_FILL_OUTLIERSfillvalType: Emgu.CV.Structure.MCvScalar
A value used to fill outliers注:flags定义在 CvEnum下的 WARP枚举类型,调用: (int)WARP.CV_WARP_INVERSE_MAP
2015-05-03 14:55 501人阅读 评论(6) 收藏 举报
分类:
C#版权声明:本文为博主原创文章,未经博主允许不得转载。目录(?)[+]
前言
之前用OpenCV做过摄像机标定及矫正,现在平台换了,改用C#,就用EmguCV做一下,其实就是OpenCV的C#版。在EmguCV中有两类摄像机标定的类,一个是CvInvoke类,一个是CameraCalibration类,两种标定效果差不多,只不过CvInvoke涉及的函数大多都是指针类型的,而C#对于指针的操作比较麻烦。本文是在CameraCalibration类的基础上完成摄像机标定,用CvInvoke类完成矫正图像。函数说明
1、角点检测
[csharp] view plain copy print ?public static PointF[] FindChessboardCorners(Image<Gray, byte> image,Size patternSize,CALIB_CB_TYPE flags)ParametersimageType: Emgu.CV.Image<Gray, Byte>Source chessboard viewpatternSizeType: System.Drawing.SizeThe number of inner corners per chessboard row and columnflagsType: Emgu.CV.CvEnum.CALIB_CB_TYPEVarious operation flags
Return ValueType: PointF[]The corners detected if the chess board pattern is found, otherwise null is returned注:输入图像需是灰度图,检测之前角点需要开辟空间,如:[csharp] view plain copy print ?cornersDetected = new PointF[nPoints]; //nPoints表示单幅图像角点总数cornersDetected = CameraCalibration.FindChessboardCorners(chessboardImage, patternSize,CALIB_CB_TYPE.ADAPTIVE_THRESH | CALIB_CB_TYPE.NORMALIZE_IMAGE);
2、标定函数
[csharp] view plain copy print ?public static double CalibrateCamera(MCvPoint3D32f[][] objectPoints,PointF[][] imagePoints,Size imageSize,IntrinsicCameraParameters intrinsicParam,CALIB_TYPE calibrationType,MCvTermCriteria termCriteria,out ExtrinsicCameraParameters[] extrinsicParams)ParametersobjectPointsType: 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 pointimagePointsType: 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 pointimageSizeType: System.Drawing.SizeThe size of the image, used only to initialize intrinsic camera matrixintrinsicParamType: Emgu.CV.IntrinsicCameraParametersThe intrisinc parameters, might contains some initial values. The values will be modified by this function.calibrationTypeType: Emgu.CV.CvEnum.CALIB_TYPEcCalibration typetermCriteriaType: Emgu.CV.Structure.MCvTermCriteriaThe termination criteriaextrinsicParamsType: Emgu.CV.ExtrinsicCameraParameters[]The output array of extrinsic parameters.
Return ValueType: DoubleThe final reprojection error注:objectPoints表示棋盘角点在世界坐标系下的坐标,有多少幅棋盘图像就应有多少角点坐标集,以物理尺寸为单位。imagePoints表示角点在图像中的坐标,以像素为单位。返回值是重投影误差。
3、映射矩阵求取
[csharp] view plain copy print ?public static void cvInitUndistortMap(IntPtr intrinsicMatrix,IntPtr distortionCoeffs,IntPtr mapx,IntPtr mapy)ParametersintrinsicMatrixType: System.IntPtrThe camera matrix (A) [fx 0 cx; 0 fy cy; 0 0 1]distortionCoeffsType: System.ntPtrThe vector of distortion coefficients, 4x1 or 1x4 [k1, k2, p1, p2].mapxType: System.IntPtrThe output array of x-coordinates of the mapmapyType: System.ntPtrThe output array of y-coordinates of the map注:定义Matrix类的映射矩阵变量,其属性中包含Ptr,可以直接当指针用,如:[csharp] view plain copy print ?private Matrix<float> mapx = new Matrix<float>(height, width);private Matrix<float> mapy = new Matrix<float>(height, width);4、几何变换[csharp]
view plain
copy
?public static void cvRemap(IntPtr src,IntPtr dst,IntPtr mapx,IntPtr mapy,int flags,MCvScalar fillval)ParameterssrcType: System.ntPtr
Source imagedstType: System.IntPtr
Destination imagemapxType: System.IntPtr
The map of x-coordinates (32fC1 image)mapyType: System.ntPtr
The map of y-coordinates (32fC1 image)flagsType: System.Int32
A combination of interpolation method and the optional flag CV_WARP_FILL_OUTLIERSfillvalType: 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文件中,方便查看和提取。相关文章推荐
- C++实现动态顺序表
- 能不能简单描述一下你在java web开发中需要用到多线程编程的场景?
- 用vlc搭建简单流媒体服务器(UDP和TCP方式)
- centos 7 挂载大硬盘
- javascript几个提高性能的知识点
- PHP Switch 语句
- DP背包问题小结(01背包,完全背包,需恰好装满或不需,一维DP、二维DP)
- etacilpuDsniatnoC.217
- 解析json数据,明明过程都写的挺对,在网络上请求也有数据,但是就是显示为空,原因是什么???
- 快慢指针在链表中的应用
- nginx vhost php文件无法识别
- 设计模式C++学习笔记之十四(Iterator迭代器模式)
- 210. Course Schedule II LeetCode
- HTML table、form表单标签的介绍
- Linux 基于IPC机制实现进程间的共享内存处理
- ACM程序设计选修课——1031: Hungar的得分问题(二)(杨辉三角+二进制转换)
- c语言经典大题
- Boost库在VS2010环境中使用
- com.mysql.jdbc.PreparedStatement.setBinaryStream(ILjava/io/InputStream;J)V错误解决
- centos 6.6 32位 实现LAMP配置