Forum

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Aravinth

Pages: [1] 2
1
Python and Java API / Align Images using Control points.
« on: January 23, 2020, 04:20:47 PM »
Hello Everyone,
                      I have Aligned the images using 6 markers and projected the markers and I have got the errors for all the markers. In order to do a simulation process, I have align the images using the control points and get the errors for those.  Now I am trying to use 5 control points from the markers leaving each one at each iteration and trying to get the error for the 5 control points each time, but after running the first iteration I have got the marker error for 5 markers and I have got the error

<CoordinateSystem 'ETRS89 / UTM zone 32N (N-E) (EPSG::3044)'>

2020-01-24 14:53:56 point 3 0.005685494747012854 0.004827383905649185 0.0002521519620586332 0.00746271173922734

2020-01-24 14:53:56 point 4 -0.01812988135498017 -0.008003545925021172 0.0012451643736568485 0.019856983145407684

2020-01-24 14:53:56 point 6 -0.000979920499958098 0.0036176517605781555 -0.0008834924167473446 0.0038507411361324226

2020-01-24 14:53:56 point 2 0.028576436801813543 -0.009189705364406109 -0.001535830924112247 0.03005698257643467

2020-01-24 14:53:56 point 1 -0.015152139123529196 0.008748216554522514 0.0009220051803708884 0.017520522436737913

Traceback (most recent call last):

2020-01-24 14:53:56   File "E:/Softz/Align_Flir.py", line 225, in <module>

2020-01-24 14:53:56     error = estim - source

2020-01-24 14:53:56 AttributeError: invalid arguments

2020-01-24 14:53:56 Error: invalid arguments

The code is not proceeding after this, please kindly help What am I doing wrong in this. I have attached the code along with this mail Kindly help me, please.


Thank you, everyone.


Code: [Select]

import itertools
import glob
import time
import os

try:
    import Metashape as env
    import Metashape
    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 = os.path.abspath('.') #'D:\\my-jobs\\marker\\'
path_images = os.path.abspath('.') #'D:\\my-jobs\\marker\\'
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 = os.path.join(path_images, 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=Metashape.CalibrationFormatXML)
# # 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 = 'Marker_Try.txt'

# chunk = Metashape.app.document.chunk
# out_crs = Metashape.CoordinateSystem("EPSG::3044")
# for camera in chunk.cameras:
#     if camera.reference.location:
#         camera.reference.location = Metashape.CoordinateSystem.transform(camera.reference.location, chunk.crs, out_crs)
# chunk.crs = out_crs 
# ch.importReference(path, Metashape.ReferenceFormatCSV, delimiter=",", columns="nxyz", create_markers=True)

# ch.updateTransform()
         
# ch.matchPhotos(downscale=0.25, generic_preselection=False,reference_preselection=True)
# ch.alignCameras()


#Project markers
#ch = Metashape.app.document.chunk
# file = open('C:\\Program Files\\Agisoft\\Metashape Pro', "markers_projections_rgb_center.txt") #input file

print(os.getcwd())
r = open('Marker_Try.txt', 'r')
data_points = r.readlines()
r.close()

import os, tempfile

for ind in range (len(data_points)):
    #w = open('Marker_Try.txt', 'w')
    #w.writelines([data_points[k] for k in range(len(data_points)) if k != ind])
    #w.close()
    data_ = [data_points[k] for k in range(len(data_points)) if k != ind]
    load_images = True
    load_thermal = True

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

    tmp = tempfile.NamedTemporaryFile(delete=False)
    with open(tmp.name, 'w') as f:
        f.writelines(data_)
        f.close()
    cnt = 0
    # go over all images
    for filename in glob.glob(os.path.join(dir_srs,fileext)):
    # add image to list
        imgList.append(filename)
        fname = filename.split('\\')
        print(filename, fname)
        # 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=Metashape.CalibrationFormatXML)
    # 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 = 'Marker_Try.txt'
    path = tmp.name

    chunk = Metashape.app.document.chunk
    out_crs = Metashape.CoordinateSystem("EPSG::3044")
    for camera in chunk.cameras:
        if camera.reference.location:
            camera.reference.location = Metashape.CoordinateSystem.transform(camera.reference.location, chunk.crs, out_crs)
    chunk.crs = out_crs 
    ch.importReference(path, Metashape.ReferenceFormatCSV, delimiter=",", columns="nxyz", create_markers=True)

    ch.updateTransform()
           
    ch.matchPhotos(downscale=0.25, generic_preselection=False,reference_preselection=True)
    ch.alignCameras()
    ###################
    ch = Metashape.app.document.chunk
    file = open("Marker_center_Flir_Final.txt") #input file
    eof = False
    line = file.readline()
    if not len(line):
            eof = True
    while not eof:
        sp_line = line.rsplit(",", 3)   #splitting read line by four parts
        y = float(sp_line[3]) #y- coordinate of the current projection in pixels
        x = float(sp_line[2]) #x- coordinate of the current projection in pixels
        path = sp_line[0] #camera label
        marker_name = sp_line[1] #marker label
        flag = 0
        for i in range (len(ch.cameras)):

            if ch.cameras[i].label == path: #searching for the camera
                for j in range (len(ch.markers)): #searching for the marker (comparing with all the marker labels in chunk)
                    if ch.markers[j].label == marker_name:
                        ch.markers[j].projections[ch.cameras[i]] = Metashape.Marker.Projection(Metashape.Vector([x,y]), True) #setting up marker projection of the correct photo)
                        flag = 1
                        break
                #if ind != j:
                #    ch.cameras[j].enable = False
                if not flag:
                    marker = ch.addMarker()
                    marker.label = marker_name
                    marker.projections[ch.cameras[i]] =  Metashape.Marker.Projection(Metashape.Vector([x,y]), True)
                break
               
        line = file.readline() #reading the line from input file
        if not len(line):
            eof = True
            break # EOF
    file.close()


    doc = env.app.document
    env_type = 1
    #chunk = env.app.document.chunk
    #chunk = env.app.document.addChunk()
    chunk = Metashape.app.document.chunk
    #path = "Marker_Try.txt"
    path = tmp.name
    chunk.importReference(path, format = env.ReferenceFormatCSV, delimiter=",", columns="nxyz", create_markers=True)
    for camera in chunk.cameras:
        camera.reference.enabled = False
    chunk.updateTransform()


       
    print ("--------------- Markers import finished. ----------------------\n")
    print(str(chunk.crs))

    chunk = Metashape.app.document.chunk

    for marker in chunk.markers:
        source = marker.reference.location
        estim = chunk.crs.project(chunk.transform.matrix.mulp(marker.position))
        error = estim - source
        total = error.norm()
        print(marker.label, error.x, error.y, error.z, total)
    print('<<------------------------------------->>')
    time.sleep(20)


2
Python and Java API / Re: Marker errors are large.
« on: January 20, 2020, 02:52:21 PM »
Dear Alexey,
                     I have sent all the essential files to the support@agisoft.com. Kindly have a look at it. Thank you

3
Python and Java API / Re: Marker errors are large.
« on: January 20, 2020, 02:25:02 PM »
Dear Alexey,
Sure I will send you the files.

4
Python and Java API / Re: Marker errors are large.
« on: January 20, 2020, 02:23:57 PM »
Dear Alexy,
I have used chunk.updateTransform() the errors are reduced but not till the centimetre level. I have a total error of 15 m. What can I do now to reduce them.

5
Python and Java API / Re: Marker errors are large.
« on: January 20, 2020, 02:12:15 PM »
Dear Alexy,
 I don't have a CSV file for the markers. I Have manually placed marker text file and the GCP textfile provided to me by the guide. Do I need a csv file for the manually placed markers. 

6
Python and Java API / Marker errors are large.
« on: January 19, 2020, 05:40:16 PM »
Hello Everyone,
                            I have used the projected markers and the GCP's to get the error of markers. I have used ETRS89 / UTM zone 32N (N-E) (EPSG::3044) coordinate system. But I get a huge error. I have also attached the code for projecting marker and to get the error. Kindly help me to reduce the error of the markers projected. Thank you.

Code: [Select]
ch = Metashape.app.document.chunk

chunk = Metashape.app.document.chunk
out_crs = Metashape.CoordinateSystem("EPSG::3044")
for camera in chunk.cameras:
    if camera.reference.location:
        camera.reference.location = Metashape.CoordinateSystem.transform(camera.reference.location, chunk.crs, out_crs)
for marker in chunk.markers:
    if marker.reference.location:
        marker.reference.location = Metashape.CoordinateSystem.transform(marker.reference.location, chunk.crs, out_crs)
chunk.crs = out_crs


# file = open('C:\\Program Files\\Agisoft\\Metashape Pro', "markers_projections_rgb_center.txt") #input file
file = open("marker_center_A_Manual.txt") #input file
eof = False
line = file.readline()
if not len(line):
eof = True
while not eof:
sp_line = line.rsplit(",", 3)   #splitting read line by four parts
y = float(sp_line[3]) #y- coordinate of the current projection in pixels
x = float(sp_line[2]) #x- coordinate of the current projection in pixels
path = sp_line[0] #camera label
marker_name = sp_line[1] #marker label
flag = 0
for i in range (len(ch.cameras)):

if ch.cameras[i].label == path: #searching for the camera

for j in range (len(ch.markers)): #searching for the marker (comparing with all the marker labels in chunk)
if ch.markers[j].label == marker_name:
ch.markers[j].projections[ch.cameras[i]] = Metashape.Marker.Projection(Metashape.Vector([x,y]), True) #setting up marker projection of the correct photo)
flag = 1
break

if not flag:
marker = ch.addMarker()
marker.label = marker_name
marker.projections[ch.cameras[i]] =  Metashape.Marker.Projection(Metashape.Vector([x,y]), True)
break

line = file.readline() #reading the line from input file
if not len(line):
eof = True
break # EOF
file.close()


doc = env.app.document
env_type = 1
#chunk = env.app.document.chunk
#chunk = env.app.document.addChunk()
chunk = Metashape.app.document.chunk
path = "C:\\Program Files\\Agisoft\\Metashape Pro\\ipi-measurement-gcp.txt"
chunk.importReference(path, format = env.ReferenceFormatCSV, delimiter=",", columns="nxyz", create_markers=True)

chunk = Metashape.app.document.chunk

for marker in chunk.markers:
      source = marker.reference.location
      estim = chunk.crs.project(chunk.transform.matrix.mulp(marker.position))
      error = estim - source
      total = error.norm()
      print(marker.label, error.x, error.y, error.z, total)




7
Python and Java API / Some of the images failed to align.
« on: January 14, 2020, 08:43:51 PM »
Hello everyone,
                           I have tried to align the thermal images using the align photos tool with the highest accuracy and also tried with the python script. I have tried in several systems (Demo version, Trail and also in the paid professional version)  but some of the images are failed to align. But the same python script for the RGB image and using the Align photos tools it works perfectly. I have attached the image with this. Kindly help me to resolve this.  kindly have a look at the attachment.


8
Python and Java API / Projecting Markers.
« on: January 07, 2020, 02:13:42 PM »
Hello Everyone,
               I have detected the markers in the image using blob detector using opencv and I have got a text file containing the markers with the coordinates. I have to project these markers into the images and get errors for the simulation. https://we.tl/t-dfvysdoUhM This link has the text file. I have also aligned the images using the script. I don't have any idea how to project the markers into the images and get the errors for simulation. Kindly help me with working code for projecting the markers.

Kindly help me...Thank you.

9
Hello Alexy, I have another doubt

1. How to calculate the Ground sampling distance GSD for the optical and thermal camera. I have the front and side overlap of the images relative to thermal camera and the altitude of the flight.

2.How to calculate the distance between flight strips for each flight.

Kindly help me.

10
Thank you Alexey. Its working now. But Why the same format worked before and not now ??

11
Hello Everyone,

I tried to run the script but I am getting this error. My calibration file is .xml format and I have done this before in the same way but now I am getting this error. Help me with this problem. I have attached the code with this.

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 = '20191220_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()


12
General / Ground sampling distance GSD
« on: January 03, 2020, 10:01:01 PM »
Hello everyone,
                         
1. How to calculate the Ground sampling distance GSD for the optical and thermal camera. I have the front and side overlap of the images relative to thermal camera and the altitude of the flight.

2.How to calculate the distance between flight strips for each flight.

Kindly help me.

13
Python and Java API / Re: Align Thermal images.
« on: December 11, 2019, 05:31:19 PM »
Hello Alexey,
 
Thank you for your guidance. I wil try and let you know.

14
Python and Java API / Re: Images are not visble after alignment
« on: December 11, 2019, 02:05:36 PM »
Hello Alexey,

Thank you for your guidance. I can see the images in a new chunk Flir.  Thank you so much.

15
Python and Java API / Re: Align Thermal images.
« 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.

Pages: [1] 2