forked from coolzhao/Geo-SAM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeo_sam_tool.py
122 lines (101 loc) · 4.54 KB
/
geo_sam_tool.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
from qgis.core import QgsApplication
from qgis.gui import QgisInterface
from PyQt5.QtCore import pyqtSignal, QObject
from PyQt5.QtWidgets import (
QAction,
QToolBar,
)
import processing
from .tools.widgetTool import Selector, EncoderCopilot
from .ui.icons import QIcon_GeoSAMTool, QIcon_EncoderTool, QIcon_EncoderCopilot
from .geo_sam_provider import GeoSamProvider
class Geo_SAM(QObject):
execute_SAM = pyqtSignal()
def __init__(self, iface: QgisInterface, cwd: str):
super().__init__()
self.iface = iface
self.cwd = cwd
self.canvas = iface.mapCanvas()
self.demo_img_name = "beiluhe_google_img_201211_clip"
feature_dir = cwd + "/features/" + self.demo_img_name
self.feature_dir = feature_dir
def initProcessing(self):
self.provider = GeoSamProvider()
QgsApplication.processingRegistry().addProvider(self.provider)
def initGui(self):
self.initProcessing()
self.toolbar: QToolBar = self.iface.addToolBar('Geo SAM Toolbar')
self.toolbar.setObjectName('mGeoSamToolbar')
self.toolbar.setToolTip('Geo SAM Toolbar')
self.actionSamTool = QAction(
QIcon_GeoSAMTool,
"Geo-SAM Segmentation",
self.iface.mainWindow()
)
self.actionSamEncoder = QAction(
QIcon_EncoderTool,
"Geo-SAM Image Encoder",
self.iface.mainWindow()
)
self.actionSamEncoderCopilot = QAction(
QIcon_EncoderCopilot,
"Geo-SAM Encoder Copilot",
self.iface.mainWindow()
)
self.actionSamTool.setObjectName("mActionGeoSamTool")
self.actionSamTool.setToolTip(
"Geo-SAM Segmentation: Use it to label landforms")
self.actionSamTool.triggered.connect(self.create_widget_selector)
self.actionSamEncoder.setObjectName("mActionGeoSamEncoder")
self.actionSamEncoder.setToolTip(
"Geo-SAM Image Encoder: Use it to encode/preprocess image before labeling")
self.actionSamEncoder.triggered.connect(self.encodeImage)
self.actionSamEncoderCopilot.setObjectName(
"mActionGeoSamEncoderCopilot")
self.actionSamEncoderCopilot.setToolTip(
"Encoder Copilot: Assist you in optimizing your Encoder Settings")
self.actionSamEncoderCopilot.triggered.connect(
self.create_widget_encoder_copilot)
self.iface.addPluginToMenu('Geo-SAM Tools', self.actionSamTool)
self.iface.addPluginToMenu('Geo-SAM Tools', self.actionSamEncoder)
self.iface.addPluginToMenu(
'Geo-SAM Tools', self.actionSamEncoderCopilot)
# self.iface.addToolBarIcon(self.action)
self.toolbar.addAction(self.actionSamTool)
self.toolbar.addAction(self.actionSamEncoder)
self.toolbar.addAction(self.actionSamEncoderCopilot)
self.toolbar.setVisible(True)
def create_widget_selector(self):
'''Create widget for selecting landform by prompts'''
if not hasattr(self, "wdg_select"):
self.wdg_select = Selector(self, self.iface, self.cwd)
self.wdg_select.open_widget()
def create_widget_encoder_copilot(self):
'''Create widget for co-piloting encoder settings'''
if not hasattr(self, "wdg_copilot"):
self.wdg_copilot = EncoderCopilot(self, self.iface, self.cwd)
self.wdg_copilot.open_widget()
def unload(self):
'''Unload actions when plugin is closed'''
if hasattr(self, "wdg_select"):
self.wdg_select.unload()
self.wdg_select.setParent(None)
if hasattr(self, "wdg_copilot"):
self.wdg_copilot.unload()
self.wdg_copilot.setParent(None)
# self.wdg_select.setVisible(False)
self.iface.removeToolBarIcon(self.actionSamTool)
self.iface.removeToolBarIcon(self.actionSamEncoder)
self.iface.removeToolBarIcon(self.actionSamEncoderCopilot)
self.iface.removePluginMenu('&Geo-SAM Tools', self.actionSamTool)
self.iface.removePluginMenu('&Geo-SAM Tools', self.actionSamEncoder)
self.iface.removePluginMenu(
'&Geo-SAM Tools', self.actionSamEncoderCopilot)
del self.actionSamTool
del self.actionSamEncoder
del self.actionSamEncoderCopilot
del self.toolbar
QgsApplication.processingRegistry().removeProvider(self.provider)
def encodeImage(self):
'''Convert layer containing a point x & y coordinate to a new point layer'''
processing.execAlgorithmDialog('geo_sam:geo_sam_encoder', {})