最近做一个图斑识别的项目,要从mask转到shp文件,花了几周时间整理了以下代码,从shape转json的coco数据集代码以后再整理。
代码
# -*- coding: utf-8 -*-
"""
Created on Mon Jan 20 16:15:37 2020
@author: hgh
"""
import geopandas as gp
from shapely.geometry import Polygon
import numpy as np
from math import sqrt, pow
from Douglas_Peuker import DouglasPeuker
points = np.load(r'E:\Project\npy\Blocks.npy')
global edge
'''
判断边
'''
def is_edge(temp, point):
locat = [[0, -1], [1, 0], [0, 1], [-1, 0]]
count = 0
for xy in locat:
check_point = [point[0] + xy[0], point[1] + xy[1]]
is_ourer = np.where((temp[:,0]==check_point[0]) & (temp[:,1]==check_point[1]))[0]
count += len(is_ourer)