Forum

Author Topic: Code improvement  (Read 5970 times)

grab

  • Newbie
  • *
  • Posts: 3
    • View Profile
Code improvement
« on: April 29, 2023, 06:07:35 PM »
Dear collegues,

i am trying to create a python script for agisoft v2.0:
What are you thinking about my code?
Do you have any suggestions for improvements?

And additionally it is not fully working by now. Does someone find errors in the codelines?

Many thanks!



Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15438
    • View Profile
Re: Code improvement
« Reply #1 on: May 02, 2023, 02:38:28 PM »
Hello grab,

Obvious changes that should be made for 2.0 compatibility:

chunk.buildDenseCloud -> chunk.buildPointCloud
source_data=Metashape.DenseCloudData -> source_data=Metashape.PointCloudData
Metashape.PointCloud.Filter -> Metashape.TiePoints.Filter
quality argument should be removed from buildDepthMaps task (quality is controlled by downscale argument)


When exporting raster use the following:
proj = Metashape.OrthoProjection()
proj.crs = projection_crs
then: chunk.exportRaster(projection = proj) #other parameters as you need

For exportModel and exportPointCloud use crs argument:
exportModel(crs = projection_crs)
exportPointCloud(crs = projection_crs)
for exportReport coordinate system shouldn't be specified.


For tie points filtering example, please check the following script:
https://github.com/agisoft-llc/metashape-scripts/blob/master/src/contrib/gradual_selection_tie_points.py
(lines in your code  chunk.filterPoints(Metashape.PointCloud.Filter are incorrect).


Also I have some doubts about copy_points_and_cameras function that you are using. If you need just to duplicate the chunk, you can just call chunk_to = chunk_from.copy().
Best regards,
Alexey Pasumansky,
Agisoft LLC

grab

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Code improvement
« Reply #2 on: May 02, 2023, 06:48:49 PM »
Many thanks Alexey for the comments. I worked those comments into the code.

I made the changes, but still errors occure:
2023-05-02 17:39:35 GPS data for DSC001.JPG: Latitude difference: -4.0657779720731924e-07, Longitude difference: 2.3896670064971204e-07, Altitude difference: -234.96099999999998
2023-05-02 17:39:35 GPS data for DSC002.JPG: Latitude difference: -1.7713330180413323e-07, Longitude difference: -1.631443993233006e-07, Altitude difference: -238.13400000000001
2023-05-02 17:39:35 saved project in 0.342 sec
2023-05-02 17:39:36 Finished processing in 0.347 sec (exit code 1)
2023-05-02 17:39:36 DuplicateChunk: items = (keypoints, depth maps, point cloud, model, DEM, orthomosaic, tiled model)
2023-05-02 17:39:36 Finished processing in 0.037 sec (exit code 1)
2023-05-02 17:39:36 BuildDepthMaps: quality = High, depth filtering = Mild, PM version
2023-05-02 17:39:36 Preparing 0 cameras info...
2023-05-02 17:39:36 GPS data has been updated.
2023-05-02 17:39:36 Finished processing in 0.001 sec (exit code 0)
2023-05-02 17:39:36 DuplicateChunk: items = (keypoints, depth maps, point cloud, model, DEM, orthomosaic, tiled model)
2023-05-02 17:39:36 Finished processing in 0.033 sec (exit code 1)
2023-05-02 17:39:36 DuplicateChunk: items = (keypoints, depth maps, point cloud, model, DEM, orthomosaic, tiled model)
2023-05-02 17:39:36 Error while processing the model: Null tie points
2023-05-02 17:39:36 Error processing model: 'NoneType' object has no attribute 'points'
2023-05-02 17:39:37 Finished processing in 0.034 sec (exit code 1)
2023-05-02 17:39:37 DuplicateChunk: items = (keypoints, depth maps, point cloud, model, DEM, orthomosaic, tiled model)
2023-05-02 17:39:37 Error performing gradual selection1: 'NoneType' object has no attribute 'points'
2023-05-02 17:39:37 Finished processing in 0.032 sec (exit code 1)
2023-05-02 17:39:37 ExportReport: path = XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
2023-05-02 17:39:37 Error performing gradual selection2: 'NoneType' object has no attribute 'points'
2023-05-02 17:39:37 Finished processing in 0.065 sec (exit code 0)
2023-05-02 17:39:37 Error writing statistics: 'NoneType' object has no attribute 'points'
2023-05-02 17:39:37 Error exporting results: Null tie points
2023-05-02 17:39:37 Processing completed successfully.

Somewhere between GPS data update and BuildDepthMaps.
I guess there is a issue with this copy chunks?!?

Would be great if you could again have a look at it. Or somebody who has suggestions to my code.

Many Thanks!

Paulo

  • Hero Member
  • *****
  • Posts: 1500
    • View Profile
Re: Code improvement
« Reply #3 on: May 02, 2023, 08:33:43 PM »
Hi grab,

I would try replacing:
Code: [Select]
        chunk2 = create_chunk(doc, "EPSG::4326")
        copy_points_and_cameras(chunk1, chunk2)

with
Code: [Select]
        chunk2 = chunk1.copy()
same remark in steps 3 and 4...

See if it helps,
Best Regards,
Paul Pelletier,
Surveyor

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15438
    • View Profile
Re: Code improvement
« Reply #4 on: May 02, 2023, 09:25:54 PM »
Hello grab,

There might be some confusion to doc and chunk variables that you are using. For example, in process_photos function the script is creating a new Metashape.Document instance and is saving it under the project name, whereas chunk variable is not connected to saved project anyhow.

If you open the project saved by the script, do you see anything there?
Best regards,
Alexey Pasumansky,
Agisoft LLC

grab

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Code improvement
« Reply #5 on: May 03, 2023, 02:31:19 PM »
Dear Paulo -> Thanks! Now the code looks much smarter and clearer.
Dear Alexey -> Thanks!
Additionally i made some changes for my code.

Again an updated code from my side. But still errors...
I believe it is a copy chunk, a saving or a loading problem.
When i open the agisoft project i have now only two chunks: "Chunk 1" and "Copy of Chunk 1"

Do you have suggestions how to solve this issue?
The rest of the code should work fine :)

Here are the error lines.
2023-05-03 12:53:30 2 images blended in 2.535 sec
2023-05-03 12:53:32 loaded partition in 0.343 sec
2023-05-03 12:53:32 boundaries extracted in 0.022 sec
2023-05-03 12:53:33 1 images blended in 0.831 sec
2023-05-03 12:53:33 orthomosaic updated in 36.331 sec
2023-05-03 12:53:33 Updating orthomosaic...
2023-05-03 12:53:34 orthomosaic updated in 0.461 sec
2023-05-03 12:53:34 Finished processing in 528.392 sec (exit code 1)
2023-05-03 12:53:34 SaveProject: path = XXXXXXXXXXX
2023-05-03 12:53:34 Saving project...
2023-05-03 12:53:34 saved project in 0.169 sec
2023-05-03 12:53:34 Finished processing in 0.175 sec (exit code 1)
2023-05-03 12:53:34 DuplicateChunk: items = (keypoints, depth maps, point cloud, model, DEM, orthomosaic, tiled model)
2023-05-03 12:53:35 Duplicating chunk...
2023-05-03 12:53:35 Error processing model: 'Metashape.PointCloud' object has no attribute 'points'
2023-05-03 12:54:03 Finished processing in 28.943 sec (exit code 1)
2023-05-03 12:54:03 DuplicateChunk: items = (keypoints, depth maps, point cloud, model, DEM, orthomosaic, tiled model)
2023-05-03 12:54:04 Duplicating chunk...
2023-05-03 12:54:04 Error performing gradual selection1: 'Metashape.PointCloud' object has no attribute 'points'
2023-05-03 12:54:32 Finished processing in 28.676 sec (exit code 1)
2023-05-03 12:54:32 DuplicateChunk: items = (keypoints, depth maps, point cloud, model, DEM, orthomosaic, tiled model)
2023-05-03 12:54:32 Duplicating chunk...
2023-05-03 12:54:32 Error performing gradual selection2: 'Metashape.PointCloud' object has no attribute 'points'
2023-05-03 12:55:01 Finished processing in 28.373 sec (exit code 1)
2023-05-03 12:55:01 ExportReport: path = XXXXXXXXXXXXXXXXX
2023-05-03 12:55:01 Generating report...
2023-05-03 12:55:01 Error writing statistics: 'Metashape.PointCloud' object has no attribute 'points'
2023-05-03 12:55:07 Analyzing chunk...
2023-05-03 12:55:08 Found 4 GPUs in 0.004 sec (CUDA: 0.002 sec, OpenCL: 0.002 sec)
2023-05-03 12:55:08 Finished processing in 7.411 sec (exit code 1)
2023-05-03 12:55:08 ExportPointCloud: path = XXXXXXXXXXXXX
2023-05-03 12:55:08 Saving point cloud...
2023-05-03 12:55:08 point cloud size: 114973886 points
2023-05-03 12:56:28 Finished processing in 79.578 sec (exit code 1)
2023-05-03 12:56:28 Error exporting results: Invalid argument name: pixel_size
2023-05-03 12:56:28 Processing completed successfully.
2023-05-03 12:58:50 LoadProject: path = XXXXXXXXXXXXX
2023-05-03 12:58:50 Loading project...
2023-05-03 12:58:51 loaded project in 0.836 sec
2023-05-03 12:58:51 Finished processing in 0.837 sec (exit code 1)