I want to find the inner and outer diameter of the spring washer I calculated that I can create two ellipses with the fitellipse function of opencv and find the diameter with the help of these ellipses, but I cannot create two ellipses, only one ellipse is formed. How can I create two ellipses or is there any other way to find inner and outer diameters?
std::vector<std::vector<cv::Point> > contours;
std::vector<cv::Vec4i> hierarchy;
cv::Mat thresh_output;
double diameter[10000]{0};
int thresh=ui->cam_one_threshold->value();
cv::Mat openCvImage=cv::imread("deneme_calib.png");
cv::cvtColor(openCvImage, openCvImage, cv::COLOR_BGRA2GRAY);
cv::blur(openCvImage, openCvImage, cv::Size(3, 3));
cv::threshold(openCvImage,thresh_output, thresh, thresh*3, cv::THRESH_BINARY_INV);
cv::findContours(thresh_output, contours, hierarchy, cv::RETR_LIST, cv::CHAIN_APPROX_SIMPLE);
cv::cvtColor(openCvImage, openCvImage, cv::COLOR_GRAY2RGB);
for (int i = 0; i < (int)contours.size(); i++)
{
{
cv::drawContours(openCvImage, contours, i, cv::Scalar(0, 255, 0), 2, 8, hierarchy, 0, cv::Point());
diameter[i] =2*std::sqrt(cv::contourArea(contours[i]) / (M_PI));
cv::ellipse(openCvImage,cv::fitEllipse(contours[i]),cv::Scalar(0,0,255),1);
}
}