-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
逆透视变换车道线检测源码
- Loading branch information
0 parents
commit d9a3cbd
Showing
34 changed files
with
4,349 additions
and
0 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
vet_ipm_ldw/build-vet_ipm_ldw-Desktop_Qt_5_10_1_GCC_64bit-Debug/.qmake.stash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
QMAKE_CXX.INCDIRS = \ | ||
/usr/include/c++/5 \ | ||
/usr/include/x86_64-linux-gnu/c++/5 \ | ||
/usr/include/c++/5/backward \ | ||
/usr/lib/gcc/x86_64-linux-gnu/5/include \ | ||
/usr/local/include \ | ||
/usr/lib/gcc/x86_64-linux-gnu/5/include-fixed \ | ||
/usr/include/x86_64-linux-gnu \ | ||
/usr/include | ||
QMAKE_CXX.LIBDIRS = \ | ||
/usr/lib/gcc/x86_64-linux-gnu/5 \ | ||
/usr/lib/x86_64-linux-gnu \ | ||
/usr/lib \ | ||
/lib/x86_64-linux-gnu \ | ||
/lib | ||
QMAKE_CXX.QT_COMPILER_STDCXX = 199711L | ||
QMAKE_CXX.QMAKE_GCC_MAJOR_VERSION = 5 | ||
QMAKE_CXX.QMAKE_GCC_MINOR_VERSION = 4 | ||
QMAKE_CXX.QMAKE_GCC_PATCH_VERSION = 0 | ||
QMAKE_CXX.COMPILER_MACROS = \ | ||
QT_COMPILER_STDCXX \ | ||
QMAKE_GCC_MAJOR_VERSION \ | ||
QMAKE_GCC_MINOR_VERSION \ | ||
QMAKE_GCC_PATCH_VERSION |
665 changes: 665 additions & 0 deletions
665
vet_ipm_ldw/build-vet_ipm_ldw-Desktop_Qt_5_10_1_GCC_64bit-Debug/Makefile
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0"?> | ||
<opencv_storage> | ||
<!-- This setting file is to set experiment parameters --> | ||
<!-- =====Set video source===== --> | ||
<video_path>file\\video\\</video_path> | ||
<!-- read file path --> | ||
<calibrationSettingFile_path>file\\calibrationSettingFile.xml</calibrationSettingFile_path> | ||
<pixel_path>file\\pixel.xml</pixel_path> | ||
<ROI_HEIGHT>30000</ROI_HEIGHT> | ||
<ROI_WIDTH>3750</ROI_WIDTH> | ||
</opencv_storage> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0"?> | ||
<opencv_storage> | ||
<comprehensiveParameters> | ||
3.1807900000000000e-001 9.6635299999999993e-002 | ||
-4.8396999999999997e-003 2.3091899999999999e-002 | ||
-9.3867100000000001e-006 1.5981799999999999e-004 | ||
6.4010299999999995e+002 5.7899599999999998e+002</comprehensiveParameters> | ||
<Distance_of_2_near_circles>1680</Distance_of_2_near_circles> | ||
<Distance_of_2_far_circles>1680</Distance_of_2_far_circles> | ||
<Distance_of_2_vertical_circles>2000</Distance_of_2_vertical_circles> | ||
<Distance_from_car_to_original_coordinate>3900</Distance_from_car_to_original_coordinate> | ||
<car_front_width>1730</car_front_width> | ||
<Extand_width>1000</Extand_width> | ||
</opencv_storage> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0"?> | ||
<opencv_storage> | ||
<one_x>3.6999925639520211e+002</one_x> | ||
<one_y>5.7849997037617891e+002</one_y> | ||
<two_x>4.2649970115376783e+002</two_x> | ||
<two_y>4.7400020455151628e+002</two_y> | ||
<three_x>8.3900055935883290e+002</three_x> | ||
<three_y>4.7350021043274643e+002</three_y> | ||
<four_x>9.1450004322865084e+002</four_x> | ||
<four_y>5.7949991401582884e+002</four_y> | ||
<five_x>-3.0956595226845128e+001</five_x> | ||
<five_y>1.2814095111316901e+003</five_y> | ||
<six_x>1.4606018418322392e+003</six_x> | ||
<six_y>1.3151492455386626e+003</six_y> | ||
</opencv_storage> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
ldw_20180505124501794.avi | ||
test1.avi | ||
highway2.avi | ||
highway1.avi | ||
|
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,271 @@ | ||
|
||
#include<calibration.h> | ||
|
||
using namespace std; | ||
using namespace cv; | ||
|
||
void initialize(){ | ||
//读取设置文件 | ||
FileStorage _fs("file\\SettingFile.xml", FileStorage::READ); | ||
if(!_fs.isOpened()) | ||
{ | ||
cout << "failed to open SettingFile.xml" << endl; | ||
} | ||
_fs["video_path"]>>video_path; | ||
_fs["calibrationSettingFile_path"]>>calibrationSettingFile_path; | ||
_fs["pixel_path"]>>pixel_path; | ||
_fs["ROI_HEIGHT"]>>ROI_HEIGHT; | ||
_fs["ROI_WIDTH"]>>ROI_WIDTH; | ||
|
||
_fs.release(); | ||
} | ||
|
||
Calibration* Calibration::vet_ptr_calibration = NULL; | ||
|
||
Calibration::Calibration() | ||
{ | ||
//初始化参数值 | ||
for(int i=0;i<8;i++) | ||
{ | ||
comprehensive_parameters[i] = 0; | ||
} | ||
} | ||
|
||
Calibration* Calibration::instance() | ||
{ | ||
//获取单例模式 | ||
if(NULL==vet_ptr_calibration) | ||
{ | ||
vet_ptr_calibration = new Calibration(); | ||
} | ||
return vet_ptr_calibration; | ||
} | ||
|
||
void Calibration::destoryInstance() | ||
{ | ||
if(NULL!=vet_ptr_calibration) | ||
{ | ||
delete vet_ptr_calibration; | ||
vet_ptr_calibration = NULL; | ||
} | ||
} | ||
|
||
bool Calibration::initComprehensiveParameters() | ||
{ | ||
// cout<<"$$$$$$$$$$$$$$$$$: "<<calibrationSettingFile_path<<endl; | ||
FileStorage _fs(calibrationSettingFile_path, FileStorage::READ); | ||
// cout<<"%%%%%%%%%%%%%%%%%%%%%%%%%%%"<<endl; | ||
if(!_fs.isOpened()){ | ||
cout << "Fail to open calibrationSettingFile.xml" << endl; | ||
return false; | ||
} | ||
|
||
FileNode arr_node = _fs["comprehensiveParameters"]; | ||
FileNodeIterator fni = arr_node.begin(); | ||
FileNodeIterator fniEnd = arr_node.end(); | ||
for(int i = 0; fni != fniEnd; fni++){ | ||
comprehensive_parameters[i++] = *fni; | ||
} | ||
|
||
//show only 2018.4.2 | ||
// for(int i=0;i<8;i++) | ||
// { | ||
// cout<<comprehensive_parameters[i]<<endl; | ||
// } | ||
|
||
_fs.release(); | ||
|
||
return true; | ||
} | ||
|
||
bool Calibration::createPixelFile()//创建一个xml文件,文件包含6个实际点对应的像素点。 | ||
{ | ||
|
||
FileStorage _fs(calibrationSettingFile_path, FileStorage::READ); | ||
if(!_fs.isOpened()){ | ||
cout << "Fail to open calibrationSettingFile.xml" << endl; | ||
return false; | ||
} | ||
float _DistNearCircles; | ||
float _DistFarCircles; | ||
float _DistVerticalCircles; | ||
float _CarFrontDist; | ||
float _ExtandWidth; | ||
float _CarFrontWidth; | ||
|
||
//标定时确定的实际坐标参数 | ||
_fs["Distance_of_2_near_circles"] >> _DistNearCircles; | ||
_fs["Distance_of_2_far_circles"] >> _DistFarCircles; | ||
_fs["Distance_of_2_vertical_circles"] >> _DistVerticalCircles; | ||
_fs["Distance_from_car_to_original_coordinate"] >> _CarFrontDist; | ||
_fs["Extand_width"] >> _ExtandWidth; | ||
_fs["car_front_width"] >> _CarFrontWidth; | ||
|
||
_fs.release(); | ||
|
||
//WRITE XML | ||
FileStorage fs(pixel_path, FileStorage::WRITE); | ||
if(!fs.isOpened()){ | ||
cout << "failed to create pixl.xml" << endl; | ||
return false; | ||
} | ||
|
||
Point2d _Real_coordinate[6];//实际坐标 | ||
Point2d _pixel_coordinate[6];//像素坐标 | ||
_Real_coordinate[0]=Point2d(-0.5*_DistNearCircles,0); | ||
_Real_coordinate[1]=Point2d(-0.5*_DistNearCircles,_DistVerticalCircles); | ||
_Real_coordinate[2]=Point2d(0.5*_DistNearCircles,_DistVerticalCircles); | ||
_Real_coordinate[3]=Point2d(0.5*_DistNearCircles,0); | ||
_Real_coordinate[4]=Point2d(-0.5*_CarFrontWidth,-_CarFrontDist); | ||
_Real_coordinate[5]=Point2d(0.5*_CarFrontWidth,-_CarFrontDist); | ||
for(int ii=0;ii<6;ii++) | ||
{ | ||
double x = _Real_coordinate[ii].x; | ||
double y = _Real_coordinate[ii].y; | ||
// cout<<x<<" "<<y<<endl; | ||
//像素坐标 | ||
if(0!=(1+comprehensive_parameters[4]*x+comprehensive_parameters[5]*y)) | ||
{ | ||
double ux = (comprehensive_parameters[6]+comprehensive_parameters[0]*x+comprehensive_parameters[1]*y)/(1+comprehensive_parameters[4]*x+comprehensive_parameters[5]*y); | ||
double vy = (comprehensive_parameters[7]+comprehensive_parameters[2]*x+comprehensive_parameters[3]*y)/(1+comprehensive_parameters[4]*x+comprehensive_parameters[5]*y); | ||
_pixel_coordinate[ii] = Point2d(ux,vy); | ||
} | ||
else | ||
{ | ||
cout<<"The Comprehensive Parameters Error!!!"<<endl; | ||
} | ||
} | ||
|
||
fs << "one_x" << _pixel_coordinate[0].x; | ||
fs << "one_y" << _pixel_coordinate[0].y; | ||
fs << "two_x" << _pixel_coordinate[1].x; | ||
fs << "two_y"<< _pixel_coordinate[1].y; | ||
fs << "three_x" << _pixel_coordinate[2].x; | ||
fs << "three_y" << _pixel_coordinate[2].y; | ||
fs << "four_x" << _pixel_coordinate[3].x; | ||
fs << "four_y" << _pixel_coordinate[3].y; | ||
fs << "five_x" << _pixel_coordinate[4].x; | ||
fs << "five_y" << _pixel_coordinate[4].y; | ||
fs << "six_x" << _pixel_coordinate[5].x; | ||
fs << "six_y" << _pixel_coordinate[5].y; | ||
fs.release(); | ||
return true; | ||
} | ||
|
||
|
||
//将像素坐标转换成实际坐标 | ||
void Calibration::pixel2Vehicle(StructPixelAndReal& pixelAndReal) | ||
{ | ||
double ux = pixelAndReal._pixel_coordinate.x; | ||
double vy = pixelAndReal._pixel_coordinate.y; | ||
|
||
double a1 = comprehensive_parameters[0]-ux*comprehensive_parameters[4]; | ||
double a2 = comprehensive_parameters[1]-ux*comprehensive_parameters[5]; | ||
double b1 = comprehensive_parameters[2]-vy*comprehensive_parameters[4]; | ||
double b2 = comprehensive_parameters[3]-vy*comprehensive_parameters[5]; | ||
double c1 = ux-comprehensive_parameters[6]; | ||
double c2 = vy-comprehensive_parameters[7]; | ||
|
||
//世界坐标 | ||
if(0!=(a1*b2-a2*b1)) | ||
{ | ||
double real_x = (b2*c1-a2*c2)/(a1*b2-a2*b1); | ||
double real_y = (a1*c2-b1*c1)/(a1*b2-a2*b1); | ||
pixelAndReal._real_coordinate = Point2d(real_x,real_y); | ||
} | ||
else | ||
{ | ||
cout<<"The Comprehensive Parameters Error!"<<endl; | ||
} | ||
} | ||
|
||
//将实际坐标转换为像素坐标 | ||
void Calibration::vehicle2Pixel(StructPixelAndReal& pixelAndReal) | ||
{ | ||
double x = pixelAndReal._real_coordinate.x; | ||
double y = pixelAndReal._real_coordinate.y; | ||
|
||
//像素坐标 | ||
if(0!=(1+comprehensive_parameters[4]*x+comprehensive_parameters[5]*y)) | ||
{ | ||
double ux = (comprehensive_parameters[6]+comprehensive_parameters[0]*x+comprehensive_parameters[1]*y)/(1+comprehensive_parameters[4]*x+comprehensive_parameters[5]*y); | ||
double vy = (comprehensive_parameters[7]+comprehensive_parameters[2]*x+comprehensive_parameters[3]*y)/(1+comprehensive_parameters[4]*x+comprehensive_parameters[5]*y); | ||
pixelAndReal._pixel_coordinate = Point2d(ux,vy); | ||
} | ||
else | ||
{ | ||
cout<<"The Comprehensive Parameters Error!!!"<<endl; | ||
} | ||
} | ||
|
||
bool Calibration::getAllPixelPoint(vector<Point2d>& allPixelPoint) | ||
{ | ||
//2018.4.11 每次换标定文件时必须重新生成一次,覆盖原来的文件(仅仅生成一次)。 | ||
createPixelFile(); | ||
FileStorage _fs(pixel_path, FileStorage::READ); | ||
if(!_fs.isOpened()){ | ||
cout << "Fail to1 open pixl.xml" << endl; | ||
return false; | ||
} | ||
|
||
double tmp[6][2] = {0}; //读取6行 | ||
//标定时确定的实际坐标参数 | ||
_fs["one_x"]>>tmp[0][0]; | ||
_fs["one_y"]>>tmp[0][1]; | ||
_fs["two_x"]>>tmp[1][0]; | ||
_fs["two_y"]>>tmp[1][1]; | ||
_fs["three_x"]>>tmp[2][0]; | ||
_fs["three_y"]>>tmp[2][1]; | ||
_fs["four_x"]>>tmp[3][0]; | ||
_fs["four_y"]>>tmp[3][1]; | ||
_fs["five_x"]>>tmp[4][0]; | ||
_fs["five_y"]>>tmp[4][1]; | ||
_fs["six_x"]>>tmp[5][0]; | ||
_fs["six_y"]>>tmp[5][1]; | ||
|
||
_fs.release(); | ||
|
||
//所有像素坐标值 | ||
for(int j=0;j<6;j++) | ||
{ | ||
allPixelPoint.push_back(Point2d(tmp[j][0],tmp[j][1])); | ||
} | ||
return true; | ||
|
||
} | ||
|
||
bool Calibration::getAllRealPoint(vector<Point2d>& allRealPoint) | ||
{ | ||
FileStorage _fs(calibrationSettingFile_path, FileStorage::READ); | ||
if(!_fs.isOpened()){ | ||
cout << "Fail to open calibrationSettingFile.xml" << endl; | ||
return false; | ||
} | ||
|
||
float _DistNearCircles; | ||
float _DistFarCircles; | ||
float _DistVerticalCircles; | ||
float _CarFrontDist; | ||
float _ExtandWidth; | ||
float _CarFrontWidth; | ||
|
||
//标定时确定的实际坐标参数 | ||
_fs["Distance_of_2_near_circles"] >> _DistNearCircles; | ||
_fs["Distance_of_2_far_circles"] >> _DistFarCircles; | ||
_fs["Distance_of_2_vertical_circles"] >> _DistVerticalCircles; | ||
_fs["Distance_from_car_to_original_coordinate"] >> _CarFrontDist; | ||
_fs["Extand_width"] >> _ExtandWidth; | ||
_fs["car_front_width"] >> _CarFrontWidth; | ||
|
||
_fs.release(); | ||
|
||
//所有世界坐标值 | ||
allRealPoint.push_back(Point2d(-0.5*_DistNearCircles,0)); | ||
allRealPoint.push_back(Point2d(-0.5*_DistNearCircles,_DistVerticalCircles)); | ||
allRealPoint.push_back(Point2d(0.5*_DistNearCircles,_DistVerticalCircles)); | ||
allRealPoint.push_back(Point2d(0.5*_DistNearCircles,0)); | ||
allRealPoint.push_back(Point2d(-0.5*_CarFrontWidth,-_CarFrontDist)); | ||
allRealPoint.push_back(Point2d(0.5*_CarFrontWidth,-_CarFrontDist)); | ||
return true; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#ifndef Calibration_H | ||
#define Calibration_H | ||
#include "global.h" | ||
|
||
void initialize(); | ||
|
||
class Calibration | ||
{ | ||
public: | ||
static Calibration *instance();//设计成单例模式类,因为后面有三处类里用到了这个类 | ||
static void destoryInstance(); | ||
bool initComprehensiveParameters(); //获取8个标定参数 | ||
void pixel2Vehicle(StructPixelAndReal&); //像素坐标到实际坐标变换 | ||
void vehicle2Pixel(StructPixelAndReal&); //实际坐标到像素坐标变换 | ||
bool getAllPixelPoint(vector<Point2d>&); //获取所有点的像素坐标:标定圆的四个点及车前端左侧、右侧两个像素点坐标 | ||
bool getAllRealPoint(vector<Point2d>&);//获取所有点的世界坐标:标定圆的四个点及车前端左侧、右侧两个世界坐标 | ||
bool createPixelFile();//生成一个xml文件,里面包含对应的六个像素坐标,用来给后面的代码读取,在图像上计算距离,用来预警。 | ||
|
||
private: | ||
Calibration(); | ||
|
||
private: | ||
static Calibration *vet_ptr_calibration; | ||
double comprehensive_parameters[8]; //用来存放综合参数 | ||
}; | ||
|
||
|
||
|
||
#endif // Calibration | ||
|
Oops, something went wrong.