Agisoft Metashape

Agisoft Metashape => Python and Java API => Topic started by: wangyanru on January 22, 2019, 06:02:18 PM

Title: export Render photos
Post by: wangyanru on January 22, 2019, 06:02:18 PM
In new version photoscan v1.4,we can export the rendered photos in the UI ,export->render photos,and there also need some manual operations to chose suitable projection plane,and the render results seems like rectified images based on source images .   so is there any method to get  render photos from specific views by python scripts? I have tried the examples like this:

Code: [Select]
import PhotoScan
import os

# Checking compatibility
compatible_major_version = "1.4"
found_major_version = ".".join(PhotoScan.app.version.split('.')[:2])
if found_major_version != compatible_major_version:
    raise Exception("Incompatible PhotoScan version: {} != {}".format(found_major_version, compatible_major_version))


def get_cameras(chunk):
    selected_cameras = [camera for camera in chunk.cameras[0:32] if camera.transform and camera.selected]

    if len(selected_cameras) > 0:
        return selected_cameras
    else:
        return [camera for camera in chunk.cameras if camera.transform]


def render_cameras():
    print("Script started...")

    chunk = PhotoScan.app.document.chunks[0]
    #chunk2 = PhotoScan.app.document.chunks[1]
    if not chunk.model:
        raise Exception("No model!")

    for camera in get_cameras(chunk):
        render = chunk.model.renderImage(camera.transform, camera.sensor.calibration)

        photo_dir = os.path.dirname(camera.photo.path)
        photo_filename = os.path.basename(camera.photo.path)
        render_filename = os.path.splitext(photo_filename)[0] + "_render.jpg"

        render.save(os.path.join(photo_dir, render_filename))

    print("Script finished!")


label = "Custom menu/Render photos for cameras"
PhotoScan.app.addMenuItem(label, render_cameras)
print("To execute this script press {}".format(label))


but the results is not as expected as exported results from UI (render photos)   ,   can anyone explain and give some tips?
Title: Re: export Render photos
Post by: Alexey Pasumansky on January 22, 2019, 06:39:24 PM
Hello wangyanru,

Which task you are trying to solve by this approach? Do you need just to create an image (a kind of photo) of the reconstructed model from the artificial camera location?
Title: Re: export Render photos
Post by: wangyanru on January 23, 2019, 05:27:32 PM
Thanks for your fast reply!
yes, we want to get images of reconstructed model from artificial locations which are on a regular arc (while it is a line in default UI render photos option )

I have computed out the locations,and rendered photos using examples mentioned above ,here is the result,it is much more blurred than the export render photo in UI(the second image),

the manually exported render photos seem like just rectified from source images,is there any api to change the default artificial location?I haven't found yet.
Title: Re: export Render photos
Post by: Alexey Pasumansky on February 28, 2019, 04:28:49 PM
Hello wangyanru,

Render Photos GUI option behaves differently from renderImage() function from Python API. The first one is intended to adjust the orientation of the cameras or generation of the intermediate camera locations basing on the current alignment. The application of such method is mostly related to the lenticular images generation.
While the renderImage() call is rendering the textured polygonal model, as it appears in the Model view, according to the input EO/IO parameters for the "virtual" camera.