資源簡介
使用C++編寫的激光雷達數據的讀取和顯示代碼 用到OpenCV2.4,OpenCV下有很多圖像處理的函數,進行激光雷達的處理時也是可以使用的。便于后面進行算法的開發和測試

代碼片段和文件信息
#include?“OpenRadar.h“
#define?pi?3.141592653
OpenRadar::OpenRadar(void)
{
}
OpenRadar::~OpenRadar(void)
{
}
bool?OpenRadar::RadarRead(char?*fileName){
????FILE*?fp?=?NULL;
????int?dis?=?0;
????int?totalCnt?=?0;
????fp?=?fopen(fileName“r“);
????if?(fp?==?NULL)
????{
????????//cout<<“failed?to?read“< ????????return?false;
????}else?{
????????//cout<<“successed?to?read“< ????????RadarRho.clear();
????????while(!feof(fp))
????????{
????????????fscanf(fp?“%d?“?&dis);
????????????RadarRho.push_back(dis);
????????????//printf(“%d??“?dis);
????????}
????????//cout<<“Total?Count:?“< ????}
????fclose(fp);
????return?true;
}
void?OpenRadar::CreateRadarImage(IplImage*?RadarImage){
????//RadarImage?=?cvCreateImage(cvSize(RadarImageWdithRadarImageHeight)IPL_DEPTH_8U1);
????cvZero(RadarImage);
????//在中心加上一個圓心
????cvCircle(RadarImage?cvPoint(RadarImageWdith/2RadarImageHeight/2)3?CV_RGB(0255255)?-1?80);
????int?xy;
????double?thetarho;
????unsigned?char?*?pPixel?=?0;
????int?halfWidth??=?RadarImageWdith/2;
????int?halfHeight?=?RadarImageHeight/2;
????for?(int?i?=?0;?i?????{
????????theta?=?(i/4.0?-?45)*pi/180;
????????rho?=?RadarRho.at(i);
????????x?=?(int)(rho*cos(theta)/5)?+?halfWidth;
????????y?=?(int)(-rho*sin(theta)/5)+?halfHeight;
????????if?(x?>=?0?&&?x?=?0?&&?y?????????{
????????????pPixel?=?(unsigned?char*)RadarImage->imageData?+?y*RadarImage->widthStep?+?3*x+2;
????????????*pPixel?=?255;
????????}else{
????????????//cout<<“x:?“< ????????}
????}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2013-02-19?19:48??OpenRadar1.0完成讀取和顯示\
?????文件????????1690??2013-02-19?19:40??OpenRadar1.0完成讀取和顯示\OpenRadar.cpp
?????文件?????????429??2013-02-19?18:50??OpenRadar1.0完成讀取和顯示\OpenRadar.h
?????文件?????????887??2013-02-19?19:43??OpenRadar1.0完成讀取和顯示\Radar.cpp
評論
共有 條評論