Forum

Author Topic: Align Thermal images.  (Read 2780 times)

Aravinth

  • Newbie
  • *
  • Posts: 18
    • View Profile
Align Thermal images.
« on: December 10, 2019, 09:43:12 PM »
Hello,
         Currently, I am working with UAV thermal images and I have to the following steps in python scripting.
 
1.Load thermal images
2.Load calibration data
3.Load GCP's
4.Select-control points
5. Do alignment
6. Get extrinsic parameters
7.Project GCP's
8. Get errors.

I think I have done till alignment but I am not sure, How to proceed after alignment. I have attached my script with this. Kindly help me.


Code: [Select]

import glob
try:
    import Metashape as env
    doc = Metashape.app.document
    env_type = 1
except:
    import PhotoScan as env
    doc = PhotoScan.app.document
    env_type = 2
   
load_images = True
load_thermal = True
# Thermal data
path_calib = 'C:\\Program Files\\Agisoft\\Metashape Pro'
path_images = 'C:\\Program Files\\Agisoft\Metashape Pro\\flir'
path_subdir = 'flir\\'
fileext = '*.tiff'
chunk_name = 'FLIR'
calib_fname = 'xt2_flir_20190206.xml'
flength = 13
psize = 0.017

ch = env.app.document.addChunk()
ch.label = chunk_name

# initiate images list
imgList = []
imgListNames = []
# construct flight directory
dir_srs = path_subdir
# reset file counter
cnt = 0

# go over all images
for filename in glob.glob(dir_srs + fileext):
# add image to list
    imgList.append(filename)
    fname = filename.split('\\')
    # add file name
    imgListNames.append(fname[-1])
    #' increment counter
    cnt += 1
   
if load_images == 1:
    # add images to chunk
    ch.addPhotos(imgList)
# create calibration instance
calibData = env.Calibration()
# load calibration data from file
calibData.load(calib_fname, format="xml")
# load camera calibration params
ch.sensors[0].user_calib = calibData
# assign camera focal length
ch.sensors[0].focal_length = flength
# assign camera pixel size
ch.sensors[0].pixel_size = env.Vector([psize,psize])
# do not optimise camera intrinsics
if env_type == 1:
    ch.sensors[0].fixed_calibration = True
else:
    ch.sensors[0].fixed = True

# ch = Metashape.app.document.chunk
path = '20191024_gcp_coordinates.txt'
ch.loadReference(path, format = Metashape.ReferenceFormatCSV, delimiter=",", columns="nxyz")

for frame in ch.frames:
    frame.matchPhotos(accuracy=Metashape.HighestAccuracy, generic_preselection=True,reference_preselection=True)

# ch.matchPhotos(accuracy=Metashape.LowAccuracy, generic_preselection=True,reference_preselection=True)
ch.alignCameras()
# ch.buildDepthMaps(quality=Metashape.MediumQuality, filter=Metashape.AggressiveFiltering)
# ch.buildDenseCloud()
# ch.buildModel(surface=Metashape.Arbitrary, interpolation=Metashape.EnabledInterpolation)
# ch.buildUV(mapping=Metashape.GenericMapping)
# ch.buildTexture(blending=Metashape.MosaicBlending, size=4096)
#optimizeCameras(fit_f=True, fit_cx=True, fit_cy=True, fit_b1=True, fit_b2=True, fit_k1=True, fit_k2=True, fit_k3=True, fit_k4=False, fit_p1=True, fit_p2=True, fit_p3=False, fit_p4=False)


« Last Edit: December 10, 2019, 09:49:17 PM by Aravinth »

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14847
    • View Profile
Re: Align Thermal images.
« Reply #1 on: December 10, 2019, 10:07:23 PM »
Hello Aravinth,

To place the GCPs you need to have the data related to the GCP label and its projections on the multiple photos (in any readable format) in order to assign them to the corresponding cameras.
Best regards,
Alexey Pasumansky,
Agisoft LLC

Aravinth

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: Align Thermal images.
« Reply #2 on: December 10, 2019, 10:17:33 PM »
Hello Alexey,
 
I have the GCP and its projections on multiple images. I don't have proper coding knowledge to do that. So what actually I have to do in this situation to project the GCP.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14847
    • View Profile
Re: Align Thermal images.
« Reply #3 on: December 11, 2019, 04:35:17 PM »
Hello Aravinth,

To define the projection for the marker on the given camera you can use the following code:

Code: [Select]
marker = chunk.markers[0] #just as an example
camera = chunk.cameras[0] #just as an example
x, y = 150, 300 #coordinates in pixels from the top-left image corner
marker.projections[camera] = Metashape.Marker.Projection(Metashape.Vector([x, y]), True)

So if you are reading the information from the file, you need to find the proper camera by its id, label or file path (depending on the information available in the file).
Best regards,
Alexey Pasumansky,
Agisoft LLC

Aravinth

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: Align Thermal images.
« Reply #4 on: December 11, 2019, 05:31:19 PM »
Hello Alexey,
 
Thank you for your guidance. I wil try and let you know.