Forum

Author Topic: Camera Pose Estimation  (Read 2909 times)

apurv.ashish

  • Newbie
  • *
  • Posts: 4
    • View Profile
Camera Pose Estimation
« on: January 07, 2018, 10:52:43 PM »
Hello,
I am working on the project to compare the camera pose estimation with the ground truth. The camera.xml, provides [r,t] matrix for all the cameras used. Does photoscan professional also has a feature which outputs the camera pose in world coordinate and its rotation.
Additionally, I am having problems in parsing the camera.xml file to extract transform matrix, is there an existing python script for parsing the XML file.

Best Regards.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14855
    • View Profile
Re: Camera Pose Estimation
« Reply #1 on: January 08, 2018, 01:40:07 PM »
Hello apurv.ashish,

Exported XML file from the same project using Standard and Professional edition would be practically identical (with the only exception, if you have georeferneced the model in Professional edition).

If you are using PhotoScan Professional you can access camera transformation matrix using Python without exporting XML:

Code: [Select]
import PhotoScan
chunk = PhotoScan.app.document.chunk
for camera in chunk.cameras:
    print(camera.transform)
Best regards,
Alexey Pasumansky,
Agisoft LLC

apurv.ashish

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Camera Pose Estimation
« Reply #2 on: January 11, 2018, 04:32:53 PM »
Hi,

Thanks for the reply. I was looking for a way to parse and calculate camera pose. However, I have created one which parses the camera.xml and extracts the camera pose. Hope, someone else will find it useful.

However, I need help in calculating re projection error. I used the script you provoded on the thread :

http://www.agisoft.com/forum/index.php?topic=3189.0

However, it returns error: Error =  AttributeError: matrix * vector: vector length does not match matrix row size minus 1.

Is there any change due to updates. What changes are required.

Best Regards
Apurv.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14855
    • View Profile
Re: Camera Pose Estimation
« Reply #3 on: January 11, 2018, 04:51:48 PM »
Hello Apurv,

The script that you have attached is not valid for the recent release versions.

The following function would return individual reprojection error for each photo in the chunk, passed as an argument:

Code: [Select]
import PhotoScan, math

 def calc_reprojection(chunk):

point_cloud = chunk.point_cloud
points = point_cloud.points
npoints = len(points)
projections = chunk.point_cloud.projections
err_sum = 0
num = 0
photo_avg = {}

for camera in chunk.cameras:
if not camera.transform:
continue

T = camera.transform.inv()
calib = camera.sensor.calibration
point_index = 0
photo_num = 0
photo_err = 0
for proj in projections[camera]:
track_id = proj.track_id
while point_index < npoints and points[point_index].track_id < track_id:
point_index += 1
if point_index < npoints and points[point_index].track_id == track_id:
if not points[point_index].valid:
continue

#dist = calib.error(T.mulp(points[point_index].coord), proj.coord).norm() ** 2
dist = camera.error(points[point_index].coord, proj.coord).norm() ** 2

err_sum += dist
num += 1
photo_num += 1
photo_err += dist

photo_avg[camera.label] = (math.sqrt(photo_err / photo_num), photo_num)

sigma = math.sqrt(err_sum / num)
rep_avg = sigma

return (rep_avg, photo_avg)
Best regards,
Alexey Pasumansky,
Agisoft LLC

apurv.ashish

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Camera Pose Estimation
« Reply #4 on: January 11, 2018, 09:04:46 PM »
Hi, thanks for the code and sorry for the lots of questions. Below is the code I am using to call the reprojection error function error you provided, however, when I run the scripts, it throws an Error: Can't open file: No such file or directory (2). I have checked and the project file is there only hence, I am unable to understand this error.

Code: [Select]
def main():

doc = PhotoScan.app.document

doc.open("/home/apurv/Desktop/HTCV-PJA/fountain dense_orignal/fountain_dense/pj9.psz")

chunk = doc.chunk

total_error, ind_error = calc_reprojection(chunk)

print('%f'%total_error)


2. The second issue I have having is with camera pose estimation from the Transformation matrix in the camera.xml.
I am using below relation to obtain the camera pose:
                               
                                                              C = -(RT)*T
where R and T are the rotational(3x3 matrix) and translation(3x1) vector. But, there is a huge difference in the ground truth and pose esitmation. For instance, Camera 0 has follow ground truth :
                                                         [-3.48  -1.196 -9.845]
estimation :
                                                          [-1.199 -0.017  0.427]
The difference increases even more for the 10th camera in the reconstruction:
ground truth :                                  [ 19.671   0.222  11.429]
estimation :                                      [ 3.602  0.115  3.388]

My question is if the transformation matrix is represented differently in photscan XML file or I have doing something incorrectly in reconstruction steps.

Best Regards
Apurv.
« Last Edit: January 11, 2018, 10:01:22 PM by apurv.ashish »