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.


Topics - MartinKobe

Pages: [1]
1
Hello all,

I get some version problems in Agisoft Metashape.

Specifically, I try to align cameras in a frame-timeline approach using dynamic-scene after upgrade of Metashape to version 2.0.0

My steps in the GUI are exactly the same for the use of MS 2.0.0 and MS 1.7.1:

(a) add 2 different folders as 4D dynamic scene each
(b) import references for camera positions from .txt file
(c) set scale between both cameras
(d) camera calibration
       - split camera groups
       - set camera type, pixel size and focal length
       - set initial to precalibrated with values for f, cx and cy
       - set fixed parameters = all

Now I get results in version 1.7.1 and no results in version 2.0.x.

I tryed to figure out something in the logs - please see attachment.
Log-start is the very same line, which represents the start of alignment.
Purple marked line should represent also the same line.
Between those both, different things seem to happen - which I totally dont get. Did something change in the use of camera calibration?

So, how to solve or handle this  :o?

Best,
Martin





2
Python and Java API / sensor calibration via python API
« on: May 24, 2024, 08:04:30 PM »
Hey guys,

Iam trying to set calbration for two sensors installed in an streoscopic setup:

Code: [Select]
   
       # filling up number of sensors according to number of cameras
        while len(project.chunk.sensors) != len(project.chunk.cameras):
            project.chunk.addSensor()
       
        # set parameters from sensor calibration file content       
        for camera in project.chunk.cameras:
   
            sensor              = camera.sensor
            sensor.label        = camera.label
            camKey              = sensor.label.split('_')[-1]
            sensor.type         = Metashape.Sensor.Type.Frame
            sensor.focal_length = config['sensor'][camKey]['constant']
            sensor.pixel_height = config['sensor'][camKey]['pix_size']
            sensor.pixel_width  = config['sensor'][camKey]['pix_size']
           
            princ_x             = config['sensor'][camKey]['princ_x']
            princ_y             = config['sensor'][camKey]['princ_y']
            focal_len           = config['sensor'][camKey]['constant']
            pixel_size          = config['sensor'][camKey]['pix_size']
           
            cal                 = Metashape.Calibration()
            cal.width           = config['sensor'][camKey]['width']
            cal.height          = config['sensor'][camKey]['height']
            cal.cx              = princ_x/pixel_size
            cal.cy              = princ_y/pixel_size
            cal.f               = focal_len/pixel_size

            sensor.user_calib        = cal
            sensor.fixed_calibration = True

until here, everything works obviously fine. console output:
Quote
for cam in StereoProject.doc.chunk.cameras:

    print(f'camera:       {cam.label}\n'
          f'focal_length: {cam.sensor.focal_length}\n'
          f'pixel_size:   {cam.sensor.pixel_size}\n'
          f'cx (px):      {cam.sensor.calibration.cx}\n'
          f'cy (px):      {cam.sensor.calibration.cy}\n'
          f'f (px):       {cam.sensor.calibration.f}\n')
         
camera:       distorted_stereoCam_E0
focal_length: 15.90096
pixel_size:   Vector([0.00345, 0.00345])
cx (px):      -24.07246376811594
cy (px):      22.217391304347824
f (px):       4608.973913043478

camera:       distorted_stereoCam_E1
focal_length: 15.96475
pixel_size:   Vector([0.00345, 0.00345])
cx (px):      -11.518840579710144
cy (px):      27.91594202898551
f (px):       4627.463768115942

and now comes the beloved blackbox-moment.

I save the project via API using something like
Quote
project.doc.chunk.save()
and then I open it with the GUI.

Please have a look at the attachment (as I dont know how to embedd an image here).
As you can see, everything was saved but of the resolution, focal length and pixel size of only one camera....

I get desperate, pls help :-P Does anyone knows where my mistake is?

best,
Martin

3
Python and Java API / Suppress Console Output
« on: May 16, 2024, 10:57:08 AM »
Dear Community,

we are executing some Metashape methods using the Python API.

As we are facing a large amount of console output:
Is there any way to suppress the console output somehow? (Maybe with redirection to a file?)

Best,
Martin


********************
Anyway, I found the following in the depth of the internet.
It generally works, but NOT with the Metashape module.


class suppress_stdout:
    def __enter__(self):
        self.old_stdout = sys.stdout
        sys.stdout = StringIO()  # Leerer Puffer für die Standardausgabe
        return self

    def __exit__(self, exc_type, exc_val, exc_tb):
        sys.stdout = self.old_stdout

4
Python and Java API / Different results from GUI and API Python
« on: September 16, 2022, 01:47:05 PM »
Dear all,

Iam relatively new in using Agisoft Metashape. And now I've stumbled across one thing that I don't quite understand.

Specifically:
I want to perform an alignment of several undistorted image pairs:
For test reasons I tryed once with the GUI and once with the API Python.
And here comes what I dont understand - the results are different.

What am I doing in the API is:
a) I choose 2 images from two different sensors installed in a stereo-capable arrangement, which are already undistorted.
b) I tell Agisoft some adjustments provided by a JSON-file. e.g. camera constant, sensor pixel size, img height/width, principle points, ...
c) I define a scalebar to tell Agisoft that camera 1 is installed at location [0,0,0] and camera 2 at [0.2,0,0] of my local coordinate system

Code: [Select]
...
    MyProject.settingsFromJSON(filePath=JSONpath, stereoProject=True)

    MyProject.addPhotosToChunk(
                imageDir             = imageDir,
                fileType             = ".tiff")

...

    MyProject.chunk.remove(MyProject.chunk.sensors[0])
   
    for i, camera in enumerate(MyProject.chunk.cameras):
        camkey              = list(MyProject.camArray.keys())[i]
       
        sensor              = MyProject.chunk.addSensor()
        sensor.label        = camkey
       
        sensor.type         = camera.sensor.type
        sensor.calibration  = camera.sensor.calibration
       
        sensor.width        = camera.sensor.width
        sensor.height       = camera.sensor.height
       
        sensor.focal_length = MyProject.camArray[camkey]['camConstant']
        sensor.pixel_height = MyProject.camArray[camkey]['pixelSize']
        sensor.pixel_width  = MyProject.camArray[camkey]['pixelSize']
        sensor.fixed_calibration = True
        camera.sensor       = sensor
       
        calib            = Metashape.Calibration()
        principleX          = MyProject.camArray[camkey]['principleX']
        principleY          = MyProject.camArray[camkey]['principleY']
        calib.cx            = principleX/sensor.pixel_height
        calib.cy            = principleY/sensor.pixel_height
        calib.f             = sensor.focal_length/sensor.pixel_height
        calib.height        = MyProject.camArray[camkey]['imgHeight']
        calib.width         = MyProject.camArray[camkey]['imgWidth']

        sensor.user_calib   = calib
        sensor.fixed_calibration = True
        camera.sensor = sensor
       
    scalebar = MyProject.chunk.addScalebar(MyProject.chunk.cameras[0],
                                           MyProject.chunk.cameras[1])

    scalebar.reference.distance = 0.2
    scalebar.reference.accuracy = 0.1

...


d) I try to perform the steps matchPhotos and alignPhotos using the API

Code: [Select]
    MyProject = PyExpress.photogrammicProcessing.processing.matchPhotos(
                project              = MyProject,
                detailLevel          = 0,
                generic_preselection = False,
                ref_preselection     = False,
                filter_stat_tie_pp   = False,
                keypoint_limit       = 10000,
                tiepoint_limit       = 5000,
                guided_matching      = False)

   --> which runs:     project.chunk.matchPhotos(
                              downscale=detailLevel,
                              generic_preselection=generic_preselection,
                              reference_preselection=ref_preselection,
                              filter_mask=False,
                              mask_tiepoints=False,
                              filter_stationary_points=filter_stat_tie_pp,
                              keypoint_limit=keypoint_limit,
                              tiepoint_limit=tiepoint_limit,
                              guided_matching=guided_matching)
   
    MyProject = PyExpress.photogrammicProcessing.processing.alignCameras(
                project              = MyProject,
                adaptive_fitting     = False,
                reset_alignment      = False)

e) Finally, I save everything in an Agisoft project using something like doc.save(path.psx).

__________

However, with some of my image-pairs this works pretty good. And with some not.

Now comes the blackbox-moment (also compare to the attachements pls):
  • I open the created .psx-file in the GUI
  • I understand that no alignment has been performed
  • So I try alignment again by using Workflow/AlignPhotos within the GUI + checking the box "reset current alignment"
  • Here it works, ...,  :o :o :o.

I ve tryed to implement exactly the same what the GUI is doing when running "Align Photos". Where am I missing something here?

I hope I have expressed myself clearly  ::) :)

Thank you very much in advance,
Martin

Pages: [1]