when I use minEnclosingCircle and minAreaRect function in win10 x64,I found that minEnclosingCircle is much slower than minAreaRect.My opencv version is 4.5.3.this is my code.
void pre_process(Mat &img)
{
cvtColor(img, img, COLOR_BGR2GRAY);
img = 255 - img;
threshold(img, img, 0, 240, THRESH_BINARY);
Mat element = getStructuringElement(MORPH_RECT, Size(5, 5));
for(int i = 0;i<5;i++)
morphologyEx(img, img, MORPH_ERODE, element);
}
int main()
{
Mat templateImg = imread("../TestImg/FF.bmp");
pre_process(templateImg);
vector<vector<Point>> contours_base;
findContours(templateImg, contours_base, RETR_EXTERNAL, CHAIN_APPROX_NONE);
Point2f center_temp;
float radius_temp;
double start = (double)getTickCount() / getTickFrequency();
minEnclosingCircle(contours_base[26], center_temp, radius_temp);
double end = (double)getTickCount() / getTickFrequency();
cout << "minEnclosingCircle use time: " << end - start << "s" << endl;
start = (double)getTickCount() / getTickFrequency();
RotatedRect rect_base = minAreaRect(contours_base[26]);
end = (double)getTickCount() / getTickFrequency();
cout << "minAreaRect use time: " << end - start << "s" << endl;
}
This is the output.
minEnclosingCircle use time: 1.09211s
minAreaRect use time: 0.000266s
This is my input img.
Is this normal for the lost time?