Forum

Author Topic: Matrix Diag in new version of Agisoft  (Read 4030 times)

viktork

  • Newbie
  • *
  • Posts: 5
    • View Profile
Matrix Diag in new version of Agisoft
« on: February 06, 2017, 05:39:06 PM »
Hello All,

I ma new in photoscan and i am trying a way to use the auto python script to create a model but when i try the script is failing in the stage

   m = PhotoScan.Matrix().diag([1,1,1,1])   

   m = m * T
   s = math.sqrt(m[0,0] ** 2 + m[0,1] ** 2 + m[0,2] ** 2) #scale factor
   R = PhotoScan.Matrix( [[m[0,0],m[0,1],m[0,2]], [m[1,0],m[1,1],m[1,2]], [m[2,0],m[2,1],m[2,2]]])

and gives an error AttributeError: 'PhotoScan.Document' object has no attribute 'diag'

Could you please someone give me a help why is doing that?

Thanks in advance,


Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14749
    • View Profile
Re: Matrix Diag in new version of Agisoft
« Reply #1 on: February 06, 2017, 05:49:42 PM »
Hello viktork,

Just change Matrix().diag() to Matrix.Diag() for the version 1.3 scripts.
Best regards,
Alexey Pasumansky,
Agisoft LLC

viktork

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Matrix Diag in new version of Agisoft
« Reply #2 on: February 06, 2017, 06:15:58 PM »
Hello Alexey,

Thank you very much.
No is giving me another error.

Traceback (most recent call last):
File "C:/Users/Administrator/Desktop/Script/AutoProcess_v8-PIM.py", line 294, in <module>
 processscan(f)
 File "C:/Users/Administrator/Desktop/Script/AutoProcess_v8-PIM.py", line 216, in processscan
  mx = (chunk.markers[c1].position + chunk.markers[c2].position + chunk.markers[c3].position + chunk.markers[c4].position) / 4
 AttributeError: invalid arguments

Could you please give me a help?

Thanks for everything :)

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14749
    • View Profile
Re: Matrix Diag in new version of Agisoft
« Reply #3 on: February 06, 2017, 06:22:01 PM »
Hello viktork,

I think some additional information is required to understand which line is failing. Can you attach the full script or send it via PM? At least a part related to pocessscan() function description and argument that you are passing to it

P.S. I'm moving the thread to Python scripting forum.
Best regards,
Alexey Pasumansky,
Agisoft LLC

viktork

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Matrix Diag in new version of Agisoft
« Reply #4 on: February 06, 2017, 06:23:41 PM »
This is the lines that is going to do is in the stage that i trying to crate the bounding box:

   v_t = T * PhotoScan.Vector( [0,0,0,1] )
   m = PhotoScan.Matrix().diag([1,1,1,1])   

   m = m * T
   s = math.sqrt(m[0,0] ** 2 + m[0,1] ** 2 + m[0,2] ** 2) #scale factor
   R = PhotoScan.Matrix( [[m[0,0],m[0,1],m[0,2]], [m[1,0],m[1,1],m[1,2]], [m[2,0],m[2,1],m[2,2]]])
   R = R * (1. / s)
   newregion.rot = R.t()

    # Calculate center point of the bounding box, by taking the average of 2 left and 2 right markers
   mx = (chunk.markers[c1].position + chunk.markers[c2].position + chunk.markers[c3].position + chunk.markers[c4].position) / 4  >>>>> In this level is failing

   mx = PhotoScan.Vector([mx[0], mx[1], mx[2]])
   newregion.center = mx

   dist = chunk.markers[mp0].position - chunk.markers[mpy].position
   dist = dist.norm()

   ratio = dist / distancepy

   newregion.size = PhotoScan.Vector([boxwidth* ratio, boxheight* ratio, boxdepth * ratio])

   chunk.region = newregion
   chunk.updateTransform()

   log("Bounding box should be aligned now")

Thanks in advance for your help.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14749
    • View Profile
Re: Matrix Diag in new version of Agisoft
« Reply #5 on: February 06, 2017, 06:30:59 PM »
And what are c1, c2, c3, c4 and mp0, mpy? Can you also post how these variables are defined?
Best regards,
Alexey Pasumansky,
Agisoft LLC

viktork

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Matrix Diag in new version of Agisoft
« Reply #6 on: February 06, 2017, 06:32:53 PM »
mp0 = 0
   mpy = 0
   mpx = 0
   fp0 = 0
   fpy = 0
   fpx = 0
   #setting for Y up, Z forward -> needed for mixamo/unity
   vector0 = PhotoScan.Vector((0,0,0))
   vectorY = PhotoScan.Vector((0,0,distancepy))   # Specify Y Distance
   vectorX = PhotoScan.Vector((distancepx,0,0))   # Specify X Distance
   c1 = 0
   c2 = 0
   c3 = 0
   c4 = 0
   c = 0

   for m in chunk.markers:
      if m.label == c1target:
         log ("Center 1 point found")
         c1 = c
      if m.label == c2target:
         log ("Center 2 point found")
         c2 = c
      if m.label == c3target:
         log ("Center 3 point found")
         c3 = c
      if m.label == c4target:
         log ("Center 4 point found")
         c4 = c
      if m.label == p0:
         mp0 = c
         fp0 = 1
         m.reference.location = vector0
         m.reference.enabled = 1
         log ("Found floormat center point")
      if m.label == py:
         mpy = c
         fpy = 1
         m.reference.location = vectorY
         m.reference.enabled = 1
         log ("found floormat Y point")
      if m.label == px:
         mpx = c
         fpx = 1
         m.reference.location = vectorX
         m.reference.enabled = 1
         log ("found floormat X point")
      c = c + 1 
 
   if fp0 and fpx and fpy:
      log ("Found all markers")
      chunk.updateTransform()
   else:
      log ("Error: not all markers found")

   newregion = chunk.region

   T = chunk.transform.matrix
   v_t = T * PhotoScan.Vector( [0,0,0,1] )
   m = PhotoScan.Matrix.Diag([1,1,1,1])   

   m = m * T
   s = math.sqrt(m[0,0] ** 2 + m[0,1] ** 2 + m[0,2] ** 2) #scale factor
   R = PhotoScan.Matrix( [[m[0,0],m[0,1],m[0,2]], [m[1,0],m[1,1],m[1,2]], [m[2,0],m[2,1],m[2,2]]])
   R = R * (1. / s)
   newregion.rot = R.t()

    # Calculate center point of the bounding box, by taking the average of 2 left and 2 right markers
   mx = (chunk.markers[c1].position + chunk.markers[c2].position + chunk.markers[c3].position + chunk.markers[c4].position) / 4

   mx = PhotoScan.Vector([mx[0], mx[1], mx[2]])
   newregion.center = mx

   dist = chunk.markers[mp0].position - chunk.markers[mpy].position
   dist = dist.norm()

   ratio = dist / distancepy

   newregion.size = PhotoScan.Vector([boxwidth* ratio, boxheight* ratio, boxdepth * ratio])

   chunk.region = newregion
   chunk.updateTransform()

   log("Bounding box should be aligned now")

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14749
    • View Profile
Re: Matrix Diag in new version of Agisoft
« Reply #7 on: February 06, 2017, 08:08:02 PM »
Hello viktork,

Does the script work without failures if you remove everything below?
Code: [Select]
  # Calculate center point of the bounding box, by taking the average of 2 left and 2 right markers
Also for debugging purposes you can use print lines to print all output to the console, like markers' positions used for mx calculation.
Best regards,
Alexey Pasumansky,
Agisoft LLC

viktork

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Matrix Diag in new version of Agisoft
« Reply #8 on: February 06, 2017, 08:34:12 PM »
Hello Alexey,

I have delete the lines as you told me,worked fine but now i have a problem is not loading the whole photos because some stages are missing.
I believe that i made a big progress on that.
Tomorrow i will have a new module and i will try again.

Thanks for your help,
Viktor

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14749
    • View Profile
Re: Matrix Diag in new version of Agisoft
« Reply #9 on: February 06, 2017, 08:42:58 PM »
Hello Viktor,

Ok, that's nice insight. I've tried to get a sum of two vectors, but using None instead one of them and got "Invalid Argument" error. So it really seems that some of the markers that you are trying to use are not defined in space (do not have actual position). You may need to add some checks for that to your code.
Best regards,
Alexey Pasumansky,
Agisoft LLC