基于像素颜色的坐标位置 [英] coordinate location based off pixel color

查看:104
本文介绍了基于像素颜色的坐标位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取图像中的特定坐标.我在图像中的多个位置标记了一个红点,以指定要获取的坐标.在GIMP中,我使用了我能找到的纯正红色(HTML表示法 ff000 ).我的想法是,我将遍历图像,直到找到纯红色的阴影,然后打印出坐标.我正在使用python和opencv这样做,但是我找不到任何好的教程(我能找到的最好的教程是 我只想知道如何找到带有红点的像素的坐标.

I am trying to get specific coordinates in an image. I have marked a red dot in the image at several locations to specify the coordinates I want to get. In GIMP I used the purist red I could find (HTML notation ff000). The idea was that I would iterate through the image until I found a pure shade of red and then print out the coordinates. I am using python and opencv to do so but I can't find any good tutorials (best I could find is I just want to know how to find the coordinates of the pixels with the red dots.

编辑(添加代码):

import cv2
import numpy as np

img = cv2.imread('image.jpg')
width, height = img.shape[:2]
for i in range(0,width):
   for j in range(0,height):
      px = img[i,j]

我不知道从这里做什么.我已经尝试过诸如if px == [x,y,z]之类的代码来寻找颜色检测,但这是行不通的.

I don't know what to do from here. I have tried code such as if px == [x,y,z] looking for color detection but that doesn't work.

推荐答案

您可以通过cv2来做到这一点:

You can do it with cv2 this way:

image = cv2.imread('image.jpg')
lower_red = np.array([0,0,220])  # BGR-code of your lowest red
upper_red = np.array([10,10,255])   # BGR-code of your highest red 
mask = cv2.inRange(image, lower_red, upper_red)  
#get all non zero values
coord=cv2.findNonZero(mask)

这篇关于基于像素颜色的坐标位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆