首页 > 解决方案 > How To Detect A Specific Mark On A Image Using OpenCv Python

问题描述

I am trying to detect a mark on a object and determine if it is left from the centre or the right. Following marked with green arrow is what i am trying to detect :

Image:

enter image description here

I have read the opencv documentation but cant find a way to do something similar. The basic step for now is to just detect the specific detail of the image and has to work every single time then i am looking forward to determining if it is on right or left.

How can i do this

Edit : I have tried shawn's method to see if it work and has the answer the only problem is that with my experimenting i cant seem to get a perfect a value as shown in the shawn's answer.

标签: pythonopencvopencv-python

解决方案


I guess it is a microscope output.

First you have to detect (locate) objects in the image :

  1. My default solution would be object detection with machine learning models. This is the way if you have lots of labeled data (e.g annotated image). For example, you can train a YOLOv3 tiny model for this problem. Without diving into too much code, you can find the tutorial for detecting something different, and apply it to your problem. For example, you can follow this tutorial, then you will ask more specific questions.

  2. If you are familiar with object detection with machine learning and frameworks like PyTorch and TensorFlow, you can find lighter models than YOLOv3 tiny from the GitHub, and you can re-train them.

You can achieve insane accuracies using machine learning, however, there are other methods :

  1. Other solutions rather than machine learning may be object detection using contour plots or object detection using HSV color space. You can find other Image Processing methods without machine learning on YouTube or other tutorial platforms.

Maybe you can follow these tutorials and then ask more specific code-related questions like "Why is the blurring is not working on my contour plot code?".

Second, after you are able to detect objects, you should extract the bounding box coordinates center, and compare it with the image center coordinates.

If the X coordinate of the detected object bounding box center is greater than the (width of the image)/2, then the object is on the right of the image. If it is smaller, then the detected object is on the left side of the image.

Hope this answers your question.


推荐阅读