2023-03-20 21:38:35 +00:00
|
|
|
import os
|
|
|
|
from opendm.ai import get_model
|
|
|
|
from opendm import log
|
|
|
|
from opendm.system import run
|
|
|
|
from opendm import io
|
|
|
|
|
2023-03-21 03:49:23 +00:00
|
|
|
def classify(point_cloud, max_threads=8):
|
2023-03-20 21:38:35 +00:00
|
|
|
tmp_output = io.related_file_path(point_cloud, postfix=".classified")
|
|
|
|
if os.path.isfile(tmp_output):
|
|
|
|
os.remove(tmp_output)
|
|
|
|
|
|
|
|
try:
|
|
|
|
model = get_model("openpointclass",
|
|
|
|
"https://github.com/uav4geo/OpenPointClass/releases/download/v1.1.3/vehicles-vegetation-buildings.zip",
|
|
|
|
"v1.0.0",
|
|
|
|
name="model.bin")
|
|
|
|
|
|
|
|
if model is not None:
|
2023-03-21 03:49:23 +00:00
|
|
|
run('pcclassify "%s" "%s" "%s" -u -s 2,64' % (point_cloud, tmp_output, model), env_vars={'OMP_NUM_THREADS': max_threads})
|
2023-03-21 03:41:10 +00:00
|
|
|
|
|
|
|
if os.path.isfile(tmp_output):
|
|
|
|
os.remove(point_cloud)
|
|
|
|
os.rename(tmp_output, point_cloud)
|
|
|
|
else:
|
|
|
|
log.ODM_WARNING("Cannot classify using OpenPointClass (no output generated)")
|
2023-03-20 21:38:35 +00:00
|
|
|
else:
|
|
|
|
log.ODM_WARNING("Cannot download/access model from %s" % (model_url))
|
2023-03-21 03:41:10 +00:00
|
|
|
|
2023-03-20 21:38:35 +00:00
|
|
|
except Exception as e:
|
|
|
|
log.ODM_WARNING("Cannot classify using OpenPointClass: %s" % str(e))
|
|
|
|
|