@@ -71,6 +71,14 @@ class DepthAnythingV3(desc.Node):
7171 value = "Metric-Large" ,
7272 exclusive = True ,
7373 ),
74+ desc .FloatParam (
75+ name = "focalpix" ,
76+ label = "Focal in pixels" ,
77+ value = 300.0 ,
78+ description = "Focal value in pixels used if it cannot be extracted from metadata." ,
79+ range = (1.0 , 10000.0 , 1.0 ),
80+ enabled = lambda node : node .sam3Model .value == "Metric-Large" ,
81+ ),
7482 desc .BoolParam (
7583 name = "outputDepth" ,
7684 label = "Output Depth Map" ,
@@ -178,7 +186,7 @@ def processChunk(self, chunk):
178186 images = []
179187
180188 for idx , path in enumerate (chunk_image_paths ):
181- img , h_ori , w_ori , pixelAspectRatio , orientation = image .loadImage (str (chunk_image_paths [idx ]), applyPAR = True )
189+ img , h_ori , w_ori , pixelAspectRatio , orientation = image .loadImage (str (chunk_image_paths [idx ][ 0 ] ), applyPAR = True )
182190
183191 img_pil = (np .clip (img , 0.0 , 1.0 ) * 255 ).astype (np .uint8 )
184192 images .append (img_pil )
@@ -191,11 +199,12 @@ def processChunk(self, chunk):
191199
192200 depth = prediction .depth [idx ]
193201
194- # if chunk.node.sam3Model.value == "Metric-Large":
195- # depth = focal * depth / 300
202+ if chunk .node .sam3Model .value == "Metric-Large" :
203+ fpix = chunk_image_paths [idx ][1 ] if chunk_image_paths [idx ][1 ] > 0.0 else chunk .node .focalpix .value
204+ depth = fpix * depth / 300
196205
197206 outputDirPath = Path (chunk .node .output .value )
198- image_stem = Path (chunk_image_paths [idx ]).stem
207+ image_stem = Path (chunk_image_paths [idx ][ 0 ] ).stem
199208
200209 image_stem = str (image_stem )
201210
@@ -214,11 +223,8 @@ def processChunk(self, chunk):
214223 image .writeImage (depth_file_path , depth_to_write , h_ori , w_ori , orientation , pixelAspectRatio , metadata_deep_model , optWrite )
215224 if chunk .node .outputDepth .value and chunk .node .saveVisuImages .value :
216225 import matplotlib
217- #if chunk.node.sam3Model.value == "Metric-Large":
218226 depth = (depth - depth .min ()) / (depth .max () - depth .min ())
219227 cmap = matplotlib .colormaps .get_cmap ('Spectral' )
220- #else:
221- # cmap = matplotlib.colormaps.get_cmap('Spectral_r')
222228 colored_depth = cmap (depth )[:, :, :3 ]
223229 image .writeImage (vis_file_path , colored_depth , h_ori , w_ori , orientation , pixelAspectRatio , metadata_deep_model )
224230
@@ -229,23 +235,32 @@ def processChunk(self, chunk):
229235def get_image_paths_list (input_path , extension ):
230236 from pyalicevision import sfmData
231237 from pyalicevision import sfmDataIO
238+ from pyalicevision import camera
232239 from pathlib import Path
233240 import itertools
241+ import numpy as np
234242
235243 include_suffixes = [extension .lower (), extension .upper ()]
236244 image_paths = []
237245
238- inPath = Path (input_path )
239- if inPath . is_dir ():
240- image_paths = sorted ( itertools . chain ( * ( inPath . glob ( f'*. { suffix } ' ) for suffix in include_suffixes )))
241- elif inPath .suffix .lower () in [".sfm" , ".abc" ]:
242- if inPath .exists ():
246+ if Path (input_path ). is_dir ():
247+ image_paths = sorted ( itertools . chain ( * ( Path ( input_path ). glob ( f'*. { suffix } ' ) for suffix in include_suffixes )))
248+ image_paths = [( p , - 1.0 ) for p in image_paths ]
249+ elif Path ( input_path ) .suffix .lower () in [".sfm" , ".abc" ]:
250+ if Path ( input_path ) .exists ():
243251 dataAV = sfmData .SfMData ()
244252 if sfmDataIO .load (dataAV , input_path , sfmDataIO .ALL ):
245253 views = dataAV .getViews ()
246254 for id , v in views .items ():
247- image_paths .append (Path (v .getImage ().getImagePath ()))
248- image_paths .sort ()
255+ intrinsicId = v .getIntrinsicId ()
256+ intrinsic = dataAV .getIntrinsic (intrinsicId )
257+ scaleOffset = camera .IntrinsicScaleOffset .cast (intrinsic )
258+ focalLength = scaleOffset .getFocalLength ()
259+ sensorWidth = scaleOffset .sensorWidth ()
260+ focal_x_pix = focalLength * float (scaleOffset .w ()) / sensorWidth
261+ image_paths .append ((Path (v .getImage ().getImagePath ()), focal_x_pix ))
262+
263+ image_paths .sort (key = lambda x : x [0 ])
249264 else :
250265 raise ValueError (f"Input path '{ input_path } ' is not a valid path (folder or sfmData file)." )
251266 return image_paths
0 commit comments