如何使用python获取此图像的某些颜色(RGB)的像素坐标?
我正在尝试进行室内导航,并且我需要机器人可以自动导航的室内地图.我正在考虑使用每个位置(某些部分)具有不同颜色的图像,并且我想知道获取某些颜色的坐标的方法.这样我就可以使用该坐标将位置指定到某些颜色区域.我目前正在使用pycharm
I'm trying to make an indoor navigation and I need indoor map that robot can automatically navigate the way. I'm thinking of using image which have different colors for each place(certain section), and I want to know the way to get the coordinates of the certain colors. So that I can designate places to certain color area using that coordinates. I am currently using pycharm
如何获取粉红色,紫色和黄色每个部分的坐标? 颜色的RGB代码为粉红色(255,128,255),黄色(255,255,0),紫色(128,128,255).
How can I get the coordinates of each of the pink,purple, and yellow part? RGB code of the colors are pink(255,128,255), yellow(255,255,0), purple(128,128, 255).
您的问题的解决方案将包括两个主要部分:
The solution to your problem will involve two main parts:
- 从输入图像中检测颜色
- 将blob转换为单个坐标.
让我们来解决第一个问题.您可以将cv2.inRange()
用于各种颜色,以获取输入图像中每个标记正方形的二进制掩码.
Let's take the first problem. You can use cv2.inRange()
with various colors, to get a binary mask for each of your marked squares in the input image.
现在,您可以在二进制蒙版上使用cv2.findContours
来检测最大轮廓,并获取其中点或其他内容.
Now you can use cv2.findContours
on the binary mask(s) to detect the largest contour and the take it's mid-point or something.