资源简介
使用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 < RadarRho.size();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 < RadarImageWdith && y >= 0 && y < RadarImageHeight)
{
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
评论
共有 条评论