当前位置:网站首页>从mask-rcnn到shp
从mask-rcnn到shp
2022-08-11 05:33:00 【我是无名的我】
最近做一个图斑识别的项目,要从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)
return count
''' 得到边后,对边逆时针排序 '''
def rank(point):
# global edge
check = [[0, -1], [1, -1], [1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1]]
for x, y in check:
check_x = point[0] + x
check_y = point[1] + y
check_point = [check_x, check_y]
if check_point in edge:
return check_point
return False
def create_shp(points):
global edge
# global edge_list
# global d
geometry = list()
# for i in range(points.shape[0]):
for i in range(1):
temp = np.argwhere(points[i]==True)
temp = np.c_[np.argwhere(points[i]==True), np.zeros(len(np.argwhere(points[i]==True)))]
count = 0
for point in temp:
if is_edge(temp, point) != 4:
temp[count, 2] = 1
count +=1
t = temp[temp[:, 2]==1]
edge = [[x, y] for x, y, z in t]
h = len(edge)
edge.sort()
edge_list = [edge[0],]
next_point = edge[0]
edge.remove(edge[0])
try:
for j in range(h):
next_point = rank(next_point)
if next_point in edge:
edge_list.append(next_point)
net_point = net_point
edge.remove(net_point)
if False in edge_list:
edge_list.remove(False)
d = DouglasPeuker()
d.main(edge_list)
edge_list = [point for point in d.qualify_list]
edge_list = Polygon(edge_list)
geometry.append(edge_list)
print('完成第%s个' % str(i+1))
except:
print('错误')
gdf = gp.GeoDataFrame(geometry=geometry)
return gdf
gdf = create_shp(points)
问题解释
- 创建shp文件用到了geopandas,安装这库的时候最好新建一个新的环境,要不然各种问题(反正我的是).
- 我把mask-rcnn得到的点存在了Blocks.npy里面。
- 一个点,判断是否为边界,主要是判断它的上下左右是否都在mask里面,这个函数是运算时间最大的。
- 对边界的排序,对点 ( x , y ) (x, y) (x,y)(最低点),依次判断 ( a + x , b + y ) (a+x, b+y) (a+x,b+y)for x, y in ([[0, -1], [1, -1], [1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1]] ),若 ( a + 0 , b − 1 ) (a+0,b-1) (a+0,b−1)在边界上面,将 ( a + 0 , b − 1 ) (a+0,b-1) (a+0,b−1)标记为 ( a , b ) (a,b) (a,b)的next_point,将判断位置转移到 ( a + 0 , b − 1 ) (a+0,b-1) (a+0,b−1)。
- 通过三的步骤,mask显然是有很多点的,这时候我们要对排序后的点进行抽稀,用到道格拉斯抽稀算法这里的代码。
思考
按道理说,直接使用步骤3的算法,能在不取出边界的条件下生成有顺序的边界,但是可能是我技术的问题(我菜),老是有问题,以后有空再研究这个。
边栏推荐
- visio文件批量转pdf
- FusionCompute8.0.0实验(0)CNA及VRM安装(2280v2)
- 无胁科技-TVD每日漏洞情报-2022-7-18
- HPC platform building
- AUTOMATION DAY06 (Ansible Advanced, Ansible Role)
- 无胁科技-TVD每日漏洞情报-2022-7-26
- MySQL中忘记用户密码怎么办?
- Django QuerySet.order_by() SQL注入漏洞复现
- 2022年全国职业技能大赛网络安全竞赛试题B模块自己解析思路(4)
- Threatless Technology-TVD Daily Vulnerability Intelligence-2022-7-31
猜你喜欢

Raspberry Pi set static IP address

项目笔记——随机2

Local yum source build

buildroot嵌入式文件系统中vi显示行号

cloudreve使用体验

CLUSTER DAY03 (Ceph overview, the deployment of Ceph CLUSTER, Ceph block storage)

照片的35x45,300dpi怎么弄

ETCD cluster fault emergency recovery - to recover from the snapshot

lvm 多盘挂载,合并使用

(3) Software testing theory (understanding the knowledge of software defects)
随机推荐
buildroot setup dhcp
window10吐槽
Apache Fink 文件上传漏洞复现及利用
项目笔记——随记
胖鸟博客之勒索病毒紧急处理文件恢复及防范方案
Apache Flink jobmanager/logs 目录穿越漏洞复现
SSL证书部署后,为什么还是显示不安全?
mysql数据库安装教程(超级超级详细)
vnc远程桌面安装(2021-10-20日亲测可用)
(二)软件测试理论(*重点用例方法编写)
本地yum源搭建
China Mobile Communications Group Co., Ltd.: Business Power of Attorney
AUTOMATION DAY07 (Ansible Vault, ordinary users use ansible)
Raspberry Pi set static IP address
HPC平台搭建
Vulnhub靶机--Chronos
No threat of science and technology - TVD vulnerability information daily - 2022-7-21
Deep Learning Matlab Toolbox Code Comments
Threatless Technology-TVD Daily Vulnerability Intelligence-2022-7-18
HPC platform building