12
« on: April 13, 2015, 08:20:46 PM »
I'm still having trouble with this. Here's my code right now:
import sys
import operator
import os
import PhotoScan
import math
label = "My Test"
cameraPath = "C:\\Test Shots\\myCameras.xml" #C:\\agi_temp"
workingPath = os.path.dirname(os.path.realpath(__file__)) + "\\" #updates to whereever this file is placed.
doc = PhotoScan.app.document
chunk = PhotoScan.Chunk()
chunk.label = label
doc.addChunk(chunk)
files = os.listdir(workingPath)
file_list=[]
for file in files:
if file.endswith("JPG"):
filePath = workingPath + file
file_list.append(filePath)
chunk.addPhotos(file_list)
chunk.importCameras(cameraPath)
# chunk.matchPhotos(accuracy=PhotoScan.HighAccuracy, preselection=PhotoScan.Preselection.NoPreselection, filter_mask=False, keypoint_limit=40000, tiepoint_limit=1000)
chunk.matchPhotos()
chunk.detectMarkers(PhotoScan.TargetType.CircularTarget12bit, 20)
sb = chunk.addScalebar(chunk.markers[7],chunk.markers[8])
sb.reference.distance = .11
chunk.markers[7].reference.location = PhotoScan.Vector((-0.002399,-0.050127,0.000000))
chunk.markers[1].reference.location = PhotoScan.Vector((-0.047861,0.034190,0.000000))
chunk.markers[10].reference.location = PhotoScan.Vector((0.056992,0.001284,0.000000))
# region selection
reg = chunk.region
print(reg.size, reg.center)
if not chunk.transform:
print("no transform")
trans = PhotoScan.Matrix().diag([1,1,1,1])
else:
print("has transform")
trans = chunk.transform
print("trans ", trans)
#<---- Rotation ---->
rot_untransformed = PhotoScan.Matrix().diag([1,1,1,1])
print("rot_untransformed ", rot_untransformed)
rot_temp = trans.matrix * rot_untransformed
s = math.sqrt(rot_temp[0, 0]**2 + rot_temp[0, 1]**2 + rot_temp[0, 2]**2)
R = PhotoScan.Matrix( [[rot_temp[0,0],rot_temp[0,1],rot_temp[0,2]], [rot_temp[1,0],rot_temp[1,1],rot_temp[1,2]], [rot_temp[2,0],rot_temp[2,1],rot_temp[2,2]]])
R = R * (1.0 / s)
#<---- Size ---->
inter_size = PhotoScan.Vector([0, 0, 0])
geo_size = PhotoScan.Vector([.2, .2, .3])
inter_size = geo_size / s
#<---- Center ---->
geo_cen = PhotoScan.Vector([0, 0, 0.1])
inter_cen = trans.matrix.inv().mulp(geo_cen)
reg = PhotoScan.Region()
reg.rot = R.t()
reg.size = inter_size
reg.center = inter_cen
chunk.region = reg
chunk.buildDenseCloud(quality=PhotoScan.HighQuality,filter = PhotoScan.AggressiveFiltering) # quality=PhotoScan.HighQuality
chunk.buildModel(surface=PhotoScan.Arbitrary, interpolation=PhotoScan.DisabledInterpolation,face_count=PhotoScan.MediumFaceCount) # face_count=PhotoScan.MediumFaceCount) # interpolation=PhotoScan.EnabledInterpolation
chunk.smoothModel(passes=2)
chunk.buildUV(mapping=PhotoScan.GenericMapping)
chunk.buildTexture(blending=PhotoScan.MosaicBlending, size=2048) # size=4096)
doc.save(workingPath + label + ".psz")
chunk.exportModel(workingPath + label + ".obj",binary=True,texture_format='jpg',normals=True,colors=False,cameras=False, format='obj')
What's odd is that it doesn't build any of the model I'm looking for, but it does get decent model of the area around it (the flat surface it's sitting on). The "myCameras.xml" is actually an export from the same exact scan that was aligned using the gui and exported manually. When I run through the steps manually in the software it works but never via the script.
Thoughts?