Forum

Author Topic: IMPORT GEOREFERENCED MODEL WITH SHIFT COORDINATES  (Read 3766 times)

jkova96

  • Full Member
  • ***
  • Posts: 168
    • View Profile
IMPORT GEOREFERENCED MODEL WITH SHIFT COORDINATES
« on: September 26, 2024, 09:14:34 PM »
I don't know why sometimes I can't load coordinate system informations for mesh while importing in Agisoft Metashape.
It all stays in gray letters. I'm pissed off cause model/mesh has coordinate info, even it has XYZ file with offsets.
Thanks.
Please login and check for picture which explains what exactly I got.
Here are folders with all items required - model OBJ, mtl file, texture and XYZ file with offset coordinates (open this file in notepad to see what coordinates are):
1.st model - https://drive.google.com/file/d/10GNy1qPBUspAgHDR4KC9b914vvrwMcoN/view?usp=sharing
2.nd model - https://drive.google.com/file/d/1AiX8xK6RAXtiBl_SzuNzBPnPgBx7Sasc/view?usp=sharing
Also, there's picture (below) which shows you data which are included in each mesh folder.

jkova96

  • Full Member
  • ***
  • Posts: 168
    • View Profile
Re: Can't set coordinate system when importing mesh in Agisoft Metashape
« Reply #1 on: September 27, 2024, 08:04:03 AM »
Hi,
I forget to say this but, I think that somehow, but don't know how instead of files which you can download. In fact, I've changed names from mtl file name and texture file name.

Maybe, this would help if someone knows (or if someone interested):
1.st original file: https://drive.google.com/file/d/1X7bWw3H7-aLU3Yj3OFGEZuzkiapW2faR/view?usp=drivesdk
2.nd original file: https://drive.google.com/file/d/1XDhSyXFmkV_ffFrKuzfaBKFPXvw9dVj0/view?usp=drivesdk

Thank you for eventual help!

Best regards!

J.K.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15177
    • View Profile
Re: Can't set coordinate system when importing mesh in Agisoft Metashape
« Reply #2 on: September 27, 2024, 02:16:43 PM »
Hello J.K.,

That is an expected behavior for the case, when the mesh model is imported to the empty chunk.

Below you can find the script that allows to import georeferenced mesh model (in projected coordinate system) to the empty chunk. So you just need to run the script (it will add a custom menu item), then point to it the path to OBJ or DXF model and select the coordinate system. Then the script will automatically assign the coordinate system to the chunk and properly import the model to it.

Code: [Select]
import Metashape
#-791116.062500 X  -1149216.000000 Y  543.011 m

def import_mesh_obj_dxf():

doc = Metashape.app.document
chunk = doc.chunk

path = Metashape.app.getOpenFileName("Select mesh file for import:", filter = "DXF files (*.dxf);; OBJ files (*.obj)")
if not path:
print("Nothing to import, script aborted.")
return 0

crs = Metashape.app.getCoordinateSystem("Specify CRS for imported mesh:", Metashape.CoordinateSystem("EPSG::5514"))
if not crs:
print("Invalid CRS, script aborted.")
return 0

if path.upper().endswith("DXF"):
file = open(path, "rt")
lines = file.readlines()
readX=False
readY=False
readZ=False
x = 0
y = 0
z = 0
readN = 0
count = 0
for line in lines:
if line.strip() == "10":
readX = True
continue
elif line.strip() == "20":
readY = True
continue
elif line.strip() == "30":
readZ = True
continue

if readX and not x:
x = float(line.strip())
readN += 1
continue
elif readY and not y:
y = float(line.strip())
readN += 1
continue
elif readZ and not z:
z = float(line.strip())
readN += 1
continue

if readN >= 3:
break
file.close()

if readN < 3:
print("Not enough data, cannot import")
return 0

chunk.crs = crs
chunk.transform.matrix = Metashape.Matrix.Translation(crs.unproject((x, y, z)))
chunk.importModel(path, Metashape.ModelFormatDXF, crs)

elif path.upper().endswith("OBJ"):

file = open(path, "rt")
lines = file.readlines()
for line in lines:
if line[0] != "v":
continue
params = line.strip().split(" ")
break

x = float(params[1])
y = float(params[2])
z = float(params[3])
file.close()

chunk.crs = crs
chunk.transform.matrix = Metashape.Matrix.Translation(crs.unproject((x, y, z)))
chunk.importModel(path, Metashape.ModelFormatOBJ, crs)

else:
print("Unsupported mesh format")
return 0
chunk.resetRegion()
print("Script finished")
#doc.save()
return 1

label = "Custom menu/Import mesh from OBJ or DXF"
Metashape.app.addMenuItem(label, import_mesh_obj_dxf)
print("To execute this script press {}".format(label))

But note that this version of the script doesn't support offsets (shift) input, if you need that, let me know.
« Last Edit: September 27, 2024, 02:21:47 PM by Alexey Pasumansky »
Best regards,
Alexey Pasumansky,
Agisoft LLC

jkova96

  • Full Member
  • ***
  • Posts: 168
    • View Profile
Re: Can't set coordinate system when importing mesh in Agisoft Metashape
« Reply #3 on: September 27, 2024, 06:41:32 PM »
Hi Alexey,
Thanks for script, but
offsets are crucial in this case.
Could you please adjust your script for offsets?

Best regards!

Josip K.

jkova96

  • Full Member
  • ***
  • Posts: 168
    • View Profile
Re: Can't set coordinate system when importing mesh in Agisoft Metashape
« Reply #4 on: September 28, 2024, 06:19:22 PM »
Hi again Alexey,

Actual reason why I need to include offset informations is to adjust model (mesh) with photos that I took. Look at the picture below in attachment. This model is exported from, let's say PIX4D Catch app, and from their site they explained what these XYZ file means - https://community.pix4d.com/t/how-do-we-obtain-origin-0-0-0-for-a-3d-model/29160

So, if you can make changes to your script that offers me to enter shift coordinates that would be really useful to me.

Thanks!

Have a nice day:)

J.K.

olihar

  • Sr. Member
  • ****
  • Posts: 258
    • View Profile
Re: Can't set coordinate system when importing mesh in Agisoft Metashape
« Reply #5 on: September 28, 2024, 10:56:09 PM »

Expot and import using the same coordinate space/system.

jkova96

  • Full Member
  • ***
  • Posts: 168
    • View Profile
Re: Can't set coordinate system when importing mesh in Agisoft Metashape
« Reply #6 on: September 28, 2024, 11:54:35 PM »
Hi Olihar and Alexey,

Yeah, I've tried, but nothing. I just can't set shift parameters in ordinary way.
Since, program from which I exported model is Pix4D Catch, I used everything that I've learned so far and I came to one conclusion.

I actually, find way to make it work...maybe better said that I just remind myself how to do again that.

Here's detailed steps what I done:

1.st) I load point cloud, densified point cloud from Pix4D Catch app as las file extension. Local coordinate system is set before loading las file.
2.nd) I load images into Agisoft Metashape (Workflow --> Add images)
3.rd) Then i load OBJ model and apply coordinate system [ WGS 84/ UTM zone 33N (EPSG: 32633) ]..
and voila... Finally I got what I wanted to get much before. Anyone look down pictures below.

Of course, there's one video which I recorded to show you what exactly I done: https://youtu.be/6dxAZ0z7Jkw

Don't know, but I supposed that I will, initially I thought so, like you said olihar - get much better chance when I match coordinate system with coordinate system of mesh/model... Unfortunately for some reason I don't know why that does not happen.

I would like that someone makes script, as Alexey says, which uses shift parameters into account to match everything perfectly.

jkova96

  • Full Member
  • ***
  • Posts: 168
    • View Profile
Re: Can't set coordinate system when importing mesh in Agisoft Metashape
« Reply #7 on: September 28, 2024, 11:56:21 PM »
BTW...I was unable to put final result cause only 4 images you can attach, plus here's video once again.

video what I done: https://youtu.be/6dxAZ0z7Jkw

Final result in attachment, picture.


BenW22

  • Jr. Member
  • **
  • Posts: 72
    • View Profile
Re: Can't set coordinate system when importing mesh in Agisoft Metashape
« Reply #8 on: September 29, 2024, 06:45:11 AM »
Hi Jkova96

I had a problem importing a mesh into Metashape. The mesh was in the format of 3d triangles (AutoCAD 3d faces). The triangle vertices coords were large values in X Y Z

What Alexi found was metashape was rounding the decimal places off the triangle vertices' coordinates when it was imported. This was because of their length of the coordinate values. Metashape has a maximum coordinate value length for each X,Y and Z when using Local Coordinates. So the mesh in Metashape was wrong  - different to the mesh i was trying to import!

Once the shifts were applied when importing the mesh, the vertice coordinates value length were shorter and Metashape could then recreate my mesh vertices correctly (only shifted X and Y)

I know this is not your issue but the information below many help importing your mesh -

Alexi found the rounding issue and created this console input for me-  Note the X and Y shifts are for my job. You would change these to your job, if a shift is needed.

- execute the following line in the Console pane: Metashape.app.document.chunk.transform.matrix=Metashape.app.document.chunk.transform.matrix
- use File Menu -> Import -> Import Model command, select Local Coordinates system option and input the following shift offsets: X = 365000, Y = 6326000, Z = 0

Hopefully this may stop your coords being greyed out.

These are the full instructions Alexi sent me and they worked for me -

Meanwhile you can also try another workaround. Using "local coordinates" system directly is not possible due to the rounding issue that will appear for the large coordinate values, but it should be possible to use Shift offests on import and export:
- create new chunk in Metashape project and make it active,
- execute the following line in the Console pane: Metashape.app.document.chunk.transform.matrix=Metashape.app.document.chunk.transform.matrix
- use File Menu -> Import -> Import Model command, select Local Coordinates system option and input the following shift offsets: X = -365000, Y = -6326000, Z = 0
- then export model using Local Coordinates option again and same shift offsets (X = 365000, Y = 6326000, Z = 0 ). You can use precision=6 that is similar to the input file.
Hopefully it should work according to your expectation: model will be loaded to Metashape in Cartesian coordinate system shifted by XYZ vector and on export the same vector will be added to all the vertices.
Let me know, if this approach works, while I am checking, why you are not getting the same results using geographic/projected coordinate system.



Kind Regards
Ben









jkova96

  • Full Member
  • ***
  • Posts: 168
    • View Profile
IMPORT GEOREFERENCED MODEL WITH SHIFT COORDINATES
« Reply #9 on: October 04, 2024, 02:02:51 PM »
Hi to everyone, I just want to have script which includes shift when importing georeferenced model to Agisoft. In mine particular case, model was generated from Pix4D Catch app and I want them to be properly imported to Agisoft. Can you provide me script which includes offsets (shift) input, something similar I asked you before, but back then it was without shift included, in this topic - https://www.agisoft.com/forum/index.php?topic=16738.0 To remind you, somone said, and that's why I used word 'remainder' in tittle of this support ticked, that one of your co-workers said these words: "But note that this version of the script doesn't support offsets (shift) input, if you need that, let me know." Thanks and have a nice day! J.K.

jkova96

  • Full Member
  • ***
  • Posts: 168
    • View Profile
Re: Can't set coordinate system when importing mesh in Agisoft Metashape
« Reply #10 on: October 04, 2024, 09:08:41 PM »
Hi Alexey,

But note that this version of the script doesn't support offsets (shift) input, if you need that, let me know.

I'm "letting" you know. Cause I need this with shift offsets. Practicaly script is unusable in my situation.
Best regards!

J.K.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15177
    • View Profile
Re: Can't set coordinate system when importing mesh in Agisoft Metashape
« Reply #11 on: October 07, 2024, 03:06:29 PM »
Hello J.K.,

I have updated the script so that it could use offsets for import.

Please check, if it works properly on your data. If not, then provide some sample data for testing.
Best regards,
Alexey Pasumansky,
Agisoft LLC

jkova96

  • Full Member
  • ***
  • Posts: 168
    • View Profile
Re: Can't set coordinate system when importing mesh in Agisoft Metashape
« Reply #12 on: October 07, 2024, 03:48:50 PM »
Hi Alexey,

Thanks for script!
I'll try to test script later, when come back to office.

Have a nice day!

J.K.