CvSeq* contour_max=0;
CvSeqReader seq_reader;
CvPoint* hull_next;
if (contour_max!=0)
{
cvStartReadSeq(contour_max,&seq_reader,0);//读序列
for (i=0;i<contour_max->total;i++)
{
hull_next = CV_GET_SEQ_ELEM( CvPoint, contour_max, i );//得到序列中具体的值
fprintf(steam,"%d %d /n",hull_next->x,hull_next->y);
}
1、轮廓
CvScalar color = CV_RGB( rand()&255, 0, 0 );
cvDrawContours(src, contour_max, color, color, -1, -1, 8);//对轮廓进行填充
cvDrawContours(src, contour_max, color, color, -1, 1, 8);//对轮廓进行绘制
1、计算一个点到另外2点连线之间的距离
double k= 0.0;//斜率
double b = 0.0;
if (fabs(ptsrc2.x - ptsrc1.x)> 0.001)
{
k = (double)(ptsrc2.y - ptsrc1.y)/(ptsrc2.x - ptsrc1.x);//水平方向斜率
b = ptsrc2.y - k*ptsrc2.x ;
}
else
{
k = tan(PI/2);
b = ptsrc2.y - k*ptsrc2.x ;
}
return fabs(k*ptdst.x - ptdst.y +b)/sqrt(k*k+1);
2、计算一个点到另外2点连线之间的距离
double dx0 = (double)ptsrc1.x - (double)ptsrc2.x;
double dy0 = (double)ptsrc1.y - (double)ptsrc2.y;
assert( dx0 != 0 || dy0 != 0 );
double scale = 1./sqrt(dx0*dx0 + dy0*dy0);
double dx = (double)ptdst.x - (double)ptsrc2.x;
double dy = (double)ptdst.y - (double)ptsrc2.y;
double dist = fabs(-dy0*dx + dx0*dy) * scale;
return dist;