中级会员
- 积分
- 238
- 威望
- 196
- 贡献
- 38
- 兑换币
- 16
- 注册时间
- 2010-3-22
- 在线时间
- 2 小时
|
CCDData是摄像头采集数据的指针,图像是用一个一维数组存储的,引用其值要写做*(CCDData+偏移量)
给个程序你参考下,应该就会用了。
#include "stdafx.h"
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
extern "C" _declspec(dllexport)
void Judge( unsigned short Speed,
unsigned char* SensorData, unsigned short SensorCount,
unsigned char* CCDData, int CCDWidth, int CCDHeight,
unsigned short* MotorPWM, unsigned short* SteerPWM)
{
CCDWidth=76; CCDHeight=30;
int CCDW,CCDH,startpoint,left,right,CCDWend,x;
int ccdMP[30];
for(CCDW=0;CCDW<CCDWidth/2;CCDW++)
{
if(*(CCDData+CCDWidth/2+CCDW)<100) {startpoint=CCDWidth/2+CCDW;CCDW=CCDWidth/2;}
else
if(*(CCDData+CCDWidth/2-CCDW)<100) {startpoint=CCDWidth/2-CCDW;CCDW=CCDWidth/2;}
}
ccdMP[0]=startpoint;
left=startpoint;
right=startpoint;
for(CCDH=0;CCDH<CCDHeight;CCDH++)
{
while((*(CCDData+left+CCDWidth*CCDH)<100)&&(left<ccdMP[CCDH]-20)&&(left>-1))
{
left--;
}
while((*(CCDData+right+CCDWidth*CCDH)<100)&&(right<ccdMP[CCDH]+20)&&(right<76))
{
right++;
}
if((left==ccdMP[CCDH]-20)||(right==ccdMP[CCDH]+20)||(left==-1)||(right==76))
{
CCDWend=CCDH;
CCDH=CCDHeight;
}
else
{
ccdMP[CCDH]=(left+right)/2;
left=ccdMP[CCDH];
right=ccdMP[CCDH];
}
}
x=0;
for(CCDH=0;CCDH<CCDWend;CCDH++) x+=ccdMP[CCDH];
x=x/CCDWend-38;
*SteerPWM=32768+x*800;
*MotorPWM=5000;
}
extern "C" _declspec(dllexport)
void Reset()
{
} |
|