Reputation: 2061
I'm applying an erode operation to a Mat
, but it's being extremely slow.
Since in OpenCV you can apply it by two different ways (using morphologyEx
and using erode
).
I'm measuring (approximately) how fast does it runs, but both them are being extremely slow!
The code for this part is:
int morph_size = 20;
Mat element = getStructuringElement( MORPH_ELLIPSE, cv::Size( 2*morph_size + 1 , 2*morph_size +1), cv::Point( morph_size, morph_size ) );
// morphologyEx(imgMascara, imgMascara, MORPH_ERODE, element );
finish_time5 = clock();
erode( imgMascara, imgMascara, element );
finish_time6 = clock();
Where imgMascara
is a Mat
. Then, When I'm measuring the time since the start to finish_time5
and finish_time6
, I'm getting:
0.0198s
0.887s
Any idea about why does it takes too much time? (It happen for both the functions, morphologyEx
and erode
).
Thank you in advance
Upvotes: 2
Views: 4623
Reputation: 2061
I've found the reason of the lentitude of the erode. There're three different reasons:
However, I can't do this, because I need this kernel size. So I continued looking for another reason, and found out:
MORPH_ELLIPSE
). If I change it to MORPH_RECT
or MORPH_CROSS
, it becomes drastically faster.Since my app works great with all them, I just changed it to MORP_RECT
.
Thank you all for your comments that helped me to find out these
Upvotes: 11