Detect objects similar to circles

前端 未结 2 1476
既然无缘
既然无缘 2021-02-04 17:20

I\'m trying to detect objects that are similar to circles using OpenCV\'s HoughCircles. The problem is: HoughCircles fails to detect such objects in so

相关标签:
2条回答
  • 2021-02-04 17:40

    Give try on below,

    1. Find contour in source.

    2. Find minimum enclosing circle for the contour.

    3. Now draw contour to new Mat with CV_FILLED.

    4. Similarly draw enclosing circle to new Mat with filled option.

    5. Perform x-or operation between the above two and count non-zero.

    6. You can decide the contour is close to circle or not by comparing the non-zero pixel between contour and enclosimg circle with a threshold. You can decide the threshold by calculating the area of encosing circle, and taking it percent.

    The idea is simple the area between contour and its enclosing circle decreases as the contour closes to circle

    0 讨论(0)
  • 2021-02-04 17:46

    Edited based on new description and additional performance and accuracy requirements.


    This is getting beyond the scope of an "OpenCV sample project", and getting into the realm of actual application development. Both performance and accuracy become requirements.

    This requires a combination of techniques. So, don't just pick one approach. You will have to try all combinations of approaches, as well as fine-tune the parameters to find an acceptable combination.


    #1. overall approach for continuous video frame recognition tasks

    • Use a slow but accurate method to acquire an initial detection result.

    • Once a positive detection is found on one frame, the next frame should switch to a fast local search algorithm using the position detected on the most recent frame.

    As a reminder, don't forget to update the "most recent position" for use by the next frame.


    #2. suggestion for initial object acquisition.

    • Stay with your current approach, and incorporate the suggestions.

    • You can still fine-tune the balance between speed and precision, because a correct but imprecise result (off by tens of pixels) will be updated and refined when the next frame is processed with the local search approach.

      • Try my suggestion of increasing the dp parameter.

    A large value of dp reduces the resolution at which Hough Gradient Transform is performed. This reduces the precision of the center coordinates, but will improve the chance of detecting a dented circle because the dent will become less significant when the transform is performed at a lower resolution.

    An added benefit is that reduced resolution should run faster.


    #3. suggestion for fast local search around a previously detected position

    Because of the limited search space and amount of data needed, it is possible to make local search both fast and precise.

    For tracking the movement of the boundary of iris through video frames, I suggest using a family of algorithms called the Snakes model.

    The focus is on tracking the movement of edges through profiles. There are many algorithms that can implement the Snakes model. Unfortunately, most implementations are tailored to very complex shape recognition, which would be an overkill and too slow for your project.

    Basic idea: (assuming that the previous result is a curve)

    1. Choose some sampling points on the curve.
    2. Scan the edge profile (perpendicular to the curve) at each the sampling point, on the new frame, using the position of the old frame. Look for the sharpest change.
    3. Remember the new edge position for this sampling point.
    4. After all of the sampling points have been updated, create a new curve by joining all of the updated sampling point positions.

    There are many varieties, and different levels of sophistication of implementations which you can find on the Internet. Unfortunately, it was reported that the one packaged with OpenCV might not work very well. You may have to try different open-source implementation, and ultimately you may have to implement one that is simple but well-tuned to your project's needs.


    #4. Seek advice for your speed optimization attempts.

    • Use a software performance profiler.

    • Add some timing and logging code around each call to OpenCV function to print out the time spent on each step. You will be surprised. The reason is that some OpenCV functions are more heavily vectorized and parallelized than others, perhaps as a result of the labor of love.

    • Unfortunately, for the slowest step - initial object acquisition, there is not much you can parallelize (by multithread).

    This is perhaps already obvious to you since you did not put #pragma omp for around the first block of code. (It would not help anyway.)

    • Vectorization (SIMD) would only benefit pixel-level processing. If OpenCV implements it, great; if not, there is not much you can do.

    My guess is that cvtColor, GaussianBlur, threshold, dilate, erode could have been vectorized, but the others might not be.


    0 讨论(0)
提交回复
热议问题