Ask Your Question
0

[Newbie] Can OpenCV find a straight boundary?

asked 2015-02-26 13:31:26 -0600

Qodex gravatar image

I have images that consist of a light area and a dark area. The boundary between the two areas is either curved, straight, or a combination (curved then straight). I need to determine if the image contains a straight segment in the boundary, and if so, its angle relative to the bottom of the image. I don't need any other output, such as the image that the Canny edge detector generates.

If OpenCV can do this, which functions should I look at?

What's really happening: a round integrated circuit wafer has a flat edge on one side. The wafer is being rotated on a spindle under a camera, and the rotation needs to stop when the flat edge reaches the top of the frame. A couple of sample images are shown below. Note in the first image the transition from straight to curved edge in the upper right corner. The second image shows where rotation should stop. (The text below the flat edge will then be OCR'ed.) Since the flat edge will always rotate into the frame in more-or-less the same spot on the right edge of the frame, it seems it would be sufficient to analyze just that small area looking for the flat edge, but would that be enough data for OpenCV to work with?

Thanks for your help!

Wafer 1

Wafer 2

Wafer sizes

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2015-02-26 14:37:20 -0600

matman gravatar image

updated 2015-02-26 14:37:59 -0600

Take a look at Hough transform. Thats not the fastest method, but it should be the easiest one. For lines: HoughLines and for circles: HoughCircles

If I got it right you want to detect in the first image the curved area as circle? I promise you there is no chance. HoughCircle will find a lot of circles when you have the right parameters, but for me that snippet looks very straight, because the arc length is very short. There will be distorsions that will be more kind of a circle.

edit flag offensive delete link more

Comments

Thanks for the suggestion, the example code looks promising. In the first image, no, I don't care about the curved section. All I care is if there is a straight section. My comment "...would that be enough data for OpenCV to work with?" is related to this question. How much data does OpenCV need in order to determine that the line is straight and not curved. Perhaps a little experimentation is needed. Speed may be a consideration; is there something else that is faster?

Qodex gravatar imageQodex ( 2015-02-26 14:49:27 -0600 )edit

"How much data does OpenCV need in order to determine that the line is straight and not curved" thats a question which has no exact answer, but is dependend of the measurement environment. If you have 3 points and they are not on a straight line is it a curve or is it because of noise/not exact measurement...

Faster algorithm: That will be a lot of hand work. If you have stable conditions for example do:

  • threshold

  • findContour

  • checkContours for curves and some other paramters. That will be the handwork, but you can look if there are useful functions here

The advantage is, that the number of data shrinks from image size to contour size

matman gravatar imagematman ( 2015-02-26 16:10:32 -0600 )edit

Mmh, the character I can use in a comment is very limited, so further on:

If you have a contour, the array will loose a dimension, so if you have a 1MPx camera you will typical deal with a contour size of about 1000 or 5000. The contours are coordinate points, so you can handle it as such. If there are no useful functions in OpenCV you can write your own ones just by passing a pointer to the data. So for example transform data to Eigen library for fitting problems is just passing the pointer of data storage to Eigen and back. So it will be useful to engage with OpenCV datastorage here and if you need to be realy fast watch for SSE and AVX

matman gravatar imagematman ( 2015-02-26 16:30:17 -0600 )edit

Did you already have any success? Which settings do you use for your hough transformation?

Janis_DE gravatar imageJanis_DE ( 2015-04-20 04:43:17 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2015-02-26 13:31:26 -0600

Seen: 466 times

Last updated: Feb 26 '15