Forum

Author Topic: Import Cameras/Build Points?  (Read 14327 times)

gchaprnka

  • Newbie
  • *
  • Posts: 14
    • View Profile
Import Cameras/Build Points?
« on: April 04, 2015, 01:12:01 AM »
I'm trying to automate the processing of data from a small camera array, and take advantage of the import cameras feature. heres the code I'm using:

Code: [Select]
import sys
import operator
import os
import PhotoScan
import math

label = "Scan 010"
workingPath = "C:\\Test Shots\\Scan 010" + "\\"
cameraPath = "C:\\Test Shots\\cameras.xml"

doc = PhotoScan.app.document
chunk = PhotoScan.Chunk()
chunk.label = label #"My Chunk"
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.buildPoints()

and it goes on to do the processing. I previously had it working with:
Code: [Select]
chunk.detectMarkers()
chunk.matchPhotos(accuracy=PhotoScan.MediumAccuracy, preselection=PhotoScan.Preselection.NoPreselection)
chunk.alignCameras()

It doesn't seem that the BuildPoints step is happening. If I stop the script at that point, I have aligned cameras but no points. Did the syntax change in the latest version? (I updated today to 1.1.4 build 2021(64bit))

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15438
    • View Profile
Re: Import Cameras/Build Points?
« Reply #1 on: April 04, 2015, 01:29:55 AM »
Hello gchaprnka,

You still need to .matchPhotos() after cameras import and prior to building the sparse cloud.
Best regards,
Alexey Pasumansky,
Agisoft LLC

gchaprnka

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Import Cameras/Build Points?
« Reply #2 on: April 06, 2015, 10:31:54 PM »
I see. Is there a reason this is so different than using the GUI? If I understand correctly the process in the GUI is:
1)make new chunk
2)add photos
3)import cameras
4)build point cloud
5+)build dense cloud/model, etc.

but in python:
1)make new chunk
2)add photos
3)import cameras
4)match photos
5)build point cloud
6+)dense clould, etc.

gchaprnka

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Import Cameras/Build Points?
« Reply #3 on: April 13, 2015, 08:20:46 PM »
I'm still having trouble with this. Here's my code right now:
Code: [Select]
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?

SamC-E

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Import Cameras/Build Points?
« Reply #4 on: April 15, 2015, 09:02:10 AM »
Hi gchaprnka,

I've been working on pretty much the exact same thing as you over the last week or so and actually found a few things in your script that really helped me. I also had your problem of the final model being outside of cameras but not of object in focus. After about 3 hours of searching through the forum (and mostly Alexey's posts  :P) I think I have found a solution to the issue, I'm not that happy with the solution but it does work.

Basically it seems to be the calibration file that is causing the problem (for me at least) in that the cameras are not calibrated properly through the script, I'm pretty sure it's my calibration file as I can manually import the calibration file and it does the same thing, the fact you're getting the same weird results suggests your calibration file might be wrong in the same way mine is. Unfortunately I haven't been able to work out what is wrong with my calibration file so my solution is just to use the functions:

Code: [Select]
chunk.alignCameras()
directly after the 'matchingPhotos' section. This just does the alignment that is normally done through the GUI, as I haven't been able to get the calibration file to work it's the second best solution. I hope this helps and if you have made any progress on this I would be very interested.

Regards
Sam

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15438
    • View Profile
Re: Import Cameras/Build Points?
« Reply #5 on: April 21, 2015, 03:00:54 PM »
Hello gchaprnka,

Using Import Cameras from GUI still performs image matching, as you are asked for the alignment accuracy, preselection and etc.
In your code you do not use .buildPoints() function after the image matching.
Best regards,
Alexey Pasumansky,
Agisoft LLC

n@sk

  • Jr. Member
  • **
  • Posts: 89
    • View Profile
Re: Import Cameras/Build Points?
« Reply #6 on: April 23, 2015, 02:44:46 AM »
Hi Alexey,

using

chunk.buildPoints(error=***)   

right after

chunk.matchPhotos(accuracy=PhotoScan.HighAccuracy, preselection=PhotoScan.Preselection.NoPreselection, filter_mask=False, keypoint_limit=***, tiepoint_limit=***)
chunk.matchPhotos()

creates less than 1000 points, regardless of the error and point limits ***

Compared to the number of points created with GUI->Tie Points->Build Point Cloud...
it looks like the 1000 tie point limit is hard coded by default for chunk.buildPoints

Is there a way around this?

gchaprnka, SamC-E
many thanks for your input

regards
nask

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15438
    • View Profile
Re: Import Cameras/Build Points?
« Reply #7 on: April 23, 2015, 09:26:38 AM »
Hello nask,

Looks like you are using chunk.matchPhotos twice, the second time with the default parameters.
Best regards,
Alexey Pasumansky,
Agisoft LLC

n@sk

  • Jr. Member
  • **
  • Posts: 89
    • View Profile
Re: Import Cameras/Build Points?
« Reply #8 on: April 23, 2015, 06:43:53 PM »
makes sense...
silly mistake

cheers for the prompt response!