I have processed a screenshot from google maps using OpenCV and identified some contours for the red road sections, and I want to project these contours to a shapefile. I have searched but couldn't find an answer that followed the same purpose. Here is the screenshot and the contours I found:
I also have the X, Y coordinates of each contour in pixels like the following:
[array([[[271, 485]],
[[271, 488]],
[[272, 489]],
[[272, 491]],
[[273, 492]],
[[274, 492]],
[[273, 492]],
[[272, 491]],
[[272, 489]],
[[271, 488]]], dtype=int32)]
I have been trying to find a way to convert my X, Y coordinates to spatial longitude and latitude and then draw the contour with another library like fiona. I have seen map projections using pyproj geopandas gdal but couldn't apply any of them to my case. Can you point me in the right direction?
Thanks a lot.
Try the below code and see if it helps:
This code uses the cv2.findContours() method to extract the contours from the image. It then creates a new shapefile using the shapefile module and adds the contours as lines to the shapefile. Finally, it saves the shapefile.