, GetLineFromEndPts(), . a b, , a b. , , , .
int GetLineFromEndPts(CvPoint a, CvPoint b, CvSeq* contour){
if (contour==NULL) {
printf("ERROR! contour in GetLineFromEndPts() is NULL!\n");
return -1;
}
float d=dist(a,b);
float ihat= ( (float) (b.x -a.x) ) /d;
float jhat= ( (float) (b.y -a.y) ) /d;
CvPoint currPt;
CvPoint prevPt=a;
currPt=a;
CvSeqWriter writer;
cvStartAppendToSeq( contour, &writer );
int t;
float tempPtx;
float tempPty;
int signx=1;
int signy=1;
for (t = 0; t < (int) (d+0.5) ; ++t) {
tempPtx=(float) t * ihat + (float) a.x;
tempPty=(float) t * jhat + (float) a.y;
if (tempPtx<0) {
signx=-1;
} else {
signx=1;
}
if (tempPty<0) {
signy=-1;
} else{
signy=1;
}
currPt=cvPoint((int) ( tempPtx + (float) signx * 0.5 ) ,
(int) ( tempPty + (float) signy * 0.5 ));
if ( t==0 || !( currPt.x == prevPt.x && currPt.y == prevPt.y ) ){
CV_WRITE_SEQ_ELEM( currPt, writer );
printf(" t=%d\n",t);
printf(" currPt.x=%d\n",currPt.x);
printf(" currPt.y=%d\n",currPt.y);
}
prevPt=currPt;
}
cvEndWriteSeq( &writer );
return 1;
}
:
int sqDist(CvPoint pta, CvPoint ptb){
return ( ((pta.x - ptb.x)*(pta.x - ptb.x) ) + ((pta.y - ptb.y)*(pta.y - ptb.y) ) );
}
:
float dist(CvPoint a, CvPoint b){
return ( sqrt( (float) sqDist(a,b)) );
}
, , :
GetLineFromEndPts(cvPoint(0,0),cvPoint(10,15),test);
:
t=0
currPt.x=0
currPt.y=0
t=1
currPt.x=1
currPt.y=1
t=2
currPt.x=1
currPt.y=2
t=3
currPt.x=2
currPt.y=2
t=4
currPt.x=2
currPt.y=3
t=5
currPt.x=3
currPt.y=4
t=6
currPt.x=3
currPt.y=5
t=7
currPt.x=4
currPt.y=6
t=8
currPt.x=4
currPt.y=7
t=9
currPt.x=5
currPt.y=7
t=10
currPt.x=6
currPt.y=8
t=11
currPt.x=6
currPt.y=9
t=12
currPt.x=7
currPt.y=10
t=13
currPt.x=7
currPt.y=11
t=14
currPt.x=8
currPt.y=12
t=16
currPt.x=9
currPt.y=13
t=17
currPt.x=9
currPt.y=14