I need the center teat point x,y location any suggestion or methodology about how can I achieve this task?

Hello there,

I have applied the object detection algorithm to detect the cow 4 teat. Now I want to find the centre point for a particular detected object as described in the below image in red colour dot.

Any suggestion or approach to do such things using OpenCV?

R_623

Thanks in advance for help!

Hi @ranjit

You asked for suggestions, here is mine, a random one.

You already detected the object of interest, it’s oblong.

The black foreground makes it easy to get a binary image by using threshold, let’s start with Otsu threshold (it’s an automatic threshold level), then get contours of the object.

In this tutorial on contours properties:

https://docs.opencv.org/master/da/dc1/tutorial_js_contour_properties.html

look for “5. Orientation”. With the contour main orientation, loop on every vertex in the contour looking for the extremus in the main direction.

I hope it helps.

1 Like

Thanks for replying to my answer…

With the contour main orientation, loop on every vertex in the contour looking for the extremus in the main direction.

Can you please explain this in details? If you are having any link or code snippet please! share it.

Thanks for the help!

tutorials are here

1 Like

Thanks for the reply! I will have a look on this.

Hi @ranjit

Adrian Rosebrock at PyImageSearch has a fine example on finding extreme points in contours:

Keep in mind this example look for extremes on one edge at the time (x and y). You need to apply more elaborate math to find the extreme in one arbitrary direction.