'Extract multiple polygons from image
Hi I am trying to extract some polygons from the image below and the final goal is to create a shapefile with the polygons.
So far i have managed to separate polygons for each different colour. Following shows extracting black colour edges and creating a binary file.
import cv2 as cv
import numpy as np
from matplotlib import pyplot as plt
img_path = 'map_test.png'
img = cv.imread(img_path,0)
img = cv.medianBlur(img,5)
ret,th1 = cv.threshold(img,120,255,cv.THRESH_BINARY)
th1_trans = th1+1
image = cv.imread(img_path)
gray = cv.cvtColor(image, cv.COLOR_BGR2GRAY)
gray = gray+1
th1_trans_gray = th1_trans*gray
cl = 1
img_sub = th1_trans_gray==cl
sub_plan = img_sub*cl
img = sub_plan.astype(np.uint8)
plt.imshow(sub_plan)
These lines are not single lines (width more than 1 pixel) also not continuous (dashed line). So I tried Canny and findContours but both bring the edges around the dashes.
I am new to opencv so I am not even sure if this is the correct path to take in tackling this problem. Can you please help me to understand the best approach to identify the coordinates of the multiple polygons in the image?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|


