Forum

Author Topic: Use of pickPoint() in order to create marker  (Read 10763 times)

CindyFr

  • Newbie
  • *
  • Posts: 21
    • View Profile
Use of pickPoint() in order to create marker
« on: June 08, 2018, 03:23:27 PM »
Hello,

I want to pick points on my model.
I know the coordinates of points, when I place them by addMarker() function, they are at the right place, but if I reference my model, they leave I don't know where. I supposed that is because they are not really on the model but just beside. The idea is to get the point on the model. So I've found the pickPoint() function.
But when I try to use it, my point doesn't appear at the right place at all (It is not even on the model ...)

Can somebody help me please ?
I know the coordinate of my point because I pick it in another software.
v2 is the ray origin (here the coordinate of the camera when I pick point in my other software)
v3 is my point

Code: [Select]
v2 = PhotoScan.Vector([float(tabResetSrcO[idM][0]), float(tabResetSrcO[idM][1]), float(tabResetSrcO[idM][2])])
v3 = PhotoScan.Vector([float(srcP[0]), float(srcP[1]), float(srcP[2])])
p = chunk.model.pickPoint(v2,v3)
if(not(p is None)):
m = chunk.addMarker()
m.label = myOwnLabel
m.reference.location = p
« Last Edit: June 08, 2018, 04:00:03 PM by CindyFr »

CindyFr

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Use of pickPoint() in order to create marker
« Reply #1 on: June 11, 2018, 10:16:43 AM »
Anybody ?

Paulo

  • Hero Member
  • *****
  • Posts: 1463
    • View Profile
Re: Use of pickPoint() in order to create marker
« Reply #2 on: June 11, 2018, 06:15:42 PM »
Hello,

I think problem is different Coordinate Systems (CS) used by PhotoScan.

pickPoint function uses coordinates of 2 points in internal coordinate system to determine coordinates of point on surface in same internal system.  In your code v2 and v3 coordinates come from external software so I suppose it is in some projected CS.

So you must transform v2, v3 from PCS to internal CS as:

T.inv().mulp(chunk.crs.unproject(v2)) where T = chunk.transfrom.matrix

The result of pickPoint, p is also in internal CS so to assign to marker.reference.location you must transform to PCS as:

chunk.crs.project(T.mulp(p)).


Hope this makes sense!
« Last Edit: June 12, 2018, 05:55:19 PM by Paulo »
Best Regards,
Paul Pelletier,
Surveyor

CindyFr

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Use of pickPoint() in order to create marker
« Reply #3 on: June 11, 2018, 06:23:04 PM »
First of all, hello Paulo and thank you for replying.
I thought the same thing, but the problem seems to be that PhotoScan has two coordinates systems in its own :
when I pick a point with the ruler tool, I get a coordinate and when I print the coordinate of the same point by script, I get another coordinate. In fact, it seems that PhotoScan has an internal coordinate system and a display coordinate system.
I don't know how to pass from one to the other one.

Also, you don't have the same coordinates if you use many ways to print them : for a marker, you have marker.reference.location and  marker.position for example. And the two methods don't retrieve the same coordinates for the same marker.

Paulo

  • Hero Member
  • *****
  • Posts: 1463
    • View Profile
Re: Use of pickPoint() in order to create marker
« Reply #4 on: June 11, 2018, 06:29:37 PM »
Exactly,

in script pickPoint will give coordinates in Internal CS. The GUI pick with ruler will display coordinates in PCS and the transformation from internal p coordinates to PCS is:

chunk.crs.project(T.mulp(p)) where T = chunk.transform.matrix

as given in my last post...
« Last Edit: June 12, 2018, 05:55:48 PM by Paulo »
Best Regards,
Paul Pelletier,
Surveyor

CindyFr

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Use of pickPoint() in order to create marker
« Reply #5 on: June 12, 2018, 09:28:51 AM »
Ok, I'm sorry  :-X, I haven't seen the definition of T ... Thank you ! I'll test it today. :)

CindyFr

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Use of pickPoint() in order to create marker
« Reply #6 on: June 12, 2018, 12:33:49 PM »
So, I've tested it, and it seems to be good,

Just little changes :

Code: [Select]
T = chunk.transform.matrix
ptSrcT = T.inv().mulp(chunk.crs.unproject(ptSrc))
ptDstT = T.inv().mulp(chunk.crs.unproject(ptDst))
pT = chunk.model.pickPoint(ptSrcT, ptDstT)

m = chunk.addMarker(pT)

« Last Edit: June 12, 2018, 03:43:34 PM by CindyFr »

mcstieg

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
Re: Use of pickPoint() in order to create marker
« Reply #7 on: August 29, 2020, 03:04:12 PM »
Is there a possibility to calculate the distance of a camera to the model in z-axis using model.pickPoint function?

I'd like to calculate the point on the model under the camera and the distance to camera center.

Thank you!
 

Paulo

  • Hero Member
  • *****
  • Posts: 1463
    • View Profile
Re: Use of pickPoint() in order to create marker
« Reply #8 on: August 30, 2020, 01:53:56 AM »
Hi,

you could just do following for example for first camera in chunk:

Code: [Select]
T = chunk.transform.matrix
camera = chunk.cameras[0]
p1 = chunk.crs.project(T.mulp(camera.center)) # camera center coordinates in project coordinate reference system
p2 = p1 - Metashape.Vector((0,0,1)) # point that is 1 unit lower in Z than p1 in project crs
p2i = T.inv().mulp(chunk.crs.unproject(p2)) # p2 in internal coordinate system
p3i = chunk.point_cloud.pickPoint(camera.center,p2i) # point on model resulting from projection of camera center to p2i vector in internal coordinate system
p3 =  chunk.crs.project(T.mulp(p3i)) # point in project crs
delz = p1.z - p3.z   # difference in Z between camera center and point beneath on model in project crs
« Last Edit: August 30, 2020, 09:41:48 AM by Paulo »
Best Regards,
Paul Pelletier,
Surveyor

mcstieg

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
Re: Use of pickPoint() in order to create marker
« Reply #9 on: August 30, 2020, 12:22:36 PM »
Thank you very much - not only for the code but also for the explanation in the code!
Works great!