Forum

Author Topic: About Set Map Region python  (Read 4514 times)

ppkong

  • Jr. Member
  • **
  • Posts: 54
    • View Profile
About Set Map Region python
« on: November 20, 2014, 10:30:25 AM »
I used 1000 UAV images generation model, and the image without distortion correction.Align photo has finished.
I use Python script 1.1 for set map region.But the position is always wrong.
Code: [Select]
# Define: Region [Name,CenterX, CenterY, SizeX, SizeY]
                    MapRegionVec = [C_4,744300,3074400, 300, 300]
                    newregion = PhotoScan.Region()
                    chunk.resetRegion()
    #rotate
                    T = chunk.transform.matrix
                    v = PhotoScan.Vector( [0,0,0,1] )
                    v_t = T * v
                    v_t.size = 3
                    if chunk.crs:
                        m = chunk.crs.localframe(v_t)
                    else:
                        m=PhotoScan.Matrix().diag([1,1,1,1])
                    m = m * T
                    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()
    #set grid center:
    #define float
                    C1=float(MapRegionVec[1])
                    C2=float(MapRegionVec[2])
                    C3=float(MapRegionVec[3])
                    C4=float(MapRegionVec[4])
                    centerUTM = PhotoScan.Vector([C1,C2,0])
                    centerGEO=chunk.crs.unproject(centerUTM)
                    print ("centerGEO:",centerGEO)
                    centerGEO.size = 4
                    centerGEO.w = 1
                    centerLocal = chunk.transform.matrix.inv() * centerGEO
                    centerLocal.size = 3
                    print ("centerUTM=",centerUTM,"centerLocal=",centerLocal)
    #define newcenter
                    newregion.center = PhotoScan.Vector([centerLocal[0], centerLocal[1], chunk.region.center[2]])
                    print ("newregion.center:",newregion.center)
 #define newsize
.......
                     newregion.size = PhotoScan.Vector([xsize,ysize,chunk.region.size[2]])
                     chunk.region = newregion
I don't know what is my code error or 1.1 script error,But I'd use this script is run on the UC camera images have no problem.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: About Set Map Region python
« Reply #1 on: November 20, 2014, 10:05:22 PM »
Hello ppkong,

Do you have problem only with the region center height or with all three coordinates?
Best regards,
Alexey Pasumansky,
Agisoft LLC

ppkong

  • Jr. Member
  • **
  • Posts: 54
    • View Profile
Re: About Set Map Region python
« Reply #2 on: November 21, 2014, 01:01:27 AM »
my problem is the region center.I want set Z coordinate of the newregion.center with chunk.region.center.But the newregion seems lower than the orgin Z coordinate of the chunk.I print this two values but they are equal.

ppkong

  • Jr. Member
  • **
  • Posts: 54
    • View Profile
Re: About Set Map Region python
« Reply #3 on: November 21, 2014, 04:05:36 AM »
As shown in the following image that I think about parameters of region , I don't know if my understanding is correct?