Forum

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - matt07lx

Pages: [1]
1
Hi All,

I'm attempting to create a python script that will copy the reconstruction region from one project and export it to a new script that will then apply the same region to other projects. My projects all use the same projected coordinate system, and are located in the same geographic space, so this should work in theory. I'm aware from other posts that the region's coordinates use the chunk's internal system, and that these need to be converted to geocentric, then projected to the proper CRS. When applying them to a new project, this process needs to be done in reverse. When I run the script within the same project it works perfectly. I can save the new script, change the region, then reset it using the new script. However, when I try to apply the new script to a different project in the same location, using the same CRS, it creates a region that is incorrect. Does anyone know where I'm going wrong?

Script to capture the original region:
Code: [Select]
import Metashape, os, glob

doc = Metashape.app.document
chunk = doc.chunk
region = chunk.region
center = chunk.region.center
rot = chunk.region.rot
size = chunk.region.size
crs = chunk.crs
T = chunk.transform.matrix

#File name must include *.py extension
file = Metashape.app.getSaveFileName("Save Script as")

print("Local Bounding Region Coordinates:")
print("Center: ",center)
print("Rotation: ",rot)
print("Size: ",size)

#Now convert them to the project CRS
#center and size are Metashape.Vector
#rotation is Metashape.Matrix - this needs to be broken into three vectors to be converted
#All are changed to strings to write to the new script file
center_CRS = chunk.crs.project(T.mulp(center)) # vector with point coordinates in CRS
center_CRS = str([center_CRS[0],center_CRS[1],center_CRS[2]])
size_CRS = chunk.crs.project(T.mulp(size)) # vector with point coordinates in CRS
size_CRS = str([size_CRS[0],size_CRS[1],size_CRS[2]])
rot1_CRS = chunk.crs.project(T.mulp(Metashape.Vector([rot[0,0], rot[0,1], rot[0,2]]))) # vector with point coordinates in CRS
rot1_CRS = str([rot1_CRS[0],rot1_CRS[1],rot1_CRS[2]])
rot2_CRS = chunk.crs.project(T.mulp(Metashape.Vector([rot[1,0], rot[1,1], rot[1,2]]))) # vector with point coordinates in CRS
rot2_CRS = str([rot2_CRS[0],rot2_CRS[1],rot2_CRS[2]])
rot3_CRS = chunk.crs.project(T.mulp(Metashape.Vector([rot[2,0], rot[2,1], rot[2,2]]))) # vector with point coordinates in CRS
rot3_CRS = str([rot3_CRS[0],rot3_CRS[1],rot3_CRS[2]])
#rot_CRS = Metashape.Matrix([rot1_CRS,rot2_CRS,rot3_CRS])
#the three elements to create region are now in the CRS
print("Bounding Region Coordinates in CRS")
print("Center: ",center_CRS)
print("Rotation: ",rot1_CRS,"\n",rot2_CRS,"\n",rot3_CRS)
print("Size: ",size_CRS)

content = ("import Metashape, os, glob\ndoc = Metashape.app.document\nchunk = doc.chunk\nregion = chunk.region\nT = chunk.transform.matrix\n\n#import the region coordinates in CRS\ncenter_CRS = Metashape.Vector(%s)\nsize_CRS = Metashape.Vector(%s)\nrot1_CRS = Metashape.Vector(%s)\nrot2_CRS = Metashape.Vector(%s)\nrot3_CRS = Metashape.Vector(%s)\n\n#But now we'd have to convert these back to the local chunk coordinates\ncrs = chunk.crs\nbb_center = T.inv().mulp(crs.unproject(center_CRS))\nbb_size = T.inv().mulp(crs.unproject(size_CRS))\nbb_rot1 = T.inv().mulp(crs.unproject(rot1_CRS))\nbb_rot2 = T.inv().mulp(crs.unproject(rot2_CRS))\nbb_rot3 = T.inv().mulp(crs.unproject(rot3_CRS))\nbb_rot = Metashape.Matrix([bb_rot1,bb_rot2,bb_rot3])\n\n#assign the new coordinates to the bounding box in other projects\nchunk.region.center = bb_center\nchunk.region.rot = bb_rot\nchunk.region.size = bb_size\n" % (center_CRS, size_CRS, rot1_CRS,rot2_CRS, rot3_CRS))

with open(path, 'w') as file:
  file.writelines(content)

print("Script exported to: ",path)

Example of a new script output by the above:
Code: [Select]
import Metashape, os, glob
doc = Metashape.app.document
chunk = doc.chunk
region = chunk.region
T = chunk.transform.matrix
crs = chunk.crs

#import the region coordinates in CRS
center_CRS = Metashape.Vector([2326260.9766565366, 4694783.921291048, 383.9612362860649])
size_CRS = Metashape.Vector([2326255.3612297955, 4694784.090214137, 381.2784408229167])
rot1_CRS = Metashape.Vector([2326260.9183688844, 4694785.530955884, 385.6499192495625])
rot2_CRS = Metashape.Vector([2326260.3992965193, 4694785.620727421, 385.6765585270715])
rot3_CRS = Metashape.Vector([2326260.636379602, 4694785.3316533305, 386.04862309706607])

#But now we'd have to convert these back to the local chunk coordinates
bb_center = T.inv().mulp(crs.unproject(center_CRS))
bb_size = T.inv().mulp(crs.unproject(size_CRS))
bb_rot1 = T.inv().mulp(crs.unproject(rot1_CRS))
bb_rot2 = T.inv().mulp(crs.unproject(rot2_CRS))
bb_rot3 = T.inv().mulp(crs.unproject(rot3_CRS))
bb_rot = Metashape.Matrix([bb_rot1,bb_rot2,bb_rot3])

#assign the new coordinates to the bounding box in other projects
chunk.region.center = bb_center
chunk.region.rot = bb_rot
chunk.region.size = bb_size

2
General / GCPs vs Scale Bars
« on: April 18, 2023, 10:08:29 PM »
I was wondering if somebody could explain the relationship of ground control points and scale bars within a model. If you use both, are scale bars considered to be "more accurate" in scaling, and hence prioritized? In my typical use, GCPs are set with a total station, in which error typically is around a cm, whereas I can use target based scale bars with errors lower than a mm. Do the scale bars simply as a control to check the GCP errors, or do they improve the accuracy of the model scale?

3
General / Characterize Model Accuracy in Real World Units?
« on: April 06, 2023, 07:35:06 PM »
Hi All - I was wondering if anyone can suggest the best method for characterizing a model's accuracy in terms of real units (e.g. meters)? Thinking through this problem, it seems to be that using a calibrated scale bar (with targets) might offer the best reading of overall model accuracy since the target centers can be located with high precision. GCPs set with a total station or GPS will likely have errors larger than a cm or more, so these can't be used to understand model accuracy below this level. I don't know how well the scale bar error characterizes the accuracy across the whole model though, since they will only be a small part of the overall model.

I've wondered if the reprojection RMS error (pixels) can somehow can be converted to real world units? If I were to take the average RMS reprojection pixel error and multiply it by the ground resolution, would that give an approximation of the average error in real units?

4
Bug Reports / Sketchfab Upload: "OpenSSL Library Not Found"
« on: July 22, 2019, 07:41:10 PM »
I get the following message when I try to upload to Sketchfab directly from Metashape: "OpenSSL Library Not Found: Please Install OpenSSL 1.0 for Data". I've installed several versions of OpenSSL (64 and 32 bit), restarted Metashape and my computer, and nothing seems to work. Any ideas? I've never had this issue before.

5
General / Palaeo3D Scale Bars?
« on: June 06, 2019, 11:58:44 PM »
Just curious if anyone has purchased scale bars from Palaeo3D (http://palaeo3d.de/WP/?page_id=23). They are much more affordable than the ones made by Cultural Heritage Imaging (http://culturalheritageimaging.org/What_We_Offer/Gear/Scale_Bars/index.html), but I'm wondering how durable they are. If anyone out there has a set, would you say they are appropriate for archaeological fieldwork? Will they break easily since they are foam?

6
General / Identify Coordinates of Object Center?
« on: January 24, 2019, 06:58:19 PM »
Is there currently a way to identify the coordinates (in a projected coordinate system) of a 3D model's center point? Alternatively, is there a way to create a target or point on the center of the model that will help me get these coordinates? Perhaps a python script can be written to do this? I need the coordinates of the center in order to correctly locate the model when imported to ArcGIS (there are known issues with locating georeferenced models in ArcGIS. I think this may help me develop a workflow to get around these issues).

Thanks!

7
General / Model Location shift after import to ArcScene [Solved]
« on: September 16, 2017, 06:29:01 AM »
This is more of a GIS question than Photoscan, I suppose, but I figure someone here might know the answer. I created a series of models in Photoscan of archaeological layers that are all georeferenced using the same markers shot with a total station one time. Therefore I am able to stack them in several programs (CloudCompare and Photoscan, too, by appending the various models into the same project), and they align perfectly since they use the exact same markers with the same exact UTM coordinates. However, when I import the Collada files into ArcScene as multipatch layers, each model ends up slightly shifted (perhaps a few centimeters). Nothing aligns perfectly, even when if I import the UTM coordinates of the markers as a shapefile.

The odd thing is that I've even checked the orthomosaic files from the same models, and they align in ArcMap perfectly, and the UTM markers are precisely located on the targets, etc. What's the difference between orthomosaics in ArcMap and multipatch files in ArcScene that I'm missing? Is it something to do with the UTM coordinates getting rounded down or something in the conversion from Collada to multipatch?

8
Python and Java API / "Split in chunks" not working?
« on: June 23, 2017, 12:00:35 AM »
I've tried to use the "split in chunks" script several times (http://wiki.agisoft.com/wiki/Split_in_chunks.py), but it doesn't seem to do anything. It only outputs "7777" in the console the first I try it, then nothing happens each subsequent time. I've tried with a couple different projects too. I'm not certain what I am doing wrong. I've used other scripts (e.g. PS130_coordinate_system_to_bounding_box.py) successfully before.

9
General / GCPs with dumpy level?
« on: June 14, 2017, 06:20:33 PM »
I've been trying to design a strategy to create a nice DEM and orthomosaic of a small area (about 40 x 23 meters), but I don't have access to a Total Station or high quality GPS to enter coordinates for GCPs. I'm considering trying to enter local coordinates using a dumpy level. This should give me relative elevation (z coordinates), at least accurate to the nearest cm. I'm not sure, though, how to get reasonably accurate x, y coordinates. I can triangulate distance measurements from known points to plot this on grid paper, but how can I convert this to reasonably accurate x and y coordinates. Is it possible to only enter z coordinates for GCPs and use a meter bar for scale elsewhere in the project? Any thoughts?

10
General / DEM without GCPs and UAV?
« on: May 03, 2017, 07:58:41 PM »
I'm trying to work out a method to create a DEM to serve as a base map for an archaeological project in a relatively small area (a property surrounding a historic home). Normally, I use a Total Station to shoot in the coordinates for GCPs, but I likely won't have access to one for this project. These coordinates not only help to georeference the resulting orthomosaics and DEMs, but they provide the x,y plane. To get around this, I was wondering if I could do something relatively simple: get a bubble level with some measurements on it. I would attach a couple targets at known distances for scale, then use the bubble levels to ensure that it was level. The resulting scale bar could also serve as the x,y plane for creating orthomosaics.

The second issue is how to get the proper coverage and image overlap without the use of a drone. I'm guessing that a pole would do the trick, since taking photos from my standing height, even in a relatively small project area, would probably not work.

Would this work? Am I missing anything or making any unintentional mistakes?

11
General / Orthophotos of Wall Facades and other vertical surfaces
« on: January 16, 2017, 10:05:13 PM »
I use Photoscan in archaeology to document standing architecture and archaeological trenches. I have a question about the feasibility of using Photoscan to create orthophotos of wall facades or other vertical surfaces. Our GCPs are measured using a total station, and these allow us to create perfect "top down" orthophotos for archaeological plans, but is it possible to do the same for walls and the sides of trenches, allowing for the creation of archaeological section drawings? I know that it is possible to choose a planar projection using markers to define the horizontal and vertical axes for the orthophoto, but if these markers are manually placed onto the 3D model from Photoscan, how accurate is the resulting orthophoto? For instance, will the horizontal orientation of the orthophoto be parallel to the x and y axis from our GCPs, or will it follow the arbitrary horizontal plane between my two markers on the wall? I have the same question for the vertical axis - will it align along the z axis from the GCPs or the line between my markers? What if the wall in question was "slanted" and not perfectly vertical? I'd appreciate any input that anybody could provide.

Pages: [1]