Ask Your Question
1

Advices about finding pointing of a bottle with opencv

asked 2015-04-20 04:08:58 -0600

dialgop gravatar image

Hello everyone, I am relatively new in OpenCV (Already checked some tutorials and I am learning on some additional programs how it works) and I know some things, however I have an assignment to work with in opencv (spin the bottle game) which goes somehow a little out of the scope of what I know.

Based on the direction that a bottle (Yes, a common bottle like a beer bottle) points in a 2d plane (a photo of a bottle) I need to create an opencv method to draw a line where the bottle points at. I heard something about Houghlines and I am currently working on that, however if you have some advices or know about other Opencv library functions that I can use, then I would be very thankful to you.

Pd: I have already decomposed the image into its edges (in case this can help to give any idea)

image description

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2015-04-20 04:39:30 -0600

If you can get this clean segmentation of the bottle each time you perform it the following steps are quite easy!

  1. Your image is binary and thus contains a cloud of edge points indicating your bottle.
  2. Now put all the points that have the edge pixel value into a vector of points.
  3. Apply PCA on the point cloud and look for the eigenvalues and principle components.
  4. This will result in the direction that the bottle is pointing to and allow you to draw a line!

More info on PCA in OpenCV can be seen in this example.

edit flag offensive delete link more

Comments

1

The drawback of this approach is that you only get the direction without a sign, so another step is needed. I'd propose to use the angle of the main Axis and to rotate the image so that you have an image of the bottle upright (or upside down). You then check the topmost and lowest columns and compute the horizontal variance of the white pixels. The variance at the bottom of the image will be much larger and you are able to tell in which direction your bottle is pointing.

FooBar gravatar imageFooBar ( 2015-04-20 04:45:04 -0600 )edit
1

Indeed, getting the orientation is indeed the second part of the problem :D But I guess that getting the overal direction is already quite challenging for TS.

StevenPuttemans gravatar imageStevenPuttemans ( 2015-04-20 04:53:48 -0600 )edit
1

If you have the direction and the midpoint of the contour, you can split the contour into 2 parts (on the "left" and "right") relative to the midpoint and in the found direction, and compute the area of the 2 contours. The one that has the smallest area is the top of the bottle, so that is the pointing direction of your bottle. Maybe it is not the best, but is an idea of continuation.

thdrksdfthmn gravatar imagethdrksdfthmn ( 2015-04-20 07:24:20 -0600 )edit

Actually it is a quite good solution which will work just fine here :)

StevenPuttemans gravatar imageStevenPuttemans ( 2015-04-20 08:25:10 -0600 )edit
1

Hey, thanks for all of the ideas. You are awesome guys. I will keep asking here because this is my first approach, later I will have to cope with several objects (identify them) and also to use several multicolored backgrounds and so on. But for now it's really good.

dialgop gravatar imagedialgop ( 2015-04-24 05:29:04 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2015-04-20 04:08:58 -0600

Seen: 526 times

Last updated: Apr 20 '15