常驻嘉宾
天才
- 积分
- 3615
- 威望
- 1795
- 贡献
- 1146
- 兑换币
- 1173
- 注册时间
- 2014-12-13
- 在线时间
- 337 小时
- 毕业学校
- 南京气象学校
|
/**
* @breif 横向畸变矫正
**/
Status ReviseTransDistortion(unsigned char PicPoint[][CAMERA_W]){
//u->Col v->row M->RowNum
//U = u*(1+(AB/CD-1)*(v/(M-1))) //矫正公式
//x=(CD/(N-1))(u-N/2) //矫正后图像坐标与真实坐标对应关系
float Pro = -0.18; //AB/CD-1
int Loc = 0;
unsigned char PicTemp[CAMERA_H][CAMERA_W] = { 0 };
for (int i = 0; i < CAMERA_H; i++){
for (int j = 0; j < CAMERA_W; j++){
PicTemp[i][j] = PicPoint[i][j];
}
}
for (int i = 0; i < CAMERA_H; i++){
for (int j = 0; j < CAMERA_W; j++){
Loc = (int)(j*(1 + (Pro*((float)i / (float)(CAMERA_H - 1)))));
PicPoint[i][Loc] = PicTemp[i][j];
}
}
return OK;
}
////////////////////////////////////////////
/**
* @breif 求解二元一次方程
**/
static Status CalLinearEquation(int Point[],float *a,float* b){
//ax+by=e
//cx+dy=f
//x=(de-bf)/(ad-bc)
//y=(af-ce)/(ad-bc)
int PointX_X1 = Point[0] * Point[0];
int PointX_X2 = Point[2] * Point[2];
float denominator = PointX_X1 * Point[2] - Point[0] * PointX_X2;
if (fabs(denominator) < 0.00001) return false; //垂直于X轴
*a = (Point[2] * Point[1] - Point[0] * Point[3]) / denominator;
*b = (PointX_X1 * Point[3] - PointX_X2 * Point[1]) / denominator;
return OK;
}
////////////////////////////////////////////
/**
* @breif 纵向畸变矫正
**/
Status ReviseLongiDistortion(unsigned char PicPoint[][CAMERA_W]){
//y=vd
float RealY = 260.0f; //260cm
float ActualY = 0.0f;
float a = 0.0, b = 0.0f;
int Point[4] = { 14, 16, 33, 150 };
CalLinearEquation(Point, &a, &b);
unsigned char PicTemp[CAMERA_H][CAMERA_W] = { 0 };
for (int i = 0; i < CAMERA_H; i++){
for (int j = 0; j < CAMERA_W; j++){
PicTemp[i][j] = PicPoint[i][j];
}
}
int LocLoc[CAMERA_H] = { 0 };
for (int i = 0; i < CAMERA_H; i++){
ActualY = a*(float)(i*i) + b*(float)i;
float Pro = ActualY / RealY;
if (Pro < 0)Pro = 0;
if (Pro > 1)Pro = 1;
LocLoc[i] = (int)(Pro * (float)(CAMERA_H - 1));
for (int j = 0; j < CAMERA_W; j++){
PicPoint[LocLoc[i]][j] = PicTemp[i][j];
}
}
for (int i = 0; i < CAMERA_H; i++){
if (LocLoc[i] != LocLoc[i + 1]){
for (int j = LocLoc[i]+1; j < LocLoc[i + 1]; j++){
for (int k = 0; k < CAMERA_W; k++){
PicPoint[j][k] = PicTemp[i][k];
}
}
}
}
return OK;
}
////////////////////////////////////////////
算法献上,已痛哭,耗了一早上,还测了好几个参数
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|