//Creted a new function that take image pointer and int reference as parameter and return center coordinates and pixel count Point2D& ColorFinder::GetPosition(Image* hsv_img, int &count) { int sum_x = 0, sum_y = 0, count = 0; Filtering(hsv_img); ImgProcess::Erosion(m_result); ImgProcess::Dilation(m_result); for(int y = 0; y < m_result->m_Height; y++) { for(int x = 0; x < m_result->m_Width; x++) { if(m_result->m_ImageData[m_result->m_Width * y + x] > 0) { sum_x += x; sum_y += y; count++; } } } if(count <= (hsv_img->m_NumberOfPixels * m_min_percent / 100) || count > (hsv_img->m_NumberOfPixels * m_max_percent / 100)) { m_center_point.X = -1.0; m_center_point.Y = -1.0; } else { m_center_point.X = (int)((double)sum_x / (double)count); m_center_point.Y = (int)((double)sum_y / (double)count); } return m_center_point; }