修改港口切片
parent
0f44939718
commit
7882cdfe62
|
|
@ -322,6 +322,7 @@ def check_B_in_A(A,B):
|
|||
# 计算矩形A和B的右边界和下边界
|
||||
Ax1 = Ax0 + Aw
|
||||
Ay1 = Ay0 + Ah
|
||||
|
||||
Bx1 = Bx0 + Bw
|
||||
By1 = By0 + Bh
|
||||
|
||||
|
|
@ -368,8 +369,11 @@ def getclusterDict(dotalist,imgheight,imgwidth,pitchSize=1024,max_overlap_rate=0
|
|||
[centerX, centerY, minX, minY, maxX, maxY]=getExternCenter(dotalist, [ids])
|
||||
dotaExtend=[minX,minY,maxX-minX,maxY-minY]
|
||||
if check_B_in_A(slicesExten,dotaExtend):
|
||||
print("True: ", slicesExten, dotaExtend)
|
||||
clusterDict[i]["id"].append(ids)
|
||||
hasContainIds.append(ids)
|
||||
# hasContainIds.append(ids)
|
||||
else:
|
||||
print("False: ",slicesExten,dotaExtend)
|
||||
|
||||
for ids in range(len(dotalist)):
|
||||
if ids in hasContainIds:
|
||||
|
|
@ -390,7 +394,7 @@ def drawSlictplot(clusterDict,dotalist,tiff_data,nrows=10,ncols=9):
|
|||
"""
|
||||
fig, axes = plt.subplots(nrows=nrows,ncols=ncols,figsize=(20, 16))
|
||||
plt.tight_layout(pad=3.0)
|
||||
|
||||
print(tiff_data.shape)
|
||||
# 9*10
|
||||
subid=0
|
||||
for cid in clusterDict:
|
||||
|
|
@ -398,7 +402,7 @@ def drawSlictplot(clusterDict,dotalist,tiff_data,nrows=10,ncols=9):
|
|||
colid=subid//nrows
|
||||
rowid=subid%nrows
|
||||
subid=subid+1
|
||||
ax = axes[rowid, colid]
|
||||
ax = axes[rowid]
|
||||
ax.set_title(str(cid))
|
||||
sliceData=tiff_data[sy:(sy+SliceSize),sx:(sx+SliceSize)]
|
||||
ax.imshow(sliceData, cmap='gray')
|
||||
|
|
@ -487,8 +491,8 @@ def DataSampleSliceRasterProcess(inbinfile,labelfilepath,outfolderpath,methodstr
|
|||
imgheight, imgwidth=tiff_data.shape
|
||||
clusterDict=getclusterDict(dotalist,imgheight,imgwidth,SliceSize,0.25)
|
||||
# drawSliceRasterPrivew(tiff_data, dotalist, clusterDict)
|
||||
ncols=int(len(clusterDict)/9+1)
|
||||
# drawSlictplot(clusterDict, dotalist, tiff_data, 9, ncols)
|
||||
nrows=int(len(clusterDict)/1+1)
|
||||
# drawSlictplot(clusterDict, dotalist, tiff_data, nrows, 1)
|
||||
tiff_name=os.path.basename(inbinfile)
|
||||
tiff_basename=os.path.splitext(tiff_name)[0]
|
||||
slictDataAndOutlabel(clusterDict, dotalist, tiff_data, tiff_basename, outfolderpath, tiff_trans, tiff_proj)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,60 @@
|
|||
import os
|
||||
import argparse
|
||||
from osgeo import ogr,gdal
|
||||
from matplotlib import pyplot as plt
|
||||
from osgeo import gdal
|
||||
import matplotlib
|
||||
import matplotlib.patches as patches
|
||||
from osgeo import gdal
|
||||
from PIL import Image
|
||||
from scipy.spatial import cKDTree
|
||||
import numpy as np
|
||||
from tools.DotaOperator import DotaObj,createDota,readDotaFile,writerDotaFile
|
||||
import argparse
|
||||
import math
|
||||
from math import ceil, floor
|
||||
|
||||
pngpath=r"D:\港口\切片结果\Geo_bc2-sm-org-vv-20231016t135315-008424-0020e8-01_3.png"
|
||||
txtpath=r"D:\港口\切片结果\Geo_bc2-sm-org-vv-20231016t135315-008424-0020e8-01_3.txt"
|
||||
|
||||
|
||||
|
||||
pngdata=np.array(Image.open(pngpath))
|
||||
dotalist=readDotaFile(txtpath)
|
||||
|
||||
plt.figure()
|
||||
plt.imshow(pngdata)
|
||||
# 绘制每个目标的矩形框并标注坐标
|
||||
for i in range(len(dotalist)):
|
||||
# 提取x和y坐标
|
||||
x_coords = [dotalist[i].x1, dotalist[i].x2, dotalist[i].x3, dotalist[i].x4]
|
||||
y_coords = [dotalist[i].y1, dotalist[i].y2, dotalist[i].y3, dotalist[i].y4]
|
||||
|
||||
# 计算最小外接矩形(AABB)
|
||||
x_min, x_max = min(x_coords), max(x_coords)
|
||||
y_min, y_max = min(y_coords), max(y_coords)
|
||||
width = x_max - x_min
|
||||
height = y_max - y_min
|
||||
|
||||
# 绘制无填充矩形框(仅红色边框)
|
||||
rect = patches.Rectangle(
|
||||
(x_min, y_min), width, height,
|
||||
linewidth=2, edgecolor='red', facecolor='none' # 关键:facecolor='none'
|
||||
)
|
||||
plt.gca().add_patch(rect)
|
||||
|
||||
# ax.annotate(f'({x},{y})', xy=(x, y), xytext=(5, 5),
|
||||
# textcoords='offset points', fontsize=10,
|
||||
# bbox=dict(boxstyle='round,pad=0.5', fc='white', alpha=0.8))
|
||||
|
||||
# 在矩形中心标注目标编号
|
||||
center_x = sum(x_coords) / 4
|
||||
center_y = sum(y_coords) / 4
|
||||
plt.text(center_x, center_y, str(i),
|
||||
ha='center', va='center', fontsize=6, color='red')
|
||||
|
||||
|
||||
plt.show()
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue