⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 calcenter.c

📁 第一届华中科技大学智能车led源码
💻 C
字号:
//*************************************************************************
//*																								                        *
//*			 ************************计算中心坐标***********************		  *
//*																								                        *
//*************************************************************************
#include "includes.h"


//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#define VIDEO_CENTER 42     //摄像头中心位置参考

#define EX_MAX 25           //两次检测间黑线最大允许偏差

//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
unsigned char uca_Center[COLUMN_MAX-COLUMN_MIN];  //中心坐标数组

unsigned char uc_Far=VIDEO_CENTER;  
  signed char sc_FarEx=0;        //远处中心坐标
  signed char sc_FarExLast=0;

unsigned char uc_Center=VIDEO_CENTER;
  signed char sc_CenterEx=0;     //中间中心坐标
  signed char sc_CenterExLast=0;

unsigned char uc_Near=VIDEO_CENTER;  
  signed char sc_NearEx=0;       //近处中心坐标
  signed char sc_NearExLast=0;
  
//************************************************************************
//*																								                       *
//*      ********************计算中心线坐标************************      *
//*																								                       *
//************************************************************************
void vCalCenter(void)
{
  unsigned char ucRow,ucColumn,ucCount;
  unsigned char *pucTemp;
  unsigned int uiSum;
  
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//远处黑线坐标中心值。
  uiSum=0;
  ucCount=0;
  for(ucColumn=COLUMN_MIN;ucColumn<COLUMN_MIN+3;ucColumn++)
  {
    for(ucRow=ROW_MIN+20;ucRow<ROW_MAX-20;ucRow++)
    {
      pucTemp=puca_BufferProcess+ucRow*IMAGE_COLUMN+ucColumn;
      
      if(*pucTemp==BLACK_POINT)
      {
        uiSum+=ucRow;
        ucCount++;
      }
    }
  }
  
  if(ucCount>12)
  {
    sc_FarEx=(unsigned char)(uiSum/ucCount)-VIDEO_CENTER;
    if((sc_FarEx-sc_FarExLast)<25&&(sc_FarEx-sc_FarExLast)>-25)
      sc_FarExLast=sc_FarEx;
    else
      sc_FarEx=sc_FarExLast;
  }
  else
    sc_FarEx=sc_FarExLast;
  

//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//中间黑线坐标中心值。
  uiSum=0;
  ucCount=0;
  for(ucColumn=COLUMN_MIN+2;ucColumn<COLUMN_MIN+7;ucColumn++)
  {
    for(ucRow=ROW_MIN;ucRow<ROW_MAX;ucRow++)
    {
      pucTemp=puca_BufferProcess+ucRow*IMAGE_COLUMN+ucColumn;
      
      if(*pucTemp==BLACK_POINT)
      {
        uiSum+=ucRow;
        ucCount++;
      }
    }
  }
  
  if(ucCount>20)
  {
    sc_CenterEx=(unsigned char)(uiSum/ucCount)-VIDEO_CENTER;
    if((sc_CenterEx-sc_CenterExLast)<25&&(sc_CenterEx-sc_CenterExLast)>-25)
      sc_CenterExLast=sc_CenterEx;
    else
      sc_CenterEx=sc_CenterExLast;
  }
  else
    sc_CenterEx=sc_CenterExLast;

//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//近处黑线坐标中心值。
  uiSum=0;
  ucCount=0;
  for(ucColumn=COLUMN_MIN+8;ucColumn<COLUMN_MAX;ucColumn++)
  {
    for(ucRow=ROW_MIN;ucRow<ROW_MAX;ucRow++)
    {
      pucTemp=puca_BufferProcess+ucRow*IMAGE_COLUMN+ucColumn;
      
      if(*pucTemp==BLACK_POINT)
      {
        uiSum+=ucRow;
        ucCount++;
      }
    }
  }
  
  if(ucCount>12)
 
  {
    sc_NearEx=(unsigned char)(uiSum/ucCount)-VIDEO_CENTER;
    if((sc_NearEx-sc_NearExLast)<25&&(sc_NearEx-sc_NearExLast)>-25)
      sc_NearExLast=sc_NearEx;
    else
      sc_NearEx=sc_NearExLast;
  }
  else
    sc_NearEx=sc_NearExLast;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -