Download Target Tracking For Robot Collaboration

Transcript
C++ Code for Hue Tacking
Total++;
goto label2;
}
}
label2: for(i=height1;i<height2-1;i++)
{
if(buffer[(height-1-i)*width + j] == 1)
{
Y += (m_CenterY - (height-i))*(m_CenterY - (height-i));
Total++;
goto label3;
}
}
label3: ;
}
if(Total != 0)
{
m_MomentY = Y/Total;
}
return;
}
// PROCEDURE: OnWindowSizeAndPosition
// TASK: Calculate the new size of the window surrounding the target object, which will be
//
processed in the next loop
void CHueTracker::OnWindowSizeAndPosition()
{
int W = m_un32ImageWidth;
int H = m_un32ImageHeight;
// The window's half size
m_WindowHeight = (int)(0.042*m_MomentY + m_Tolerance);
m_WindowLength = (int)(0.042*m_MomentX + m_Tolerance);
// The upper-left corner position of the window
m_WindowPositionX1 = m_CenterX - m_WindowLength;
if(m_WindowPositionX1 < 0 ) m_WindowPositionX1 = 0;
m_WindowPositionX2 = m_CenterX + m_WindowLength;
if(m_WindowPositionX2 > W) m_WindowPositionX2 = W;
m_WindowPositionY1 = m_CenterY - m_WindowHeight;
if(m_WindowPositionY1 < 0) m_WindowPositionY1 = 0;
m_WindowPositionY2 = m_CenterY + m_WindowHeight;
if(m_WindowPositionY2 > H) m_WindowPositionY2 = H;
// if the target is not found reset the window's size
if( m_CenterX == 0 && m_CenterY == 0)
{
m_WindowPositionX1 = 0;
m_WindowPositionX2 = W;
m_WindowPositionY1 = 0;
m_WindowPositionY2 = H;
}
return;
76