[英]How can I find out which color is there on an image of map based on the coordinates of the location?
I have this image of the map of India and I want to find out what is the color on the map if I search for a coordinate. 我有印度地图的这张图片,如果我搜索一个坐标,我想知道地图上的颜色是什么。
This is for a project I am trying to implement using Python. 这是我尝试使用Python实现的项目。
For example, in this image if I search for 28.7041° N, 77.1025° E which is the coordinates for Delhi, India, I want to get that the color at that coordinates is orange. 例如,在此图像中,如果我搜索28.7041°N,77.1025°E这是印度德里的坐标,我想得到该坐标处的颜色为橙色。 Link to image : https://drive.google.com/open?id=1GDj_HCnAy_CgL9IQ0d2p8Q8Dd4i-eydK 链接到图片: https : //drive.google.com/open?id = 1GDj_HCnAy_CgL9IQ0d2p8Q8Dd4i-eydK
This is a bit vague question but I'll try to guide you showing you example code. 这是一个有点模糊的问题,但我会尝试指导您向您展示示例代码。 This is bogus code to help you find the right library and execution path, ultimately you will have to roll your own 这是一个虚假的代码,可以帮助您找到正确的库和执行路径,最终您将不得不自己动手
1 - Request for the coordinates in the web service you want to download image from. 1 - 请求您要从中下载图像的Web服务中的坐标。 This will probably be easier using a web library such as requests
or any other scraping library. 使用Web库(如requests
或任何其他抓取库)可能会更容易。
import requests
resp = requests.get('https://my-web-service', params={'lat':42.42,'lng':77.1025})
2 - Locate the image url in the response, make another request to download the image. 2 - 在响应中找到图像URL,发出另一个下载图像的请求。 You may need to parse the response using re
or using other forms of web parsing (such as beautifulsoup
) 您可能需要使用re
或使用其他形式的Web解析来解析响应(例如beautifulsoup
)
image_url = re.match('https://[a-z].png', resp.text).group(0)
image_resp = requests.get(image_url)
3 - Feed the content of the image to an image library such as pyopencv
3 - 将图像的内容输入图像库,例如pyopencv
import cv2
img_array = cv2.imdecode(image_resp.content)
4 - Check the pixel 4 - 检查像素
print(img_array[40][40])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.