Hi Flyzq,
you can look at shapely.geometry and import Polygon as
from shapely.geometry import Polygon
chunk = Metashape.app.document.chunk
T = chunk.transform.matrix
crs = chunk.shapes.crs
given a shape then populate vertices with shape internal vertex coordinates as
vertices = [(T.inv().mulp(crs.unproject(vertex))) for vertex in shape.vertices] # vertices in internal coordinates
for a given camera then the polygon p with the shape projected image coordinates will be defined by:
image_ver = list() # image shape vertices
w = camera.sensor.width
h = camera.sensor.height
frame = Polygon([(0,0),(w,0),(w,h),(0,h)])
num_ver = 0
for vertex in vertices:
num_ver += 1
if not camera.project(vertex):
continue
x = round(camera.project(vertex).x,3)
y = round(camera.project(vertex).y,3)
if num_ver < len(vertices) :
image_ver.append((x,y))
p = Polygon(image_ver)
print(camera.label,p.intersection(frame))
Note that we use intersection of polygon p with image frame to only get shape within frame. Result will be something like attached screen copy....
I think this could get you started