Forum

Author Topic: captureView() return empty Image  (Read 4894 times)

linshuh

  • Newbie
  • *
  • Posts: 7
    • View Profile
captureView() return empty Image
« on: September 29, 2020, 09:58:30 AM »
Hi all,
I wonder why "captureView() return empty Image" happen? If captureView() does not work, what's the other solution I can use, to take screenshot of model in ModelViewSolid mode?
Running "screenshot_meta.py" get error
Quote
image.save('cameratest.png')
RuntimeError: Can't save image: cameratest.png
When I try to open this png image by MacOS Finder, it tells me the file is empty.
The reason why I use captureView() rather than renderImage/reanderPreview() is because I want to render model in "ModelViewSolid" (non-texture) mode.
  • How I run script:
Code: [Select]
$ /Applications/MetashapePro.app/Contents/MacOS/MetashapePro -r screenshot_meta.py
  • screenshot_meta.py
Code: [Select]
def main():
    app = Metashape.app
    app.model_view.model_view_mode = Metashape.Application.ModelView.ModelViewSolid  #<--- change view mode. Don't want default colored model
    doc = app.document
    doc.open('test_screenshot_solid.psz')
    image = Metashape.app.model_view.captureView(width = 300, height = 150, transparent = False, hide_items = True)
    image.save('cameratest.png')

    Thanks advance

    Seboon

    • Jr. Member
    • **
    • Posts: 72
      • View Profile
    Re: captureView() return empty Image
    « Reply #1 on: September 29, 2020, 01:07:18 PM »
    Hello linshuh,

    Try this:
    Code: [Select]
    def main():
        app = Metashape.app
        app.model_view.model_view_mode = Metashape.Application.ModelView.ModelViewSolid  #<--- change view mode. Don't want default colored model
        doc = app.document
        doc.open('test_screenshot_solid.psz')
        image = Metashape.app.model_view.captureView(width = 300, height = 150, transparent = False, hide_items = True)
        cap =  Metashape.Image(image.width, image.height, "RGBA", "U8")
        image.save('cameratest.png')

    See  section "Metashape.Image" in Metashape Python API for more information on the arguments.

    Best regards,
    Sébastien
    S.Poudroux
    Archaeologist - Topographer - Drone remote pilot

    linshuh

    • Newbie
    • *
    • Posts: 7
      • View Profile
    Re: captureView() return empty Image
    « Reply #2 on: September 29, 2020, 07:36:06 PM »
    Hi Seboon,
    Thank you so much for the reply, but I still get the same issue, i.e. Image(cap) is empty.
    My MetashapePro version is 1.6.4
    And when I run this script, I didn't open the Metashape GUI.

    Do you know why that happen?

    Thanks Advance

    Alexey Pasumansky

    • Agisoft Technical Support
    • Hero Member
    • *****
    • Posts: 15464
      • View Profile
    Re: captureView() return empty Image
    « Reply #3 on: September 29, 2020, 10:16:40 PM »
    Hello linshuh,

    When you do not use application GUI the Model View is not created. Also Metashape.app.document will return None, as it is related to the currently opened project in GUI mode.

    Best regards,
    Alexey Pasumansky,
    Agisoft LLC