简体   繁体   中英

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.

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. Link to image : 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. This will probably be easier using a web library such as requests or any other scraping library.

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. You may need to parse the response using re or using other forms of web parsing (such as 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

import cv2

img_array = cv2.imdecode(image_resp.content)

4 - Check the pixel

print(img_array[40][40])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM