文档介绍:文档.
2/8
1/8
机器视觉算法之物体方位特征提取
在机器视觉处理中,我们经常要对检测到的物体的方位特征进行评估。比如说,我们要OCR识别一个字符串。那么这个字符串与x轴的夹角就很重要,我们需要这个信息把这个字符串转e::Format_RGB32:
caseQImage::Format_ARGB32:
caseQImage::Format_ARGB32_Premultiplied:
for(inti=0;i<height;i++)
{
constQRgb*pSrc=(QRgb*)(i);
uchar*pDest=(uchar*)ret・scanLine(i);
for(intj=0;j<width;j++)
{
pDest[j]=qGray(pSrc[j]);
}
}
break;
}
returnret;
文档
文档.
6/8
7/8
QPointFcenter(constQlmage&image,intvalue)
{
if(image・isNull()||image・format()!=QImage::Format_Indexed8)
{
returnQPointF(-1,-1);
}
intwidth=();
intheight=();
intx_mean=0;
inty_mean=0;
intcount=0;
for(intj=0;j<height;j++)
{
constuchar*p=(j);
for(inti=0;i<width;i++)
{
if(
p[i]==value)
{
x_mean+=i;y_mean+=j;count++;
}
}
}
returnQPointF((double)x_mean/count,(double)y_mean/count);}
StructELLIPSE_PARA
{-一
doublex_mean;〃椭圆的中心坐标x
doubley_mean;〃椭圆的中心坐标y
doubler1;〃椭圆的长轴半径
doubler2;〃椭圆的短轴半径
doubletheta;〃椭圆的长轴与x轴的夹角(逆时针)
};
/**
briefellipseFit将一片区域当作椭圆来估计五个几何参数
paramimage
文档
文档.
6/8
7/8
文档
文档
8/8
9/8
paramvalue
parampara
*/
boolellipseFit(constQlmage&image,intvalue,ELLIPSE_PARA*para)
{
if(image・isNull()||image・format()!=QImage::Format_Indexed8)
{
returnfalse;
}
QPointFc=center(image,value);
intwidth=();
intheight=