自动驾驶AVM环视算法–图像的畸变矫正和各个视图矫正图(TOP、Left和Right)

源码工程:

链接:https://pan.baidu.com/s/1_f7hiRlS5I8ABajAFPT-hw?pwd=vjcm提取码:vjcm

主要是根据需求实现不同视角的自由切换,当前实现是俯视图想、左视图像和右视图像的输出,测试结果参见下图:

原始图

俯视图

左视图

右视图

当前使用的摄像头安装位置(白色三角的位置就是摄像头的安装位置)

算法的实现

1、根据视角的不同设置不同的相机的旋转矩阵

俯视图像的旋转矩阵设置如下所示

js_initAngle(data_TOP, 90, 0, 0);

坐视图像的旋转矩阵设置如下所示

js_initAngle(data_TOP, 0, 90, 0);

右视图像的旋转矩阵设置如下所示

js_initAngle(data_TOP, 0, *90, 0);

2、初始化相机实际安装的位置参数

js_initAngle(data_0, 25, 0, 0);

3、初始化相机的内参参数

float  a[4] = { 160,-0.0005,0,0 };

4、遍历图像每个点坐标实现坐标的变换并输出各个视图的图像

图片的测试代码

	IplImage* img = cvLoadImage("test1.jpg");
	IplImage* det_TOP = cvCreateImage(cvSize(img->width, img->height), img->depth, img->nChannels);
	IplImage* det_LEFT = cvCreateImage(cvSize(img->width, img->height), img->depth, img->nChannels);
	IplImage* det_RIGHT = cvCreateImage(cvSize(img->width, img->height), img->depth, img->nChannels);
	js_getPlaneImag_TOP(img->imageData, det_TOP->imageData, img->width, img->height, img->nChannels);
	js_getPlaneImag_LEFT(img->imageData, det_LEFT->imageData, img->width, img->height, img->nChannels);
	js_getPlaneImag_RIGHT(img->imageData, det_RIGHT->imageData, img->width, img->height, img->nChannels);
	cvShowImage("img", det_TOP);
	cvWaitKey(0);

图片的测试结果

视频的测试代码

// TODO: 在此添加控件通知处理程序代码
	IplImage* det_TOP = cvCreateImage(cvSize(1280, 720), 8, 3);
	IplImage* det_LEFT = cvCreateImage(cvSize(1280, 720), 8, 3);
	IplImage* det_RIGHT = cvCreateImage(cvSize(1280, 720), 8, 3);
	IplImage* detROI = cvCreateImage(cvSize(384, 216), 8, 3);
	CvVideoWriter* writer = cvCreateVideoWriter("Front_TOP_Result.avi", CV_FOURCC('X', 'V', 'I', 'D'), 25, cvSize(1280, 720));
	cvNamedWindow("视频播放", CV_WINDOW_AUTOSIZE);
	CvCapture* capture = cvCreateFileCapture("Front.avi");
	IplImage* frame;
	while (frame = cvQueryFrame(capture))
	{
		js_getPlaneImag_TOP(frame->imageData, det_TOP->imageData, frame->width, frame->height, frame->nChannels);
		js_getPlaneImag_LEFT(frame->imageData, det_LEFT->imageData, frame->width, frame->height, frame->nChannels);
		js_getPlaneImag_RIGHT(frame->imageData, det_RIGHT->imageData, frame->width, frame->height, frame->nChannels);
		//鱼眼图像
		cvResize(frame, detROI);
		cvSetImageROI(det_TOP, cvRect((frame->width-384)/2, 0, 384, 216));
		cvCopy(detROI, det_TOP);
		cvResetImageROI(det_TOP);

		//左侧图像
		cvResize(det_LEFT, detROI);
		cvSetImageROI(det_TOP, cvRect(0, 0, 384, 216));
		cvCopy(detROI, det_TOP);
		cvResetImageROI(det_TOP);


		//右侧图像
		cvResize(det_RIGHT, detROI);
		cvSetImageROI(det_TOP, cvRect(det_RIGHT->width - 384, 0, 384, 216));
		cvCopy(detROI, det_TOP);
		cvResetImageROI(det_TOP);

		cvWriteFrame(writer, det_TOP);
		cvShowImage("视频播放", det_TOP);
		char c = cvWaitKey(1);
		if (c == 27)break;
	}
	cvReleaseVideoWriter(&writer);
	cvReleaseCapture(&capture);
	cvDestroyWindow("视频播放");

视频测试结果

https://www.bilibili.com/video/BV1mW4y1c7cG/

未经允许不得转载:金书世界 » 自动驾驶AVM环视算法–图像的畸变矫正和各个视图矫正图(TOP、Left和Right)

相关文章

评论 (0)