4

I am thinking of implement a image processing based solution for industrial problem.

The image is consists of a Red rectangle. Inside that I will see a matrix of circles. The requirement is to count the number of circles under following constraints. (Real application : Count the number of bottles in a bottle casing. Any missing bottles???)

  1. The time taken for the operation should be very low.
  2. I need to detect the red rectangle as well. My objective is to count the items in package and there are no mechanism (sensors) to trigger the camera. So camera will need to capture the photos continuously but the program should have a way to discard the unnecessary images.
  3. Processing should be realtime.
  4. There may be a "noise" in image capturing. You may see ovals instead of circles.

My questions are as follows,

  1. What is the best edge detection algorithm that matches with the given scenario?
  2. Are there any other mechanisms that I can use other than the edge detection?
  3. Is there a big impact between the language I use and the performance of the system?
1
  • @Joe. The cases may be rotated a bot. There may be little deviations from ideal situations. Note that the industrial environment does not behave in the perfect way :) Commented Nov 8, 2010 at 0:16

6 Answers 6

8

AHH - YOU HAVE NOW TOLD US THE BOTTLES ARE IN FIXED LOCATIONS!

IT IS AN INCREDIBLY EASIER PROBLEM.

All you have to do is look at each of the 12 spots and see if there is a black area there or not. Nothing could be easier.

You do not have to do any edge or shape detection AT ALL.

It's that easy.

You then pointed out that the box might be rotatated, things could be jiggled. That the box might be rotated a little (or even a lot, 0 to 360 each time) is very easily dealt with. The fact that the bottles are in "slots" (even if jiggled) massively changes the nature of the problem. You're main problem (which is easy) is waiting until each new red square (crate) is centered under the camera. I just realised you meant "matrix" literally and specifically in the sentence in your original questions. That changes everything totally, compared to finding a disordered jumble of circles. Finding whether or not a blob is "on" at one of 12 points, is a wildly different problem to "identifying circles in an image". Perhaps you could post an image to wrap up the question.


Finally I believe Kenny below has identified the best solution: blob analysis.


"Count the number of bottles in a bottle casing"...

Do the individual bottles sit in "slots"? ie, there are 4x3 = 12 holes, one for each bottle.

In other words, you "only" have to determine if there is, or is not, a bottle in each of the 12 holes.

Is that correct?

If so, your problem is incredibly easier than the more general problem of a pile of bottles "anywhere".

Quite simply, where do we see the bottles from? The top, sides, bottom, or? Do we always see the tops/bottoms, or are they mixed (ie, packed top-to-tail). These issues make huge, huge differences.

1
  • 2
    +1: predefined number of slot = for each slot define a square, count the non-black pixels in the square, with a decent illumination there should be a great difference between an empty slot and a non-empty one. any image processing library will do that almost in real-time, even on small embedded smart-cameras. Commented Nov 7, 2010 at 12:25
3

Surf/Sift = overkill in this case you certainly don't need it.

If you want real time speed (about 20fps+ on a 800x600 image) I recommend using Cuda to implement edge detection using a standard filter scheme like sobel, then implement binarization + image closure to make sure the edges of circles are not segmented apart.

The hardest part will be fitting circles. This is assuming you already got to the step where you have taken edges and made sure they are connected using image closure (morphology.) At this point I would proceed as follows:

  1. run blob analysis/connected components to segment out circles that do not touch. If circles can touch the next step will be trickier
  2. for each connected componet/blob fit a circle or rectangle using RANSAC which can run in realtime (as opposed to Hough Transform which I believe is very hard to run in real time.)

Step 2 will be much harder if you can not segment the connected components that form circles seperately, so some additional thought should be invested on how to guarantee that condition.

Good luck.

Edit

Having thought about it some more, I feel like RANSAC is ideal for the case where the circle connected components do touch. RANSAC should hypothetically fit the circle to only a part of the connected component (due to its ability to perform well in the case of mostly outlier points.) This means that you could add an extra check to see if the fitted circle encompasses the entire connected component and if it does not then rerun RANSAC on the portion of the connected component that was left out. Rinse and repeat as many times as necessary.

Also I realize that I say circle but you could just as easily fit an ellipse instead of circles using RANSAC.

Also, I'd like to comment that when I say CUDA is a good choice I mean CUDA is a good choice to implement the sobel filter + binirization + image closing on. Connected components and RANSAC are probably best left to the CPU, but you can try pushing them onto CUDA though I don't know how much of an advantage a GPU will give you for those 2 over a CPU.

4
  • The whole set of SURF/SIFT features is an overkill, certainly, but in terms of design time, using an existing SIFT/SURF feature extractor could be quicker than writing a custom algorithm by oneself, and there is a real risk that any custom solution will have a poorer end performance than those highly optimized algorithms (I know it has happened to me before). Commented Oct 5, 2010 at 21:30
  • @Gregor Petrin: Indeed your point is a valid one; however, in this particular case the license for the use of SIFT and SURF are both highly restrictive and essentially don't let anyone use them for commercial purposes. Furthermore, as far as I remember SIFT and SURF implementations are currentlty not real time.
    – ldog
    Commented Oct 5, 2010 at 22:22
  • +1, But I don't think you need CUDA for that. Use a high-performance library like IPP that uses modern CPU's SIMD instructions, and you should be able to do sobel-filtering, binarization, morphological operations at 20 Hz easily. Probably even if you use only one core.
    – Niki
    Commented Nov 6, 2010 at 20:13
  • CUDA for a 20fps sobel+bin+close ? are you sick ?? you can do so much more with a simple image processing library on a decent processor ! i personally achieve 30fps using the slowest image processing library existing (which is NI Vision). Matrox MIL or Intel IPP should be really enough for that job. Commented Nov 7, 2010 at 12:22
2
  • For the circles, try the Hough transform.
  • other mechanisms: dunno
  • Compiled languages will possibly be faster.
2
  • Updated my question a bit. Images may not be extremely sharp. We are not going to use the cameras with very high shutter speeds. So We may capture the circles as Ovals. Can I use a correction with hough transform for this? Commented Oct 5, 2010 at 11:37
  • hough transform for finding circles requires that you know the size of the circles beforehand if you want to achieve a decent framerate. Commented Nov 7, 2010 at 12:28
2

SIFT should have a very good response to circular objects - it is patented, though. GLOHis a similar algorithm, but I do not know if there are any implementations readily available.

Actually, doing some more research, SURF is an improved version of SIFT with quite a few implementations available, check out the links on the wikipedia page.

2
  • SIFT must have a poor behavior on circles because they are symmetrical so that there is no preferred place for them to appear.
    – user1196549
    Commented Jul 17, 2018 at 16:40
  • Just a quick note that SIFT patent expired in 2020.
    – Robinson
    Commented May 12, 2022 at 0:53
1
  1. Sum of colors + convex hull to detect boundary. You need, mostly, 4 corners of a rectangle, and not it's sides?
  2. No motion, no second camera, a little choice - lot of math methods against a little input (color histograms, color distribution matrix). Dunno.
  3. Java == high memory consumption, Lisp == high brain consumption, C++ == memory/cpu/speed/brain use optimum.
1
1

If the contrast is good, blob analysis is the algorithm for the job.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.