Ask Your Question

how to detect and count pills (capsules)

asked 2014-07-23 02:15:28 -0500

Nehalkumar gravatar image

updated 2014-07-29 01:24:09 -0500

Which algorithm is use full to detect pills and capsules. And after detection count the number of capsules on the table using opencv android.

image description

image description

edit retag flag offensive close merge delete



First of all, before people start suggesting approaches, are these images examples of the cases this is going to be used on? These seem as google grabbed examples, whereas computer vision problems depend A LOT on the actual situation, so providing examples that will need the algorithm to work on, will be much better.

StevenPuttemans gravatar imageStevenPuttemans ( 2014-07-23 03:36:37 -0500 )edit

How to detect capsules from image using opencv android ? Just now i am using generalize Hough transform algorithm to detect capsules

Nehalkumar gravatar imageNehalkumar ( 2014-07-23 04:11:55 -0500 )edit

... answer my question !

StevenPuttemans gravatar imageStevenPuttemans ( 2014-07-23 04:35:12 -0500 )edit

These images are from google. But in my criteria 5 to 10 capsule on table and user start app camera and count the capsules. like i have 10 live capsules on table and count it

Nehalkumar gravatar imageNehalkumar ( 2014-07-23 04:54:10 -0500 )edit

background is white(normal no another item at background) and light is appropriate for detect. it's depend on shape(cylinder shape)

Nehalkumar gravatar imageNehalkumar ( 2014-07-23 05:14:41 -0500 )edit

Then please add pictures that represent your problem. If I describe a solution for these images, which are quite difficult, then it will never work for you ...

StevenPuttemans gravatar imageStevenPuttemans ( 2014-07-23 05:53:19 -0500 )edit

Hello StevenPuttemans i upload images please check and give solution how to detect all pills using opencv android

Nehalkumar gravatar imageNehalkumar ( 2014-07-29 01:25:54 -0500 )edit

I do not provide copy paste solutions. I will think about some guidelines and get back to you.

StevenPuttemans gravatar imageStevenPuttemans ( 2014-07-30 03:42:26 -0500 )edit

ok i am also think on it and you get then update me . Thank you....

Nehalkumar gravatar imageNehalkumar ( 2014-07-30 23:44:21 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2014-07-31 01:53:24 -0500

Since I am not a favorite of providing of the shelf solutions but rather insights on how to tackle this problem, I will try to explain how I would go ahead with this problem.

  1. Perform a grayscaling and histogram equilization of the input image.
  2. Perform a thresholding on the image, based on the background color range to retrieve a binary blob image.
  3. Since the binary image will also contain the lines on the paper (no way of avoiding lines but keeping black pills) I would perform a erosion operator on the image then a dilation to grow the pill regions back.
  4. You will now have blobs that perfectly describe regions of pills.
  5. You are now able to perform a contours finding function, resulting in the amount of pills inside the image.
  6. If preferred you could set a region of interest to the seperate pills and use a classifier to decide which kind of pill you are dealing with.
edit flag offensive delete link more


as per our discussion , i am use findContours then after find area and drawContours but camera distance give different number pills from different distance. how to solve distance problem ? you have any idea regarding this.

Nehalkumar gravatar imageNehalkumar ( 2014-08-02 02:06:27 -0500 )edit
Login/Signup to Answer

Question Tools


Asked: 2014-07-23 02:15:28 -0500

Seen: 1,317 times

Last updated: Jul 31 '14