Hi all
I'm looking for help , I have a probleme to set a region in my project from fixed points A to B, I have a text file with coordinates X,Y like this:
{
"Y": "131524.72623558177",
"X": "600237.012492972"
},
{
"Y": "131520.4597589273",
"X": "600236.8305144551"
},
{
"Y": "131516.19328227278",
"X": "600236.6485359382"
},
{
"Y": "131511.9268056183",
"X": "600236.4665574214"
}
What I'm looking for is to set a region box from 1st coordinates to 2nd (define by zone im my project to get the smallest parts) and do some stuff with , after get a 2nd region, from 2nd coordinates to 3rd (do some stuff with)etc etc
How to do it with python ?? to set my region ?? There is a lot infos over here
http://www.agisoft.com/forum/index.php?topic=1886.15 or
http://www.agisoft.com/forum/index.php?topic=2488.0 But I can't figured it out since few hours now , how can I fix it
I've tried that but doesn't work at all ....
mySize = 4
#select the project
doc = PhotoScan.app.document
# Define: Map region
# MapRegionVec = [CenterX, CenterY, SizeX0, SizeY0, ZRotationDeg]
MapRegionVec = [coord_x, coord_y, mySize, mySize, 0.0]
#get the current chunk
chunk = doc.chunk
#create new region
newregion = PhotoScan.Region()
# Set region size
newregion.size = PhotoScan.Vector([MapRegionVec[2], MapRegionVec[3], chunk.region.size[2]])
# Set region rotation
# build rotation matrix in our coordinate system
RotZDeg = -MapRegionVec[4]
SinRotZ = math.sin(math.radians(RotZDeg))
CosRotZ = math.cos(math.radians(RotZDeg))
RotMat = PhotoScan.Matrix([[CosRotZ, -SinRotZ, 0, 0], [SinRotZ, CosRotZ, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]])
# Rotate region bounding box
T = chunk.transform.matrix
v = PhotoScan.Vector([0, 0, 0, 1])
v_t = T * v
v_t.size = 3
m = chunk.crs.localframe(v_t)
m = m * T
m = RotMat * m
s = math.sqrt(m[0, 0] ** 2 + m[0, 1] ** 2 + m[0, 2] ** 2) # scale factor
R = PhotoScan.Matrix([[m[0, 0], m[0, 1], m[0, 2]], [m[1, 0], m[1, 1], m[1, 2]], [m[2, 0], m[2, 1], m[2, 2]]])
R = R * (1. / s)
newregion.rot = R.t()
# Put newregion to chunk
chunk.region = newregion
I've tried to pout my region center to one of my markers points and thats works , but did we can define a region possition between 2 points as I asked at the beginning of my post
# Define: Region [CenterX, CenterY, CenterZ, SizeX, SizeY, ZRotationDeg]
MapRegionVec = [600225.8792,131360.0026,67.30138399999889, 173.8, 143.6, -25.0]
# Set region center:
newregion = PhotoScan.Region()
centerUTM = PhotoScan.Vector([MapRegionVec[0], MapRegionVec[1], MapRegionVec[2]])
centerGEO = chunk.crs.unproject(centerUTM)
centerLocal = chunk.crs.localframe(centerGEO)
#newregion.center = PhotoScan.Vector([0,0,0])
newregion.size = PhotoScan.Vector([150,150,90])
chunk.region = newregion
#newregion.size = PhotoScan.Vector([MapRegionVec[3], MapRegionVec[4], chunk.region.size[2]])
# Set region rotation
import math
SinRotZ= math.sin(math.radians(MapRegionVec[5]))
CosRotZ= math.cos(math.radians(MapRegionVec[5]))
newregion.rot = PhotoScan.Matrix( [[SinRotZ,-CosRotZ,0], [CosRotZ,SinRotZ,0], [0,0,1]] )
# put newregion to chunk
chunk.region = newregion