Agisoft Metashape

Agisoft Metashape => Python and Java API => Topic started by: adams on September 19, 2016, 02:40:12 PM

Title: Import OPK from ASCII file and convert them to YPR
Post by: adams on September 19, 2016, 02:40:12 PM
Hello,

Is it possible to import OPK from ASCII file, and then convert them to Yaw,Pitch, Roll   using script below:

Code: [Select]
#to convert opk into ypr
yaw, pitch, roll = PhotoScan.utils.mat2ypr(PhotoScan.utils.opk2mat(PhotoScan.Vector((omega, phi, kappa))).t())

I have no idea how to import OPK from ASCII file (ID, X, Y, Z, omega, phi kappa) without numpy...

I count on your support


Title: Re: Import OPK from ASCII file and convert them to YPR
Post by: Alexey Pasumansky on September 19, 2016, 05:46:27 PM
Hello adams,

You can use the following function Python function from the Console pane to load the reference data using OPK data:
PhotoScan.app.document.chunk.importCameras(path = "d:/file.txt", format = "opk")
Title: Re: Import OPK from ASCII file and convert them to YPR
Post by: Juilson on October 17, 2016, 04:20:59 PM
Hi!

I'm trying to "reread" an OPK file generated from Photoscan in order to refine my matches.
I have though no clue how to call the function mentioned above. Could you please give us some more detail on it?

Best regads
Juilson
Title: Re: Import OPK from ASCII file and convert them to YPR
Post by: Alexey Pasumansky on October 17, 2016, 05:57:17 PM
Hello Juilson,

At the moment, .importCameras() Python API function assumes that each line contains the following information in the same order:
Code: [Select]
camera_label x-coord y-coord z-coord omega phi kappaPhotoScan cameras export in OPK format also generates rotation matrix elements that need to be removed.
Title: Re: Import OPK from ASCII file and convert them to YPR
Post by: PK_2509 on November 02, 2016, 08:49:21 PM
Hello Alexey,

I have an additional question.

My ASCII file has the format you provided. When I import the file from the Console pane, I don´t get an error.
I have tested to import a xml file and it works perfect.

Also I don´t found the format "opk" for importCameras in the Python API.

What am I doing wrong?
Title: Re: Import OPK from ASCII file and convert them to YPR
Post by: Alexey Pasumansky on November 04, 2016, 06:18:41 PM
Hello PK_2509,

Do the camera labels in the active chunk correspond to the camera names in opk text file? Please check that in the project the extension is the same in the camera labels (*.tiff).
Title: Re: Import OPK from ASCII file and convert them to YPR
Post by: PK_2509 on November 04, 2016, 08:07:07 PM
Hello Alexey,

yes the camera labels in the active chunk correspond to the camera names in opk text file.
Title: Re: Import OPK from ASCII file and convert them to YPR
Post by: Alexey Pasumansky on November 05, 2016, 07:50:44 PM
Hello PK_2509,

You need to use "space" delimiter, as it seems that you have "tab" in your input file.
Title: Re: Import OPK from ASCII file and convert them to YPR
Post by: PK_2509 on November 07, 2016, 06:46:23 PM
Hello Alexey,

thank you for your advise. Everthing works perfect now.

Best regards
Title: Re: Import OPK from ASCII file and convert them to YPR
Post by: lfreguete on June 24, 2021, 11:06:54 PM
Good afternoon, Mr. Pasumansky.
I was able to run this function, but when I try to check what are the current camera rotation values, the values are the same of before.
If in my Reference Panel I have values of pitch,Yas and roll and try to import the opk file, after running the camera.reference.rotation, the variables are still in YPR.

How can I convert my opk to the YPR?

Hello adams,

You can use the following function Python function from the Console pane to load the reference data using OPK data:
PhotoScan.app.document.chunk.importCameras(path = "d:/file.txt", format = "opk")
Title: Re: Import OPK from ASCII file and convert them to YPR
Post by: lfreguete on June 25, 2021, 08:15:02 PM
I would like to add that the imported camera coordinates are in a specific crs. Does importCamera take that in consideration?
Title: Re: Import OPK from ASCII file and convert them to YPR
Post by: Alexey Pasumansky on July 01, 2021, 12:52:19 AM
Hello lfreguete,

Can you please show a few lines related to the camera data being imported in the format that you are trying to use on input?

To switch the angle convention used (without re-calculation applied):
Code: [Select]
chunk.euler_angles = Metashape.EulerAngles.EulerAnglesOPK