镜头标定内外参

这段代码展示了如何使用OpenCV进行相机标定的过程。首先,通过读取摄像头捕获的帧并检测棋盘格角点,然后进行亚像素级精确定位。接着,将检测到的角点存储并计算摄像机的内参数矩阵和畸变系数矩阵。最终,将这些参数保存到XML文件,并展示校正前后的图像效果。
摘要由CSDN通过智能技术生成
//liyongbo 2015.05.06  changchun 
//#include "stdafx.h"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <string>

using namespace cv;
using namespace std;

#include "cv.h"
#include "highgui.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <math.h>
#include <float.h>
#include <limits.h>
#include <time.h>
#include <ctype.h>
// OpenCV
#include <cxcore.h>
#include <cv.h>
#include <highgui.h>
#include <cvaux.h>


#include "cv.h"
#include "highgui.h"
#include <string>
#include <iostream>
#include <opencv2/calib3d/calib3d.hpp>
#define CV_CALIB_CB_ADAPTIVE_THRESH 1
#define CV_CALIB_CB_NORMALIZE_IMAGE 2
#define CV_CALIB_CB_FILTER_QUADS 4
#define CV_CALIB_CB_FAST_CHECK 8



int main()
{
	int cube_length = 7;

	CvCapture* capture;

	capture = cvCreateCameraCapture(0);

	if (capture == 0){
		printf("无法捕获摄像头设备!\n\n");
		return 0;
	}
	else{
		printf("捕获摄像头设备成功!!\n\n");
	}

	IplImage* frame;

	cvNamedWindow("帧截取窗口", 1); 
        //cvNamedWindow()函数用于在屏幕上创建一个窗口,将被显示的图像包含于该窗口中。
        //函数的第一个参数指定了该窗口的窗口标题,如果要使用HighGUI库所提供的其他函数与该窗口进行交互时,我们将通过该参数值引用这个窗口。


	printf("按“C”键截取当前帧并保存为标定图片...\n按“Q”键退出截取帧过程...\n\n");

	int number_image = 1;
	char *str1;
	str1 = ".jpg";
	char filename[20] = "";

	while (true)
	{
		frame = cvQueryFrame(capture);// 从摄像头或者文件中抓取并返回一帧
		if (!frame)
			break;
		cvShowImage("帧截取窗口", frame); //图像显示

		if (cvWaitKey(10) == 'c'){
			printf("进入截取程序!!!!!!");
			sprintf_s(filename, "%d.jpg", number_image); // int sprintf_s( char *buffer, size_t sizeOfBuffer, const char *format [, argument] ... );

			//这个函数的主要作用是将若干个argument按照format格式存到buffer中

				cvSaveImage(filename, frame);//保存
			cout << "成功获取当前帧,并以文件名" << filename << "保存...\n\n";
			printf("按“C”键截取当前帧并保存为标定图片...\n按“Q”键退出截取帧过程...\n\n");
			number_image++;
		}
		else if (cvWaitKey(10) == 'q'){
			printf("截取图像帧过程完成...\n\n");
			cout << "共成功截取" << --number_image << "帧图像!!\n\n";
			brea
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值