Algorithms for retrieving limbs and heads from outlines

Source: Internet
Author: User

Algorithms for retrieving limbs and heads from outlines

The algorithm for getting the limbs and the head is implemented, that is, getting five U-shaped endpoints.


The algorithm is as follows:

Int segmentbody (cvseq * contour)
{
Float standbodylength = 10.0;
Float standarc = 40;
Float LK, L1, L2 = 0;
Cvpoint pt1, pt2, pt0;
Double total_arc = 0; // inner Rotation Angle
Double rarc12 = 0;
Double arc12 = 0;
 
Bool haslkvec = false; // whether a previously recorded vector exists

Cvseqreader reader;
Cvseqreader subreader;
Int n = contour-> total;
Int I;
Cvpoint pt;
Cvpoint pre_pt;
Cvpoint pre_pre_pt;

// Cvfont font;
// Cvinitfont (& font, cv_font_hershey_simplex, 0.3, 0.3, 0.0, 1, cv_aa );

Cvstartreadseq (contour, & reader );

For (I = 0; I <n; I ++)
{
Cv_read_seq_elem (PT, Reader );
// Printf ("% d, % d/N", Pt. X, Pt. y );
Pre_pt = pre_pre_pt = pt;


// Draw_cross (PT, cv_rgb (255,255,255), 3 );

If (I = 9)
Draw_cross (PT, cv_rgb (240,222,240), 3 );

// Cvline (DST, PT, pre_pt, cv_rgb (0,255, 0), 2, cv_aa, 0 );
// Calculate the distance between two points
Subreader = reader;

Haslkvec = false;
Total_arc = 0;

// Printf ("------------------/N ");
// Printf ("% d, % d/N", Pt. X, Pt. y );
For (Int J = 0; j <5; j ++)
{
// Printf ("in sub % d, % d/N", Pt. X, Pt. y );
L1 = calc_2point_magn.pdf (PT, pre_pt );
If (L1> standbodylength)
{
// Check whether a previously recorded point exists. If yes, check the angle range.
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); // use the cross set to check whether the vector is in the inner or outer rotation.
If (vtnor. z> 0) total_arc + = rarc12;
Else total_arc-= rarc12;


// Check that the angle range is reasonable-200-160
If (ABS (total_arc + 180) <standarc)
{

// Check whether the Quadrilateral between parallel lines is on the same axis, and determine the similarity
If (is_closed_vectors (PT, pre_pt, pt1, pt2 ))
{
// A search is completed successfully.
// Record two vectors and clear the mark
Haslkvec = false;
Total_arc = 0;
// Draw the position
Draw_2points (PT, pre_pt, pt1, pt2 );

// Skip the formed points. The advantage is to reduce the calculation, and the second is to avoid different points.
For (int K = 0; k <j; k ++)
{
Cv_read_seq_elem (PT, Reader );
Pre_pt = pre_pre_pt = pt;
}

}
// Cvshowimage ("components", DST );
// Cvwaitkey (0 );

Break;
}

}
Else
{
// Record two points
Pt1 = pt;
Pt2 = pre_pt;
Haslkvec = true;
}

}
// Ignore short-term segments and skip their detection points to speed up detection.
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;
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.