Forum

Author Topic: split_in_chunks: Zero Resolution Error (v1.5)  (Read 6946 times)

Silent_T

  • Newbie
  • *
  • Posts: 4
    • View Profile
split_in_chunks: Zero Resolution Error (v1.5)
« on: January 17, 2019, 08:54:17 PM »
Hello,
I have received a Zero Resolution error when running the Split In Chunks script to create a dense point cloud. I am using the latest script copied from https://github.com/agisoft-llc/metashape-scripts/blob/master/src/split_in_chunks_dialog.py

I am aware of what the Zero Resolution error means from other posts https://www.agisoft.com/forum/index.php?topic=5109.msg44587#msg44587, and I understand that there are no, or not enough points in the chunk I am processing to create the dense point cloud. See attached screenshot of the 4x4 split that I am processing, the bounding box shown (i.e. 1-4) is the one that stops processing.

However, in the past (before v1.5.0) I have run the script with no problems on chunks with few or no points available to create a dense cloud, similar to this current scenario. The script simply skipped over those chunks with not enough points and didn't create a dense cloud, but continued on processing the other chunks.

In Metashape v1.5 I am getting a Zero Resolution error when the script encounters a chunk with few or no points. Error follows (I have replaced the file location with <FileDir> for brevity):

Quote
File "<FileDir>, line 152, in <lambda>

proc_split = lambda: self.splitChunks()

File "<FileDir", line 286, in splitChunks

new_chunk.buildDenseCloud(max_neighbors=100)  # keep_depth=False

Exception: Zero resolution


I have tried to continue processing from this point using the additional code found in this thread (also pasted below), thinking I could skip it manually with this method: https://www.agisoft.com/forum/index.php?topic=10024.0
Code: [Select]
chunk_labels = [ichunk.label for ichunk in PhotoScan.app.document.chunks]
if  "Chunk " + str(i) + "_" + str(j) in chunk.labels:
    continue

Per the previous threads instructions, I added the above additional code on line 239 (i.e in between the following lines):
Code: [Select]
for i in range(1, partsX + 1):
                if not buildDense:
I Updated "PhotoScan" to "Metashape" and received the following error:
Quote
File "<FileDir>", line 152, in <lambda>

proc_split = lambda: self.splitChunks()

File "<FileDir>", line 240, in splitChunks

chunk_labels = [ichunk.label for ichunk in Metashape.app.document.chunks]

AttributeError: 'Metashape.Chunk' object has no attribute 'labels'

In this case, understand that 'labels' needs to be defined for 'Metashape.Chunk', but I have tried editing the script with my limited coding ability to no success. I can't seem to find a solution to move forward.

Any thoughts on how to get the script to skip chunks with few or no points? Or, as a workaround, how to get the additional script to allow continued processing from what has already been processed? Thanks in advance for any assistance provided.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: split_in_chunks: Zero Resolution Error (v1.5)
« Reply #1 on: January 17, 2019, 09:18:34 PM »
Hello Silent_T,

There seem to be a typo in the code for continuing the job:
Code: [Select]
chunk_labels = [ichunk.label for ichunk in PhotoScan.app.document.chunks]
if  "Chunk " + str(i) + "_" + str(j) in chunk_labels:
    continue
Should be chunk_labels in the second line, not "chunk.labels". I have also corrected it in the original post in another thread.
Best regards,
Alexey Pasumansky,
Agisoft LLC

LDBL

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: split_in_chunks: Zero Resolution Error (v1.5)
« Reply #2 on: January 17, 2019, 09:22:42 PM »
Apologies for jumping on your thread but I've experienced the same with a different line of code.

Although not entirely the same, I also received zero resolution in v1.5 when python scripting hit

Code: [Select]
chunk.alignCameras()
As above, python script works in previous versions. Also changing python script from
Code: [Select]
PhotoScan. to
Code: [Select]
Metashape. has no bearing on success or failure of script to run...just seems to hit a wall and zero resolution.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: split_in_chunks: Zero Resolution Error (v1.5)
« Reply #3 on: January 17, 2019, 09:36:38 PM »
In order to skip "zero resolution" chunks for the dense cloud generation, you can use try-except approach:


Code: [Select]
try:
   chunk.buildDenseCloud()
except Exception as exc:
    print("Something wrong for chunk ", chunk.label, ". Skipped error: ",exc)
Best regards,
Alexey Pasumansky,
Agisoft LLC

LDBL

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: split_in_chunks: Zero Resolution Error (v1.5)
« Reply #4 on: January 17, 2019, 09:49:40 PM »
In order to skip "zero resolution" chunks for the dense cloud generation, you can use try-except approach:


Code: [Select]
try:
   chunk.buildDenseCloud()
except Exception as exc:
    print("Something wrong for chunk ", chunk.label, ". Skipped error: ",exc)

Thanks Alexey, will try this.

Silent_T

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: split_in_chunks: Zero Resolution Error (v1.5)
« Reply #5 on: January 17, 2019, 11:49:11 PM »
Hello Alexey,
Thank you for the suggestions. I have tried to implement the exception with limited results. I think I need clarification on where exactly to integrate the code.

I'm assuming your code is meant to replace lines 275-279 and/or 283-288 (shown in the attached screenshot). I have tried doing so in both locations together and separate.

The reason I say I have had limited success is because the result is the creation of all of the split chunks (16 in my case, 4x4), they are just empty (i.e. no dense cloud). I can use these in the batch processing tool like normal, so that is a possibility, albeit not an ideal solution. However, the Build Dense Cloud option within the script no longer works as it is just bypassed. While I do now have a workaround, I'm just curious if I can get this working smoothly...

Can you please clarify what lines you think I should be replacing or inserting and where??
Thank you!

Options I have tried:
1: replacing the statement in after "else"
Code: [Select]
if buildDense:
                    if new_chunk.depth_maps:
                        reuse_depth = True
                        if new_chunk.depth_maps.meta['depth/depth_downscale']:
                            quality = QUALITY[new_chunk.depth_maps.meta['depth/depth_downscale']]
                        if new_chunk.depth_maps.meta['depth/depth_filter_mode']:
                            filtering = FILTERING[new_chunk.depth_maps.meta['depth/depth_filter_mode']]
                        try:
                            new_chunk.buildDepthMaps(quality=quality, filter=filtering, reuse_depth=reuse_depth)
                            new_chunk.buildDenseCloud(max_neighbors=100)  # keep_depth=False
                        except RuntimeError:
                            print("Can't build dense cloud for " + chunk.label)

                    else:
                        reuse_depth = False
                        try:
                            chunk.buildDenseCloud()
                        except Exception as exc:
                            print("Something wrong for chunk ", chunk.label, ". Skipped error: ",exc)


2 replacing the first "try" statement
Code: [Select]
if buildDense:
                    if new_chunk.depth_maps:
                        reuse_depth = True
                        if new_chunk.depth_maps.meta['depth/depth_downscale']:
                            quality = QUALITY[new_chunk.depth_maps.meta['depth/depth_downscale']]
                        if new_chunk.depth_maps.meta['depth/depth_filter_mode']:
                            filtering = FILTERING[new_chunk.depth_maps.meta['depth/depth_filter_mode']]
                        try:
                            chunk.buildDenseCloud()
                        except Exception as exc:
                            print("Something wrong for chunk ", chunk.label, ". Skipped error: ",exc)

                    else:
                        reuse_depth = False
                        try:
                            new_chunk.buildDepthMaps(quality=quality,
                                                     filter=Metashape.FilterMode.AggressiveFiltering, reuse_depth=reuse_depth)
                            new_chunk.buildDenseCloud(max_neighbors=100)  # keep_depth=False
                        except RuntimeError:
                            print("Can't build dense cloud for " + chunk.label)

3 replacing both "try" statements
Code: [Select]
if buildDense:
                    if new_chunk.depth_maps:
                        reuse_depth = True
                        if new_chunk.depth_maps.meta['depth/depth_downscale']:
                            quality = QUALITY[new_chunk.depth_maps.meta['depth/depth_downscale']]
                        if new_chunk.depth_maps.meta['depth/depth_filter_mode']:
                            filtering = FILTERING[new_chunk.depth_maps.meta['depth/depth_filter_mode']]
                        try:
                            chunk.buildDenseCloud()
                        except Exception as exc:
                            print("Something wrong for chunk ", chunk.label, ". Skipped error: ",exc)

                    else:
                        reuse_depth = False
                        try:
                            chunk.buildDenseCloud()
                        except Exception as exc:
                            print("Something wrong for chunk ", chunk.label, ". Skipped error: ",exc)

godszerg

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: split_in_chunks: Zero Resolution Error (v1.5)
« Reply #6 on: March 06, 2019, 07:55:09 PM »
Does anyone solve this Zero resolution problem after splitting in chunks?

Silent_T

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: split_in_chunks: Zero Resolution Error (v1.5)
« Reply #7 on: March 06, 2019, 08:14:29 PM »
Replying to:
Does anyone solve this Zero resolution problem after splitting in chunks?

Using Alexey's suggestions I was able to split the project into chunks, just without doing any processing (Dense Cloud or Mesh creation) using the "split in chunks" dialog. I was able to then build the dense cloud and mesh on all the chunks using the batch processing feature. quote below:
...
The reason I say I have had limited success is because the result is the creation of all of the split chunks (16 in my case, 4x4), they are just empty (i.e. no dense cloud). I can use these in the batch processing tool like normal, so that is a possibility, albeit not an ideal solution. However, the Build Dense Cloud option within the script no longer works as it is just bypassed. While I do now have a workaround, I'm just curious if I can get this working smoothly...
...

So, this process works, but I have not checked for any script updates that might fix the script, nor have I run it since my previous post. 

harmbrar

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: split_in_chunks: Zero Resolution Error (v1.5)
« Reply #8 on: June 24, 2019, 06:47:03 PM »
Hi there,

I'm also running in to this issue when I am trying to build the dense point could, I added the exception in split_in_chunks code and it works no matter how much I am splitting. But now when I am also building a mesh I am getting either a "null image" or "empty surface" error, when I try to skip those I get a incomplete/distorted model.
I am guessing it is happening because I am skipping chunks when making the dense cloud? Is there a solution to get a model even though we are skipping chunks?

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: split_in_chunks: Zero Resolution Error (v1.5)
« Reply #9 on: June 24, 2019, 07:50:03 PM »
Hello harmbrar,

Can you post the code block that you are using to build the dense cloud and mesh in the certain chunk-duplicate?
Best regards,
Alexey Pasumansky,
Agisoft LLC

harmbrar

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: split_in_chunks: Zero Resolution Error (v1.5)
« Reply #10 on: June 24, 2019, 08:07:35 PM »
I am using the script from: https://github.com/agisoft-llc/metashape-scripts/blob/master/src/split_in_chunks_dialog.py

Below is the modified bit of the code. I just added a try exception for the build dense cloud and changed the build model expect from run time to exception so the "null image" and "empty surface" errors are skipped.

What I am trying to do is split in to many chunks (5x5) and produce a model.

Code: [Select]
if buildDense:
                    if new_chunk.depth_maps:
                        reuse_depth = True
                        if new_chunk.depth_maps.meta['depth/depth_downscale']:
                            quality = QUALITY[new_chunk.depth_maps.meta['depth/depth_downscale']]
                        if new_chunk.depth_maps.meta['depth/depth_filter_mode']:
                            filtering = FILTERING[new_chunk.depth_maps.meta['depth/depth_filter_mode']]
                        try:
                            new_chunk.buildDepthMaps(quality=quality, filter=filtering, reuse_depth=reuse_depth)
                            new_chunk.buildDenseCloud(max_neighbors=100)  # keep_depth=False
                        except Exception:
                            print("Can't build dense cloud for " + chunk.label)

                    else:
                        reuse_depth = False
                        try:
                            new_chunk.buildDepthMaps(quality=quality,
                                                     filter=Metashape.FilterMode.AggressiveFiltering, reuse_depth=reuse_depth)
                            try:
                                new_chunk.buildDenseCloud(max_neighbors=100)
                            except Exception:
                                print("Can't build dense cloud for " + chunk.label)  # keep_depth=False
                        except RuntimeError:
                            print("Can't build dense cloud for " + chunk.label)

                    if autosave:
                        doc.save()

                if buildMesh:
                    if new_chunk.dense_cloud:
                        try:
                            new_chunk.buildModel(surface=mesh_mode,
                                                 source=Metashape.DataSource.DenseCloudData,
                                                 interpolation=Metashape.Interpolation.EnabledInterpolation,
                                                 face_count=Metashape.FaceCount.HighFaceCount)
                        except Exception:
                            print("Can't build mesh for " + chunk.label)
                    else:
                        try:
                            new_chunk.buildModel(surface=mesh_mode,
                                                 source=Metashape.DataSource.PointCloudData,
                                                 interpolation=Metashape.Interpolation.EnabledInterpolation,
                                                 face_count=Metashape.FaceCount.HighFaceCount)
                        except Exception:
                            print("Can't build mesh for " + chunk.label)
« Last Edit: June 24, 2019, 08:11:28 PM by harmbrar »

harmbrar

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: split_in_chunks: Zero Resolution Error (v1.5)
« Reply #11 on: June 25, 2019, 10:54:46 PM »
Idk if this information may help find a solution but.
When I build dense cloud and mesh, With the buildDenseCloud wrapped in a try-except to skip zero resolution chunks. I get a "Null Image" error.
Code: [Select]
try:
                 new_chunk.buildModel(surface=mesh_mode,
                                             source=Metashape.DataSource.PointCloudData,
                                             interpolation=Metashape.Interpolation.EnabledInterpolation,
                                             face_count=Metashape.FaceCount.HighFaceCount)
                  except RuntimeError:
                       print("Can't build mesh for " + chunk.label)

The above code is run when
Code: [Select]
if new_chunk.dense_cloudis false

It errors on this line:
Code: [Select]
face_count=Metashape.FaceCount.HighFaceCount

christian.thau

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: split_in_chunks: Zero Resolution Error (v1.5)
« Reply #12 on: May 04, 2021, 05:09:09 PM »
Hi Alexey,

I'd like to bring this topic up again. Could you please elaborate on the try-except approach? Where/how exactly do we have to incorporate this piece of code in the split_in_chunks script in order to get this to work? I am sure this would be of great help to many of us here in this forum.

Thanks in advance,
Christian


In order to skip "zero resolution" chunks for the dense cloud generation, you can use try-except approach:


Code: [Select]
try:
   chunk.buildDenseCloud()
except Exception as exc:
    print("Something wrong for chunk ", chunk.label, ". Skipped error: ",exc)

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: split_in_chunks: Zero Resolution Error (v1.5)
« Reply #13 on: May 04, 2021, 06:17:56 PM »
Hello Christian,

Do you use the latest script version in Metashape 1.7?

The code sample is assumed to substitute chunk.buildDenseCloud() line. It will return the custom message to the Console pane without stopping the script.
Similar checks can be added for other workflow operations, that require some base data which can be missing in the project.
Best regards,
Alexey Pasumansky,
Agisoft LLC

christian.thau

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: split_in_chunks: Zero Resolution Error (v1.5)
« Reply #14 on: May 06, 2021, 11:13:56 AM »
Hi Alexey,

thanks for you quick reply. Yes, I am using the latest GitHub script in Metashape version 1.7.2. I will try your suggestion and see if this works.

Cheers,
Christian