亿加合和智能车制作

标题: 图像横向矫正和纵向矫正时,单片机跑步过来了,白写了 [打印本页]

作者: shen1994    时间: 2016-4-14 14:31
标题: 图像横向矫正和纵向矫正时,单片机跑步过来了,白写了
/**
* @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;
}
////////////////////////////////////////////
算法献上,已痛哭,耗了一早上,还测了好几个参数

作者: 何俊    时间: 2016-4-14 15:06
哪有这么用的。。。存个表,然后对提取的线校正。

作者: 跑龙套的人    时间: 2016-4-14 15:17
咋不拿个广角的镜头试试
作者: 喆3喆    时间: 2016-4-14 15:27
:lol:lol
作者: 9802344    时间: 2016-4-14 16:05
向量表是指的里面的哪些参数?
作者: shen1994    时间: 2016-4-14 17:41
9802344 发表于 2016-4-14 16:05
向量表是指的里面的哪些参数?

point(4)测出来的点坐标,用二次函数去描述

作者: miaobrother    时间: 2016-4-14 18:08
如果采集一行 处理一行行么?
作者: shen1994    时间: 2016-4-14 23:08
miaobrother 发表于 2016-4-14 18:08
如果采集一行 处理一行行么?

一行数据没有处理的必要,我的图像是因为失真严重了,才想起来用的

作者: miaobrother    时间: 2016-4-15 10:13
shen1994 发表于 2016-4-14 23:08
一行数据没有处理的必要,我的图像是因为失真严重了,才想起来用的

因为我把摄像头反着装,所以来一行处理一行,这样采集完一副也就处理完一副了,你这个矫正需要上下行关联吗

作者: shen1994    时间: 2016-4-15 22:03
miaobrother 发表于 2016-4-15 10:13
因为我把摄像头反着装,所以来一行处理一行,这样采集完一副也就处理完一副了,你这个矫正需要上下行关联 ...

你可以试一试,很好理解

作者: 9802344    时间: 2016-4-16 10:06
point4里面代表什么意思呢?还有一个a b 为什么都是零
作者: 我的世界123    时间: 2018-3-4 15:53
point(4)代表什么意思?不太理解,还有你的纵向校正基于什么公式呢?




欢迎光临 亿加合和智能车制作 (http://www.znczz.com/) Powered by Discuz! X3.2