Ask Your Question

Revision history [back]

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.