Using Python, OpenCV and AWS Lambda to gather crime statistics – Part 3

Using Python, OpenCV and AWS Lambda to gather crime statistics – Part 3

This is the third part in my series of scraping data from the local police department, to gather crime statistics over time.

  • Part 1 covers the collection of the images
  • Part 2 covers the finding of the pins on the image
  • Part 3 (This part) will cover determining where the pins are geographically located
  • Part 4 will cover a nice display using Kibana

Part two has identified the pixel locations of all of the pins in the image. We need to then take these locations and translate them into actual coordinates.

The biggest challenge is, the images are always taken by hand and the location differs slightly. For example, see this image from Part 1:

So based on this I can’t assume the origin (0,0) of the image is always the same location on the earth. The next best thing I can do is pick a known location and use this to calibrate my coordinates. I initially started with a single location on the map, however if they decide to change the zoom in the future, two locations will give me both a point and distance calibration, so I’ve opted for two known tiles on the map. The process is the same, search the image for the two known locations and mark the pixel where it is found.

To choose the location, I’ve tried to pick somewhere which is fairly unique in shape, not located too close to an edge, and unlikely to have a pin placed on top of it. For the above map, I’m looking for the following two sections, which I have named “KeyPoints”.



For each KeyPoint, I’ll also need to know the latitude and longitude

With two keypoints, the result is looking promising. Below is the result which finds a pin on (50.949546,6.822494) and a search of google maps in this location shows that it’s exactly on the mark: