python - 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:
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.
解决方案
I guess it is a microscope output.
First you have to detect (locate) objects in the image :
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.
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 :
- 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.
推荐阅读
- automation - 在 Ansible 剧本中,有什么更好的方法来迭代对象列表并根据该对象的数据调用不同的角色?
- kubernetes - 当应用程序在端口 80 上时,Kubernetes 负载均衡器重定向到 HTTPs
- powershell - 协助将列数据从 Import-CSV 拆分为多列
- xpath - 如何使用 xpath 获取包含单词的第一个标签?
- arrays - 字母矩阵中最长的连续路径
- html - 导航栏上方的 div 看起来不像预期的那样
- mysql - 需要加快 WHERE NOT EXISTS 查询
- javascript - D3.csv 读入 promise
- jquery - 如果元素的子元素为空,则将类添加到该元素的另一个子元素
- azure-functions - Cosmos DB changefeed 突然没有触发 Azure Function 触发器