I export the depth from the GUI and I get the resolution of the image the same as RGB image and good result as show in the figure 1. However, I want to try the python to export the depth to obtain the result as the GUI. But, the result from the python is not the same as in in the GUI, as shown in the figure 2. Therefore, How can I solve this problem in python code. I will shows you the code in this post.
import Metashape
import numpy
from PySide2 import QtWidgets
def save_depth_maps():
chunk = Metashape.app.document.chunk #active chunk
#app = QtWidgets.QApplication.instance()
if not chunk.depth_maps:
message = "No depth maps in the active chunk. Script Aborted."
print(message)
Metashape.app.messageBox(message)
return 0
print("Script started...")
#app.processEvents() # this is the click even when we create the menu bar
if chunk.transform.scale:
scale = chunk.transform.scale
else:
scale = 1
count = 0
camera_list = list()
for camera in chunk.cameras:
camera_list.append(camera)
depth = chunk.depth_maps[camera_list[4]].image()
img = depth * 1
img.save('C:/Users/DepthMapGeneration/Depth/test7.jpg')
message = "Script finished "
print(message)
#print("Depth maps exported to:\n " + output_folder)
Metashape.app.messageBox(message)
return 1
#Metashape.app.addMenuItem("Custom menu/Save Depth Maps", save_depth_maps)
if __name__ == "__main__":
save_depth_maps()