What algorithm can be used to determine the presence of multiple stripes?
Using python, which may be the best algorithm or the best strategy to detect the presence of colored bands as in image? The image is scanned and cropped, the problem is that the crop not to be precise and I can not make use of a control that makes use of Cartesian coordin开发者_StackOverflow中文版ates to determine if the lines are present. The strips may be present or not.
You have a number of options at your disposal:
- If the strips are going to be the same size, and their orientation is known, then you can use cross-correlation (with working Python source). Your template image could be a single stripe, or a multiple strip pattern if you know the number of strips and their spacing.
- More generally, you could go with morphological image processing and look for rectangles. You'd first have to threshold your image (using Ohtsu's method or some empirically determined threshold) and then perform contour detection. Here's an example that does something similar, but for ellipses -- it's trivial to modify it to look for rectangles. This time the source in in C, but it uses OpenCV like the first example, so it should be trivial to port
- There are other approaches such as edge detection and Fourier analysis, but I really think that the first two are going to be more than enough for you.
精彩评论