Since I am doing image processing for drones in my master's research, is it a 3D construction software called Metashape (formerly Photoscan)? I am using. Originally, image processing was performed on individual images, and it became necessary to obtain the location information of the detected crops. I used to create a mosaic image from individual images in advance, but is it possible to obtain 3D coordinates by finding the points that match the points found in the individual images and the mosaic image? I proceeded based on the hypothesis.
Metashape has a Python API, and functions that are not implemented in software can be executed by writing code in Python. However, there are few people who use Metashape or Python API, so even if you search in Japanese, there is not much information.
For example, the blog of the aerial survey laboratory at Yamaguchi University contains information about Metashape, which can be said to be the only one in Japanese. Metashape Python API Note
Perhaps the rest will be information gathering in English. In the Metashape official API explanation, there is a manual of nearly 200 pages, and you will write the code while referring to this.
Metashape Python Reference Release 1.6.0
However, this manual is quite simplified and lacks information to solve the problem at hand. It's unfriendly. Instead, knowledge is accumulated in the question corner called Agisoft forum, which is very helpful.
https://www.agisoft.com/forum/index.php
While referring to the above sites, we will make trial and error.
To summarize what I tried to do, ** Coordinates in the image before mosaic: [x, y] ** From ** 3D coordinates: [X, Y, Z] ** Want to get! about it. It was realized by referring to the following article.
How to add marker using camera's coordinates.
script.py
import Metashape
doc = Metashape.app.document
chunk = doc.chunk
camera = chunk.cameras[N]
surface = chunk.model
point = surface.pickPoint(camera.center, camera.transform.mulp(camera.sensor.calibration.unproject(Metashape.Vector([x,y]))))
marker = chunk.addMarker(point)
marker_coord = chunk.crs.project(chunk.transform.matrix.mulp(marker.position))
1st to 4th lines: Import Metashape and specify one image before mosaicking. 5th to 6th lines: Converted by multiplying the point [x, y] on the image coordinate system by an image-specific transformation matrix (created by mosaicking). Lines 7-8: Place a marker corresponding to point in chunk and convert this point to an absolute coordinate system.
Perhaps the hardest part is transforming the coordinate system. ** Image coordinate system →? ?? Coordinate system → Absolute coordinate system ** Is being converted to.
In any case, I was able to get the 3D coordinates corresponding to a specific point in the individual image. If you say "Import csv, run the conversion in a for loop, and then output the result in csv", it looks good. (vocabulary)
To use the Metashape Python API, you need to refer to the Python API reference while gathering information on the Agisoft forum. I hope it helps! Thank you ~
Recommended Posts