从轮廓中取得四肢与头部的算法
实现了取得四肢与头部的算法,即取得五个U形的端点.
算法如下:
- int SegmentBody(CvSeq* contour)
- {
- float StandBodyLength = 10.0;
- float StandArc = 40;
- float lk,l1,l2=0;
- CvPoint pt1,pt2,pt0;
- double total_arc = 0;
- double rarc12= 0;
- double arc12= 0;
-
- bool Haslkvec = false;
-
- CvSeqReader reader;
- CvSeqReader subReader;
- int N = contour->total;
- int i;
- CvPoint pt;
- CvPoint pre_pt;
- CvPoint pre_pre_pt;
-
-
-
-
-
- cvStartReadSeq(contour, &reader);
-
- for (i= 0; i < N; i++)
- {
- CV_READ_SEQ_ELEM(pt, reader);
-
- pre_pt = pre_pre_pt = pt;
-
-
-
-
- if(i==9)
- draw_cross( pt, CV_RGB(240,222,240), 3 );
-
-
-
- subReader = reader ;
-
- Haslkvec = false;
- total_arc =0;
-
-
-
- for(int j=0;j<5;j++)
- {
-
- l1=calc_2Point_Magnitude(pt,pre_pt);
- if (l1>StandBodyLength)
- {
-
- if(Haslkvec)
- {
- Vector3f vt1 = Vector3f (pre_pre_pt.x-pre_pt.x,pre_pre_pt.y-pre_pt.y,0);
- Vector3f vt2 = Vector3f (pre_pt.x-pt.x,pre_pt.y-pt.y,0);
- arc12 = AngleBetweenVectors(vt1,vt2);
- rarc12 = 180*arc12/pi;
- Vector3f vtnor=Cross(vt1,vt2);
- if(vtnor.z >0) total_arc += rarc12;
- else total_arc -= rarc12;
-
-
- if (abs(total_arc+180)<StandArc)
- {
-
- if(Is_Closed_Vectors(pt,pre_pt,pt1,pt2))
- {
-
-
- Haslkvec = false;
- total_arc = 0;
-
- draw_2Points(pt,pre_pt,pt1,pt2);
-
- for(int k=0;k<j;k++)
- {
- CV_READ_SEQ_ELEM(pt, reader);
- pre_pt = pre_pre_pt = pt;
- }
- }
-
-
- break;
- }
-
- }
- else
- {
-
- pt1=pt;
- pt2=pre_pt;
- Haslkvec = true;
- }
-
- }
-
- else
- {
- pt = pre_pt;
- pre_pt = pre_pre_pt;
- }
-
- pre_pre_pt = pre_pt;
- pre_pt= pt;
- CV_READ_SEQ_ELEM(pt, subReader);
- }
- }
-
- return 0;
- }
(hardVB) |