Agisoft Metashape

Agisoft Metashape => Python and Java API => Topic started by: masayuki on November 12, 2021, 03:55:09 PM

Title: Save Images with Markers
Post by: masayuki on November 12, 2021, 03:55:09 PM
Before taking multiple images and camera alignment (will take much time),
I would like to simply check whether or not markers can be detected in a single image.

I run my python script in headless mode.
My script has the following procedure.

1. Read a single image that contain coded target markers.
2. Detect the markers.
   (coded-target can be detected even before camera alignment)
3. Save the image in which the markers are drawn.

I have completed step 2, but I don't know how to get the image data with the marker (flag) drawn on it.
Is it possible to obtain a 2D image with markers as displayed in Metashape's GUI?
Title: Re: Save Images with Markers
Post by: wojtek on November 13, 2021, 03:26:14 PM
You could use PIL library to insert a graphic where your marker coordinates are and save it as a copy. It's a fairly simple library to work with.
Title: Re: Save Images with Markers
Post by: masayuki on November 14, 2021, 06:04:32 PM
@wojtek
Thanks for your reply.
I found the following page and gave it a try.
https://agisoft.freshdesk.com/support/solutions/articles/31000136860-how-to-install-external-python-module-to-photoscan-professional-pacakge

The marker position(x[pix], y[pix]) on the image could be obtained in the following way.

Code: [Select]
for marker in chunk.markers:
    for cam, proj in marker.projections.items():
        target_pos = (proj.coord.x), proj.coord.y)

I'm more familiar with OpenCV, I used "cv2.drawMarker" to draw the markers.
This Q&A has been resolved.