Working with regions in opencv?
Hello, currently I’m in the training phase of opencv. I have previously worked with another image processing-library. In that library you were working with regions. This brings an extreme time advantage. Does something similar exists in opencv?
For example in opencv a normal threshold followed by an erosion with a circular mask of 200 px takes approximately 7 seconds. (On a small VGA-Image)
Thanks for replies in advance.
200px is it radius? Can you show your code. What is your platform?
I am using c++, visual studio 13, opencv 3.1. I think 200px is the diameter.
Code snippet:
Mat elementCirc = getStructuringElement(MORPH_ELLIPSE, cv::Size(200, 200));
Mat closed = Mat();
cv::morphologyEx(roi, closed, cv::MORPH_CLOSE, elementCirc, cv::Point(-1, -1), 1);
Can you give size of roi?
The contour diameter is 130 px. And it is as a circular object.
link text
in release 1.17s in debug 15s with this program
For this simple task, i was thinking of times in the 1 ms range (like in halcon). The opencv standard functions are not time optimized right? What do i have to do for reaching that goal?
I think you should check if it is exactly same kernel. You opencv withcuda if you want to improve speed. I have some difficulty to understand speed ratio of 100
Kernal should be the same. I'll have a look at cuda. I am sceptical, because in Halcon the GPU advantage was not that huge. Perhaps it is different in opencv.
At the moment i have no access to a cuda GPU. But i tried to program my own erode, which is faster using bigger masks but still by far too slow. Perhaps you have an idea for optimization?
cv::threshold(channels[2], threshed, (int)numericRedThresh->Value, 255, THRESH_BINARY);
int eroval = (int)nmrc_erosion->Value;
time1 = clock();
//Standard erode
Mat opencvEroImg;
Mat mask = getStructuringElement(MORPH_ELLIPSE, cv::Size(eroval, eroval));
erode(threshed, opencvEroImg, mask, cv::Point(-1, -1), 1);
time2 = clock();
//Attempt for own erosion
eroval = eroval / 2;
Mat ownEroImg = threshed.clone();
for (int r = 0; r<threshed.rows; r++)<="" p="">
{
for (int c = 0; c<threshed.cols; c++)<="" p="">
{
int test = threshed.at<char>(r, c);
//Black?
if (test == 0)
{
...
int ri = threshed.at<char>(r, c + 1);
}
}
time3 = clock();
time1 = time2 - time1;
time2 = time3 - time2;
imshow("opencvEro", opencvEroImg); imshow("ownEro", ownEroImg);