Ask Your Question

Bottle Detection

asked 2018-01-18 03:34:30 -0600

Werz gravatar image

updated 2018-01-19 01:56:28 -0600


I have the following application: Attached you can see some Images, it is a White Container with some different bottles in it (I made 4 Pictures to see the structure of this). There are 6 positions for the bottles, and 2 different bottle types in it. In different applications, all of the 6 positions can have a big bottle (called "tube"), a small bottle (called "Cup") or be empty. In the example Images you can see 2 Tubes, 2 Cups and 2 Empty positions.

A Camera is looking from the front to this Container, like in Image IMG_0001.JPG. The Task is to detect one of the 3 Options for each of the 6 positions (Is there a tube, a Cup or empty).

  • Additional Infos: Please do not consider the data Matrix codes on the backside, just ignore them.
  • The red lid of the large tubes is not present, please also ignore them (I forgot to unplug them before making Pictures)

How would you solve this Problem with OpenCV? Would you suggest a Special Illumination?

Thank you for helping

image description

image description

edit retag flag offensive close merge delete



can you try again, with the images ?

berak gravatar imageberak ( 2018-01-18 03:38:47 -0600 )edit

hello, the Problem is that I am not able to upload an Image, how does this work?

Werz gravatar imageWerz ( 2018-01-18 04:13:53 -0600 )edit

image upload through the "picture" symbol does not work, nor in internet explorer, neither in firefox. Also Attachment via zip fil does not work

Werz gravatar imageWerz ( 2018-01-18 04:18:35 -0600 )edit

It works for me. Why do you mean "it does not work"? have you got an error message. Image size must be less than 1MB

LBerger gravatar imageLBerger ( 2018-01-18 04:23:49 -0600 )edit

when I click on the Picture Symbol, a diolog opens for a link and for browsing a Picture on the local drive. When brwosing an clicking ok, the link of the Picture on the local drive appears in the field near the browse tab, but then when clicking ok, Dialog disappears and nothing happen, the same for the attachment symbol

Werz gravatar imageWerz ( 2018-01-18 04:45:43 -0600 )edit

I think you have choose first time an image with more than 1Mb and system is blocked after? Why ? I don't know. Try to post a new question and we will delete question later. Don't delete it please

LBerger gravatar imageLBerger ( 2018-01-18 04:53:38 -0600 )edit

@Werz , try to remove site cookies and login again.

mshabunin gravatar imagemshabunin ( 2018-01-18 05:02:29 -0600 )edit

you are right, the poictures has been bigger than 1MB; now I have compressed them to <1MB, but still it does not work, even with a new question post. I also have deleted all Cookies, without succes, still not possible :(

Werz gravatar imageWerz ( 2018-01-18 05:22:52 -0600 )edit

would it be possible, that I mail someone the Images, that uploades them then?

Werz gravatar imageWerz ( 2018-01-18 06:36:10 -0600 )edit

post a download link from gdrive or similar

procton gravatar imageprocton ( 2018-01-18 06:52:45 -0600 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2018-01-19 02:30:32 -0600

VxW gravatar image


the illumination is not so important, but they should be constant (avoid interfering light).

  • In a first step I would try to detect the box based on the outer contours, or place the box on a fixed position and define a mask
  • Second define a roi and calculate the profile for this roi, before you can apply a e.g. median filter to eliminate noise (see images below)
  • Third, for each tube, cup or empty there is a unique profile characteristics
  • Fourth, compare the unique characteristics with a current one based on a distance measure

Instead of comparing the profiles you can also try to do a template matching approach.

Image with ROI including background

image description

Image with ROI within box

image description

Image with applied median filter before

image description


edit flag offensive delete link more


Hello, thank you very much for this proposal.

The good News is: The box is always on a fixed Position and is not moving during detection.

This is a very good idea, to Analyse the Profile. The Problem is, that this red Labels on the big tubes are not always present. But anyway, there should be a way to distinguish between this 2 types by this strategy.

Have you done this Analysis you posted above with open cv? Could you please tell me, which functions you have used?

I will try to Analyse this on the real System, thank you very much. If you have additional ideas, please let me know!


Werz gravatar imageWerz ( 2018-01-22 02:29:24 -0600 )edit


I have now uploaded a Picture from the real System with the real Background, see link here:

(I am still not able to upload Images directly...)

As you can see, there are 4 different Containers, 3 of them are "Tubes", and one of them is a "Cup" (the Little one).

The Problem is, that they are overlapping in the worst case. Additionally, in one of the Images on of the tubes is positioned higher, this has also to be detected by the camera, has someone an idea how to detect this?

Thank you!

Werz gravatar imageWerz ( 2018-02-08 07:13:18 -0600 )edit


the reduce function works very goog for this, but now Im looking for a possibility to draw a graph out of this vector i created with the reduce function, how have you done this with opencv?

Werz gravatar imageWerz ( 2018-02-09 05:03:11 -0600 )edit

are you working in c++ or python or...?

VxW gravatar imageVxW ( 2018-02-09 05:08:31 -0600 )edit

working with c++

Werz gravatar imageWerz ( 2018-02-09 05:10:38 -0600 )edit

I havn't tried it but there are lot of plotting frameworks in c++

looks simple:

is popular:

seems to be professional:

try it out

VxW gravatar imageVxW ( 2018-02-09 05:17:22 -0600 )edit

Thank you for this. I have downloaded the first one, but it seems that i Need python for this. Compiler complains that he does not find "Python.h" when compiling...

Werz gravatar imageWerz ( 2018-02-09 05:49:27 -0600 )edit

Question Tools

1 follower


Asked: 2018-01-18 03:34:30 -0600

Seen: 1,786 times

Last updated: Feb 08 '18