8 from xml.etree.ElementTree
import parse
24 def plyfile(file, progress=gr.Progress(track_tqdm=
True)):
25 progress(0, desc=
"Uploading Starting")
26 file_paths = file.name
28 for i
in progress.tqdm(file_paths, desc=
"Uploading from file"):
37 def rgbfile(file, progress=gr.Progress(track_tqdm=
"True")):
38 progress(0, desc=
"Uploading Starting")
39 rgbfile_paths = file.name
41 for i
in progress.tqdm(rgbfile_paths, desc=
"Uploading from file"):
45 rgbfile_name = os.path.basename(rgbfile_paths).split(
'/')[-1]
46 rgb_name = os.path.splitext(rgbfile_name)
50 currentPath = os.getcwd()
52 if os.path.exists(rgbfile_paths):
53 shutil.move(rgbfile_paths , currentPath+
"//DepthMap//"+rgbfile_name)
57 def depthfile(file, progress=gr.Progress(track_tqdm=
"True")):
58 depthfile_paths = file.name
59 progress(0, desc=
"Uploading Starting")
61 for i
in progress.tqdm(depthfile_paths, desc=
"Uploading from file"):
65 depthfile_name = os.path.basename(depthfile_paths).split(
'/')[-1]
66 depth_name = os.path.splitext(depthfile_name)
71 currentPath = os.getcwd()
73 if os.path.exists(depthfile_paths):
74 shutil.move(depthfile_paths , currentPath+
"//DepthMap//"+depthfile_name)
75 return depthfile_paths
77 def lightfile(directory, progress=gr.Progress(track_tqdm=
"True")):
78 progress(0, desc=
"lightfile Uploading Starting")
80 for file
in directory:
81 lightfile_name = os.path.basename(file.name).split(
'/')[-1]
82 light_name = os.path.splitext(lightfile_name)
83 currentPath = os.getcwd()
84 if os.path.exists(file.name):
85 shutil.move(file.name , currentPath+
"//LightField//"+light_name[0])
88 light = os.getcwd()+
"//LightField//" 93 progress(0, desc=
"trimeshfile Uploading Starting")
94 trimesh_file_paths = file.name
96 for i
in progress.tqdm(trimesh_file_paths, desc=
"trimeshfile Uploading from file"):
101 trimesh = trimesh_file_paths
103 return trimesh_file_paths
106 progress(0, desc=
"wrpplyfile Uploading Starting")
107 wrp_file_paths = file.name
109 for i
in progress.tqdm(wrp_file_paths, desc=
"wrpplyfile Uploading from file"):
114 wrpply = wrp_file_paths
116 return wrp_file_paths
119 point_file_paths = file.name
120 tree = parse(point_file_paths)
121 root = tree.getroot()
124 PointConfig = point_file_paths
125 point_ScaleX = root.find(
"ScaleX").text
126 point_ScaleY = root.find(
"ScaleY").text
127 point_ScaleZ = root.find(
"ScaleZ").text
128 point_Distance = root.find(
"Distance").text
129 point_SLM_PixelPitchX = root.find(
"SLM_PixelPitchX").text
130 point_SLM_PixelPitchY = root.find(
"SLM_PixelPitchY").text
131 point_SLM_PixelNumX = root.find(
"SLM_PixelNumX").text
132 point_SLM_PixelNumY = root.find(
"SLM_PixelNumY").text
133 point_SLM_WaveLength_1 = root.find(
"SLM_WaveLength_1").text
134 point_SLM_WaveLength_2 = root.find(
"SLM_WaveLength_2").text
135 point_SLM_WaveLength_3 = root.find(
"SLM_WaveLength_3").text
137 return {point_Scale_X:point_ScaleX,
138 point_Scale_Y:point_ScaleY,
139 point_Scale_Z:point_ScaleZ,
140 point_Distance_pre:point_Distance,
141 point_PixelPitch_X:point_SLM_PixelPitchX,
142 point_PixelPitch_Y:point_SLM_PixelPitchY,
143 point_PixelNum_X:point_SLM_PixelNumX,
144 point_PixelNum_Y:point_SLM_PixelNumY,
145 point_WaveLength_1:point_SLM_WaveLength_1,
146 point_WaveLength_2:point_SLM_WaveLength_2,
147 point_WaveLength_3:point_SLM_WaveLength_3
151 depth_file_paths = file.name
152 tree = parse(depth_file_paths)
153 root = tree.getroot()
156 DepthConfig = depth_file_paths
158 depth_Field_Lens = root.find(
"FieldLength").text
159 depth_Near_Depth = root.find(
"NearOfDepth").text
160 depth_Far_Depth = root.find(
"FarOfDepth").text
161 depth_Num_OfDepth =
"256" 162 depth_PixelPitch_X= root.find(
"SLM_PixelPitchX").text
163 depth_PixelPitch_Y = root.find(
"SLM_PixelPitchY").text
164 depth_PixelNum_X = root.find(
"SLM_PixelNumX").text
165 depth_PixelNum_Y = root.find(
"SLM_PixelNumY").text
166 depth_Wave_Length1 = root.find(
"SLM_WaveLength_1").text
167 depth_Wave_Length2 = root.find(
"SLM_WaveLength_2").text
168 depth_Wave_Length3 = root.find(
"SLM_WaveLength_3").text
170 return {depth_FieldLength:depth_Field_Lens,
171 depth_NearOfDepth:depth_Near_Depth,
172 depth_FarOfDepth:depth_Far_Depth,
173 depth_NumOfDepth:depth_Num_OfDepth,
174 depth_PixelPitchX:depth_PixelPitch_X,
175 depth_PixelPitchY:depth_PixelPitch_Y,
176 depth_PixelNumX:depth_PixelNum_X,
177 depth_PixelNumY:depth_PixelNum_Y,
178 depth_WaveLength1:depth_Wave_Length1,
179 depth_WaveLength2:depth_Wave_Length2,
180 depth_WaveLength3:depth_Wave_Length3
185 light_file_paths = file.name
186 tree = parse(light_file_paths)
187 root = tree.getroot()
190 LightConfig = light_file_paths
192 light_distance = root.find(
"Distance").text
193 light_Image_NumOf_X = root.find(
"Image_NumOfX").text
194 light_Image_NumOf_Y = root.find(
"Image_NumOfY").text
195 light_PixelPitch_X= root.find(
"SLM_PixelPitchX").text
196 light_PixelPitch_Y = root.find(
"SLM_PixelPitchY").text
197 light_PixelNum_X = root.find(
"SLM_PixelNumX").text
198 light_PixelNum_Y = root.find(
"SLM_PixelNumY").text
199 light_Wave_Length1 = root.find(
"SLM_WaveLength_1").text
200 light_Wave_Length2 = root.find(
"SLM_WaveLength_2").text
201 light_Wave_Length3 = root.find(
"SLM_WaveLength_3").text
203 return {light_Distance:light_distance,
204 light_Image_NumOfX:light_Image_NumOf_X,
205 light_Image_NumOfY:light_Image_NumOf_Y,
206 light_PixelPitchX:light_PixelPitch_X,
207 light_PixelPitchY:light_PixelPitch_Y,
208 light_PixelNumX:light_PixelNum_X,
209 light_PixelNumY:light_PixelNum_Y,
210 light_WaveLength1:light_Wave_Length1,
211 light_WaveLength2:light_Wave_Length2,
212 light_WaveLength3:light_Wave_Length3
216 trimesh_file_paths = file.name
217 tree = parse(trimesh_file_paths)
218 root = tree.getroot()
221 TrimeshConfig = trimesh_file_paths
223 trimesh_ScaleX = root.find(
"ScaleX").text
224 trimesh_ScaleY = root.find(
"ScaleY").text
225 trimesh_ScaleZ = root.find(
"ScaleZ").text
226 trimesh_LampDirectionX = root.find(
"LampDirectionX").text
227 trimesh_LampDirectionY = root.find(
"LampDirectionY").text
228 trimesh_LampDirectionZ = root.find(
"LampDirectionZ").text
229 trimesh_PixelPitchX = root.find(
"SLM_PixelPitchX").text
230 trimesh_PixelPitchY = root.find(
"SLM_PixelPitchY").text
231 trimesh_PixelNumX = root.find(
"SLM_PixelNumX").text
232 trimesh_PixelNumY = root.find(
"SLM_PixelNumY").text
233 trimesh_Wave_Length1 = root.find(
"SLM_WaveLength_1").text
234 trimesh_Wave_Length2 = root.find(
"SLM_WaveLength_2").text
235 trimesh_Wave_Length3 = root.find(
"SLM_WaveLength_3").text
237 return {trimesh_Scale_X:trimesh_ScaleX,
238 trimesh_Scale_Y:trimesh_ScaleY,
239 trimesh_Scale_Z:trimesh_ScaleZ,
240 trimesh_LampDirection_X:trimesh_LampDirectionX,
241 trimesh_LampDirection_Y:trimesh_LampDirectionY,
242 trimesh_LampDirection_Z:trimesh_LampDirectionZ,
243 trimesh_PixelPitch_X:trimesh_PixelPitchX,
244 trimesh_PixelPitch_Y:trimesh_PixelPitchY,
245 trimesh_PixelNum_X:trimesh_PixelNumX,
246 trimesh_PixelNum_Y:trimesh_PixelNumY,
247 trimesh_WaveLength_1:trimesh_Wave_Length1,
248 trimesh_WaveLength_2:trimesh_Wave_Length2,
249 trimesh_WaveLength_3:trimesh_Wave_Length3
253 wrp_file_paths = file.name
254 tree = parse(wrp_file_paths)
255 root = tree.getroot()
258 WrpConfig = wrp_file_paths
260 print(
"[wrpXmlParing] root = ",root)
261 wrp_ScaleX = root.find(
"ScaleX").text
262 wrp_ScaleY = root.find(
"ScaleY").text
263 wrp_ScaleZ = root.find(
"ScaleZ").text
264 wrp_distance = root.find(
"Distance").text
265 wrp_NumOfWRP = root.find(
"NumOfWRP").text
266 wrp_LocationOfWRP = root.find(
"LocationOfWRP").text
267 wrp_SLM_PixelPitchX = root.find(
"SLM_PixelPitchX").text
268 wrp_SLM_PixelPitchY = root.find(
"SLM_PixelPitchY").text
269 wrp_SLM_PixelNumX = root.find(
"SLM_PixelNumX").text
270 wrp_SLM_PixelNumY = root.find(
"SLM_PixelNumY").text
271 wrp_SLM_WaveLength_1 = root.find(
"SLM_WaveLength_1").text
272 wrp_SLM_WaveLength_2 = root.find(
"SLM_WaveLength_2").text
273 wrp_SLM_WaveLength_3 = root.find(
"SLM_WaveLength_3").text
275 return {wrp_Scale_X:wrp_ScaleX,
276 wrp_Scale_Y:wrp_ScaleY,
277 wrp_Scale_Z:wrp_ScaleZ,
278 wrp_Distance:wrp_distance,
279 wrp_NumOf_WRP:wrp_NumOfWRP,
280 wrp_WRP_Location:wrp_LocationOfWRP,
281 wrp_PixelPitch_X:wrp_SLM_PixelPitchX,
282 wrp_PixelPitch_Y:wrp_SLM_PixelPitchY,
283 wrp_PixelNum_X:wrp_SLM_PixelNumX,
284 wrp_PixelNum_Y:wrp_SLM_PixelNumY,
285 wrp_WaveLength_1:wrp_SLM_WaveLength_1,
286 wrp_WaveLength_2:wrp_SLM_WaveLength_2,
287 wrp_WaveLength_3:wrp_SLM_WaveLength_3
291 file = pathlib.Path(
"OpenholoGeneration")
292 plyfile = pathlib.Path(ply)
294 if Diffraction ==
"R-S":
296 elif Diffraction ==
"Fresnel":
299 if Encoding ==
"Phase":
301 elif Encoding ==
"Amplitude":
303 elif Encoding ==
"Real":
305 elif Encoding ==
"Imaginary":
308 if Precision ==
"single":
319 if plyfile.exists () :
320 subprocess.run([
'./OpenholoGeneration -a \"{}\" -c \"{}\" -i \"{}\" -e \"{}\" -m \"{}\" -p \"{}\" -f \"{}\"'.format(
"0",PointConfig, ply, enc, pre, mode, diff)], shell=
True)
322 print(
"File upload did not complete. Please try again after the file is uploaded.")
324 print(
"OpenholoGeneration file does not exist, so it does not work normally")
325 return './Result/PointCloud_'+Diffraction+
"_"+Encoding+
'.bmp' 328 file = pathlib.Path(
"OpenholoGeneration")
329 currentPath = os.getcwd()
330 rgbfile = pathlib.Path(currentPath+
"//DepthMap//"+rgb+
".bmp")
331 depthfile = pathlib.Path(currentPath+
"//DepthMap//"+depth+
".bmp")
333 if Encoding ==
"Phase":
335 elif Encoding ==
"Amplitude":
337 elif Encoding ==
"Real":
339 elif Encoding ==
"Imaginary":
344 elif pc_mode ==
"GPU":
348 if rgbfile.exists ()
and depthfile.exists () :
349 subprocess.run([
'./OpenholoGeneration -a \"{}\" -c \"{}\" -i \"{}\" \"{}\" \"{}\" -e \"{}\" -m \"{}\" -p \"{}\"'.format(
"1",DepthConfig,
'./DepthMap', rgb, depth, enc,
"1", mode)], shell=
True)
351 print(
"File upload did not complete. Please try again after the file is uploaded.")
353 print(
"OpenholoGeneration file does not exist, so it does not work normally")
355 return './Result/DepthMap_'+Encoding+
'.bmp' 358 file = pathlib.Path(
"OpenholoGeneration")
359 lightdir = pathlib.Path(light)
361 if Encoding ==
"Phase":
363 elif Encoding ==
"Amplitude":
365 elif Encoding ==
"Real":
367 elif Encoding ==
"Imaginary":
375 if lightdir.exists () :
376 subprocess.run([
'./OpenholoGeneration -a \"{}\" -c \"{}\" -i \"{}\" -e \"{}\" -m \"{}\" -p \"{}\"'.format(
"2",LightConfig, light, enc,
"1", mode)], shell=
True)
378 print(
"File upload did not complete. Please try again after the file is uploaded.")
380 print(
"OpenholoGeneration file does not exist, so it does not work normally")
381 return './Result/LightField_'+Encoding+
'.bmp' 384 file = pathlib.Path(
"OpenholoGeneration")
385 trimeshfile = pathlib.Path(trimesh)
387 if Encoding ==
"Phase":
389 elif Encoding ==
"Amplitude":
391 elif Encoding ==
"Real":
393 elif Encoding ==
"Imaginary":
401 if trimeshfile.exists () :
402 subprocess.run([
'./OpenholoGeneration -a \"{}\" -c \"{}\" -i \"{}\" -e \"{}\" -m \"{}\" -p \"{}\"'.format(
"3",TrimeshConfig, trimesh, enc,
"1", mode)], shell=
True)
404 print(
"File upload did not complete. Please try again after the file is uploaded.")
406 print(
"OpenholoGeneration file does not exist, so it does not work normally")
407 return './Result/TriMesh_'+Encoding+
'.bmp' 410 file = pathlib.Path(
"OpenholoGeneration")
411 wrpplyfile = pathlib.Path(wrpply)
413 if Encoding ==
"Phase":
415 elif Encoding ==
"Amplitude":
417 elif Encoding ==
"Real":
419 elif Encoding ==
"Imaginary":
428 if wrpplyfile.exists () :
429 subprocess.run([
'./OpenholoGeneration -a \"{}\" -c \"{}\" -i \"{}\" -e \"{}\" -m \"{}\" -p \"{}\"'.format(
"4",WrpConfig, wrpply, enc,
"1", mode)], shell=
True)
431 print(
"File upload did not complete. Please try again after the file is uploaded.")
433 print(
"OpenholoGeneration file does not exist, so it does not work normally")
434 return './Result/WRP_'+Encoding+
'.bmp' 438 with gr.Blocks(theme=gr.themes.Soft(), css=
".gradio-container {background-color: #CFE3EA}", title=
"Openholo Generation")
as demo:
440 gr.HTML(
"<img src='/file/logo_m.png' align='left' vspace='14' hspace='14'> <font size ='6'><b>Hologram generation methods by Openholo library</b>")
442 with gr.Tab(label =
"Point Cloud"):
444 with gr.Row()
as row:
446 pointxml = gr.File(label=
"Choose a PointCloud Config (.xml) File to Upload",interactive=
"True")
448 ply = gr.File(label=
"Choose a PointCloud (*.ply) File to Upload",interactive=
"True")
449 plyout = gr.Textbox(label=
"[Warning] Please wait until the size of the ply file to be uploaded is large and displayed in the temporary path in the text box below. The upload is complete when the box below is displayed.")
450 with gr.Row()
as row:
452 point_Scale_X = gr.Textbox(label =
"Scale X", placeholder=
"0.01")
453 point_Scale_X.change(
lambda s: s, inputs=point_Scale_X)
455 point_Scale_Y = gr.Textbox(label =
"Scale Y", placeholder=
"0.01")
456 point_Scale_Y.change(
lambda s: s, inputs=point_Scale_Y)
458 point_Scale_Z = gr.Textbox(label =
"Scale Z", placeholder=
"0.01")
459 point_Scale_Z.change(
lambda s: s, inputs=point_Scale_Z)
460 with gr.Row()
as row:
461 point_Distance_pre = gr.Textbox(label =
"Distance", placeholder=
"0.5")
462 point_Distance_pre.change(
lambda s: s, inputs=point_Distance_pre)
463 with gr.Row()
as row:
465 point_PixelPitch_X = gr.Textbox(label =
"PixelPitch X", placeholder=
"10e-6")
466 point_PixelPitch_X.change(
lambda s: s, inputs=point_PixelPitch_X)
468 point_PixelPitch_Y = gr.Textbox(label =
"PixelPitch Y", placeholder=
"10e-6")
469 point_PixelPitch_Y.change(
lambda s: s, inputs=point_PixelPitch_Y)
470 with gr.Row()
as row:
472 point_PixelNum_X = gr.Textbox(label =
"PixelNum X", placeholder=
"1920")
473 point_PixelNum_X.change(
lambda s: s, inputs=point_PixelNum_X)
475 point_PixelNum_Y = gr.Textbox(label =
"PixelNum Y", placeholder=
"1080")
476 point_PixelNum_Y.change(
lambda s: s, inputs=point_PixelNum_Y)
477 with gr.Row()
as row:
479 point_WaveLength_1 = gr.Textbox(label =
"WaveLength1", placeholder=
"638e-9")
480 point_WaveLength_1.change(
lambda s: s, inputs=point_WaveLength_1)
482 point_WaveLength_2 = gr.Textbox(label =
"WaveLength2", placeholder=
"520e-9")
483 point_WaveLength_2.change(
lambda s: s, inputs=point_WaveLength_2)
485 point_WaveLength_3 = gr.Textbox(label =
"WaveLength3", placeholder=
"450e-9")
486 point_WaveLength_3.change(
lambda s: s, inputs=point_WaveLength_3)
487 with gr.Row()
as row:
489 Diffraction = gr.Dropdown([
'R-S',
'Fresnel'], value=
"R-S", label =
"Diffraction Flag" , info=
"Choose an flag!")
491 Encoding = gr.Dropdown([
'Phase',
'Amplitude',
'Real',
'Imaginary'], value=
"Phase", label =
"Encoding Method" , info=
"Choose an encoding!")
492 with gr.Row()
as row:
494 Precision = gr.Radio([
"single",
"double"], value=
"single", label=
"Precision (GPGPU)")
496 pc_mode = gr.Radio([
"CPU",
"GPU"], value=
"GPU", label=
"CPU / GPU")
498 pointOutput = gr.Image(label=
"Point Cloud Bmp")
499 pointGen = gr.Button(value =
"Generate Point Cloud Hologram")
500 pointxml.upload(fn=pointXmlParing, inputs=pointxml,outputs=[point_Scale_X,point_Scale_Y,point_Scale_Z,point_Distance_pre,point_PixelPitch_X,point_PixelPitch_Y,point_PixelNum_X,point_PixelNum_Y,point_WaveLength_1,point_WaveLength_2,point_WaveLength_3])
501 ply.upload(fn=plyfile, inputs=ply, outputs=plyout, show_progress=
"True")
502 pointGen.click(fn=pointGenerate,inputs=[Diffraction,Encoding,Precision,pc_mode],outputs=pointOutput)
504 with gr.Tab(label =
"DepthMap"):
506 with gr.Row()
as row:
508 depthxml = gr.File(label=
"Choose a Depthmap Xml File to Upload",interactive=
"True")
510 bmprgb = gr.File(label=
"Choose a Rgb File to Upload",interactive=
"True")
511 rgbout = gr.Textbox(label=
"[Warning] Please wait until the size of the rgb file to be uploaded is large and displayed in the temporary path in the text box below. The upload is complete when the box below is displayed.")
513 bmpdepth = gr.File(label=
"Choose a Depthmap File to Upload",interactive=
"True")
514 depthout = gr.Textbox(label=
"[Warning] Please wait until the size of the depth file to be uploaded is large and displayed in the temporary path in the text box below. The upload is complete when the box below is displayed.")
515 with gr.Row()
as row:
517 depth_FieldLength = gr.Textbox(label =
"Field Lens(m)", placeholder=
"1000e-3")
518 depth_FieldLength.change(
lambda s: s, inputs=depth_FieldLength)
520 depth_NumOfDepth = gr.Textbox(label =
"Num Of Depth", placeholder=
"256")
521 depth_NumOfDepth.change(
lambda s: s, inputs=depth_NumOfDepth)
522 with gr.Row()
as row:
524 depth_NearOfDepth = gr.Textbox(label =
"Near Depth(m)", placeholder=
"0.4")
525 depth_NearOfDepth.change(
lambda s: s, inputs=depth_NearOfDepth)
527 depth_FarOfDepth = gr.Textbox(label =
"Far Depth(m)", placeholder=
"0.6")
528 depth_FarOfDepth.change(
lambda s: s, inputs=depth_FarOfDepth)
529 with gr.Row()
as row:
531 depth_PixelPitchX = gr.Textbox(label =
"PixelPitch X(m)", placeholder=
"10e-6")
532 depth_PixelPitchX.change(
lambda s: s, inputs=depth_PixelPitchX)
534 depth_PixelPitchY = gr.Textbox(label =
"PixelPitch Y(m)", placeholder=
"10e-6")
535 depth_PixelPitchY.change(
lambda s: s, inputs=depth_PixelPitchY)
536 with gr.Row()
as row:
538 depth_PixelNumX = gr.Textbox(label =
"PixelNum X", placeholder=
"1920")
539 depth_PixelNumX.change(
lambda s: s, inputs=depth_PixelNumX)
541 depth_PixelNumY = gr.Textbox(label =
"PixelNum Y", placeholder=
"1080")
542 depth_PixelNumY.change(
lambda s: s, inputs=depth_PixelNumY)
543 with gr.Row()
as row:
545 depth_WaveLength1 = gr.Textbox(label =
"WaveLength1(m)", placeholder=
"638e-9")
546 depth_WaveLength1.change(
lambda s: s, inputs=depth_WaveLength1)
548 depth_WaveLength2 = gr.Textbox(label =
"WaveLength2(m)", placeholder=
"520e-9")
549 depth_WaveLength2.change(
lambda s: s, inputs=depth_WaveLength2)
551 depth_WaveLength3 = gr.Textbox(label =
"WaveLength3(m)", placeholder=
"450e-9")
552 depth_WaveLength3.change(
lambda s: s, inputs=depth_WaveLength3)
553 with gr.Row()
as row:
555 Propagation = gr.Dropdown([
'Angular Spectrum'], value=
"Angular Spectrum", label =
"Propagation Method" , info=
"Choose an Propagation!")
557 Encoding = gr.Dropdown([
'Phase',
'Amplitude',
'Real',
'Imaginary'], value=
"Phase", label =
"Encoding Method", info=
"Choose an Encoding!")
558 with gr.Row()
as row:
560 pc_mode = gr.Radio([
"CPU",
"GPU"], value=
"GPU", label=
"CPU / GPU", info=
"Choose an mode!")
561 depthxml.upload(fn=depthXmlParing, inputs=depthxml,outputs=[depth_FieldLength,depth_NearOfDepth,depth_FarOfDepth,depth_NumOfDepth,depth_PixelPitchX,depth_PixelPitchY,depth_PixelNumX,depth_PixelNumY,depth_WaveLength1,depth_WaveLength2,depth_WaveLength3])
562 bmprgb.upload(fn=rgbfile, inputs=bmprgb, outputs=rgbout, show_progress=
"True")
563 bmpdepth.upload(fn=depthfile, inputs=bmpdepth, outputs=depthout, show_progress=
"True")
564 depthOutput = gr.Image(label=
"DepthMap Bmp")
565 depthGen = gr.Button(value =
"Generate DepthMap Hologram")
566 depthGen.click(fn=depthGenerate, inputs=[Encoding,pc_mode] ,outputs=depthOutput)
568 with gr.Tab(label =
"LightField"):
570 with gr.Row()
as row:
572 lightxml = gr.File(label=
"Choose a LightField Xml File to Upload",interactive=
"True")
574 lightbmp = gr.File(label=
"Image Folder to Upload",interactive=
"True", file_count=
"directory")
575 with gr.Row()
as row:
577 light_Distance = gr.Textbox(label =
"Distance", placeholder=
"0.5")
578 light_Distance.change(
lambda s: s, inputs=light_Distance)
579 with gr.Row()
as row:
581 light_Image_NumOfX = gr.Textbox(label =
"Num of Img X", placeholder=
"10")
582 light_Image_NumOfX.change(
lambda s: s, inputs=light_Image_NumOfX)
584 light_Image_NumOfY = gr.Textbox(label =
"Num of Img Y", placeholder=
"10")
585 light_Image_NumOfY.change(
lambda s: s, inputs=light_Image_NumOfY)
586 with gr.Row()
as row:
588 light_PixelPitchX = gr.Textbox(label =
"PixelPitch X(m)", placeholder=
"1e-5")
589 light_PixelPitchX.change(
lambda s: s, inputs=light_PixelPitchX)
591 light_PixelPitchY = gr.Textbox(label =
"PixelPitch Y(m)", placeholder=
"1e-5")
592 light_PixelPitchY.change(
lambda s: s, inputs=light_PixelPitchY)
593 with gr.Row()
as row:
595 light_PixelNumX = gr.Textbox(label =
"PixelNum X", placeholder=
"1920")
596 light_PixelNumX.change(
lambda s: s, inputs=light_PixelNumX)
598 light_PixelNumY = gr.Textbox(label =
"PixelNum Y", placeholder=
"1080")
599 light_PixelNumY.change(
lambda s: s, inputs=light_PixelNumY)
600 with gr.Row()
as row:
602 light_WaveLength1 = gr.Textbox(label =
"WaveLength1(m)", placeholder=
"638e-9")
603 light_WaveLength1.change(
lambda s: s, inputs=light_WaveLength1)
605 light_WaveLength2 = gr.Textbox(label =
"WaveLength2(m)", placeholder=
"520e-9")
606 light_WaveLength2.change(
lambda s: s, inputs=light_WaveLength2)
608 light_WaveLength3 = gr.Textbox(label =
"WaveLength3(m)", placeholder=
"450e-9")
609 light_WaveLength3.change(
lambda s: s, inputs=light_WaveLength3)
610 with gr.Row()
as row:
612 Encoding = gr.Dropdown([
'Phase',
'Amplitude',
'Real',
'Imaginary'], value=
"Phase", label =
"Encoding Method", info=
"Choose an Encoding!")
614 pc_mode = gr.Radio([
"CPU",
"GPU"], value=
"GPU", label=
"CPU / GPU", info=
"Choose an mode!")
616 lightxml.upload(fn=lightXmlParing, inputs=lightxml,outputs=[light_Distance,light_Image_NumOfX,light_Image_NumOfY,light_PixelPitchX,light_PixelPitchY,light_PixelNumX,light_PixelNumY,light_WaveLength1,light_WaveLength2,light_WaveLength3])
617 lightbmp.upload(fn=lightfile, inputs=lightbmp, show_progress=
"True")
618 lightOutput = gr.Image(label=
"LightField Bmp")
619 lightGen = gr.Button(value =
"Generate LightField Hologram")
620 lightGen.click(fn=lightGenerate, inputs=[Encoding,pc_mode] ,outputs=lightOutput)
622 with gr.Tab(label =
"Triangle Mesh"):
624 with gr.Row()
as row:
626 trimeshxml = gr.File(label=
"Choose a Triangle Mesh Config (.xml) File to Upload",interactive=
"True")
628 trimeshply = gr.File(label=
"Choose a Triangle Mesh (*.ply) File to Upload",interactive=
"True")
629 trimeshplyout = gr.Textbox(label=
"[Warning] Please wait until the size of the Triangle Mesh file to be uploaded is large and displayed in the temporary path in the text box below. The upload is complete when the box below is displayed.")
630 with gr.Row()
as row:
632 trimesh_Scale_X = gr.Textbox(label =
"Scale X", placeholder=
"0.005")
633 trimesh_Scale_X.change(
lambda s: s, inputs=trimesh_Scale_X)
635 trimesh_Scale_Y = gr.Textbox(label =
"Scale Y", placeholder=
"0.005")
636 trimesh_Scale_Y.change(
lambda s: s, inputs=trimesh_Scale_Y)
638 trimesh_Scale_Z = gr.Textbox(label =
"Scale Z", placeholder=
"0.005")
639 trimesh_Scale_Z.change(
lambda s: s, inputs=trimesh_Scale_Z)
640 with gr.Row()
as row:
642 trimesh_LampDirection_X = gr.Textbox(label =
"LampDirectionX", placeholder=
"0")
643 trimesh_LampDirection_X.change(
lambda s: s, inputs=trimesh_LampDirection_X)
645 trimesh_LampDirection_Y = gr.Textbox(label =
"LampDirectionY", placeholder=
"0.3")
646 trimesh_LampDirection_Y.change(
lambda s: s, inputs=trimesh_LampDirection_Y)
648 trimesh_LampDirection_Z = gr.Textbox(label =
"LampDirectionZ", placeholder=
"1")
649 trimesh_LampDirection_Z.change(
lambda s: s, inputs=trimesh_LampDirection_Z)
650 with gr.Row()
as row:
652 trimesh_PixelPitch_X = gr.Textbox(label =
"PixelPitch X", placeholder=
"10e-6")
653 trimesh_PixelPitch_X.change(
lambda s: s, inputs=trimesh_PixelPitch_X)
655 trimesh_PixelPitch_Y = gr.Textbox(label =
"PixelPitch Y", placeholder=
"10e-6")
656 trimesh_PixelPitch_Y.change(
lambda s: s, inputs=trimesh_PixelPitch_Y)
657 with gr.Row()
as row:
659 trimesh_PixelNum_X = gr.Textbox(label =
"PixelNum X", placeholder=
"1920")
660 trimesh_PixelNum_X.change(
lambda s: s, inputs=trimesh_PixelNum_X)
662 trimesh_PixelNum_Y = gr.Textbox(label =
"PixelNum Y", placeholder=
"1080")
663 trimesh_PixelNum_Y.change(
lambda s: s, inputs=trimesh_PixelNum_Y)
664 with gr.Row()
as row:
666 trimesh_WaveLength_1 = gr.Textbox(label =
"WaveLength1", placeholder=
"638e-9")
667 trimesh_WaveLength_1.change(
lambda s: s, inputs=trimesh_WaveLength_1)
669 trimesh_WaveLength_2 = gr.Textbox(label =
"WaveLength2", placeholder=
"520e-9")
670 trimesh_WaveLength_2.change(
lambda s: s, inputs=trimesh_WaveLength_2)
672 trimesh_WaveLength_3 = gr.Textbox(label =
"WaveLength3", placeholder=
"450e-9")
673 trimesh_WaveLength_3.change(
lambda s: s, inputs=trimesh_WaveLength_3)
674 with gr.Row()
as row:
676 Encoding = gr.Dropdown([
'Phase',
'Amplitude',
'Real',
'Imaginary'], value=
"Phase", label =
"Encoding Method" , info=
"Choose an encoding!")
678 pc_mode = gr.Radio([
"CPU",
"GPU"], value=
"GPU", label=
"CPU / GPU")
679 trimeshOutput = gr.Image(label=
"Triangle Mesh Bmp")
680 trimeshGen = gr.Button(value =
"Generate Triangle Mesh Hologram")
681 trimeshxml.upload(fn=trimeshXmlParing, inputs=trimeshxml,outputs=[trimesh_Scale_X,trimesh_Scale_Y,trimesh_Scale_Z,trimesh_LampDirection_X,trimesh_LampDirection_Y,trimesh_LampDirection_Z,trimesh_PixelPitch_X,trimesh_PixelPitch_Y,trimesh_PixelNum_X,trimesh_PixelNum_Y,trimesh_WaveLength_1,trimesh_WaveLength_2,trimesh_WaveLength_3])
682 trimeshply.upload(fn=trimeshfile, inputs=trimeshply, outputs=trimeshplyout, show_progress=
"True")
683 trimeshGen.click(fn=trimeshGenerate,inputs=[Encoding,pc_mode],outputs=trimeshOutput)
685 with gr.Tab(label =
"WRP"):
687 with gr.Row()
as row:
689 wrpxml = gr.File(label=
"Choose a WRP Config (.xml) File to Upload",interactive=
"True")
691 wrpply = gr.File(label=
"Choose a WRP (*.ply) File to Upload",interactive=
"True")
692 wrpplyout = gr.Textbox(label=
"[Warning] Please wait until the size of the ply file to be uploaded is large and displayed in the temporary path in the text box below. The upload is complete when the box below is displayed.")
693 with gr.Row()
as row:
695 wrp_Scale_X = gr.Textbox(label =
"Scale X", placeholder=
"0.0015")
696 wrp_Scale_X.change(
lambda s: s, inputs=wrp_Scale_X)
698 wrp_Scale_Y = gr.Textbox(label =
"Scale Y", placeholder=
"0.0015")
699 wrp_Scale_Y.change(
lambda s: s, inputs=wrp_Scale_Y)
701 wrp_Scale_Z = gr.Textbox(label =
"Scale Z", placeholder=
"0.0015")
702 wrp_Scale_Z.change(
lambda s: s, inputs=wrp_Scale_Z)
703 with gr.Row()
as row:
705 wrp_Distance = gr.Textbox(label =
"Distance", placeholder=
"0.5")
706 wrp_Distance.change(
lambda s: s, inputs=wrp_Distance)
708 wrp_NumOf_WRP = gr.Textbox(label =
"NumOfWRP", placeholder=
"1")
709 wrp_NumOf_WRP.change(
lambda s: s, inputs=wrp_NumOf_WRP)
711 wrp_WRP_Location = gr.Textbox(label =
"LocationOfWRP", placeholder=
"0.003")
712 wrp_WRP_Location.change(
lambda s: s, inputs=wrp_WRP_Location)
713 with gr.Row()
as row:
715 wrp_PixelPitch_X = gr.Textbox(label =
"PixelPitch X", placeholder=
"1e-5")
716 wrp_PixelPitch_X.change(
lambda s: s, inputs=wrp_PixelPitch_X)
718 wrp_PixelPitch_Y = gr.Textbox(label =
"PixelPitch Y", placeholder=
"1e-5")
719 wrp_PixelPitch_Y.change(
lambda s: s, inputs=wrp_PixelPitch_Y)
720 with gr.Row()
as row:
722 wrp_PixelNum_X = gr.Textbox(label =
"PixelNum X", placeholder=
"1920")
723 wrp_PixelNum_X.change(
lambda s: s, inputs=wrp_PixelNum_X)
725 wrp_PixelNum_Y = gr.Textbox(label =
"PixelNum Y", placeholder=
"1080")
726 wrp_PixelNum_Y.change(
lambda s: s, inputs=wrp_PixelNum_Y)
727 with gr.Row()
as row:
729 wrp_WaveLength_1 = gr.Textbox(label =
"WaveLength1", placeholder=
"638e-9")
730 wrp_WaveLength_1.change(
lambda s: s, inputs=wrp_WaveLength_1)
732 wrp_WaveLength_2 = gr.Textbox(label =
"WaveLength2", placeholder=
"520e-9")
733 wrp_WaveLength_2.change(
lambda s: s, inputs=wrp_WaveLength_2)
735 wrp_WaveLength_3 = gr.Textbox(label =
"WaveLength3", placeholder=
"450e-9")
736 wrp_WaveLength_3.change(
lambda s: s, inputs=wrp_WaveLength_3)
737 with gr.Row()
as row:
739 Encoding = gr.Dropdown([
'Phase',
'Amplitude',
'Real',
'Imaginary'], value=
"Phase", label =
"Encoding Method" , info=
"Choose an encoding!")
741 pc_mode = gr.Radio([
"CPU",
"GPU"], value=
"GPU", label=
"CPU / GPU")
742 wrpOutput = gr.Image(label=
"WRP Bmp")
743 wrpGen = gr.Button(value =
"Generate WRP Hologram")
744 wrpxml.upload(fn=wrpXmlParing, inputs=wrpxml,outputs=[ wrp_Scale_X, wrp_Scale_Y, wrp_Scale_Z, wrp_Distance, wrp_NumOf_WRP, wrp_WRP_Location, wrp_PixelPitch_X, wrp_PixelPitch_Y, wrp_PixelNum_X, wrp_PixelNum_Y, wrp_WaveLength_1, wrp_WaveLength_2, wrp_WaveLength_3])
745 wrpply.upload(fn=wrpplyfile, inputs=wrpply, outputs=wrpplyout, show_progress=
"True")
746 wrpGen.click(fn=wrpGenerate,inputs=[Encoding,pc_mode],outputs=wrpOutput)
748 if __name__ ==
"__main__":
749 demo.queue(concurrency_count=10).launch(share=
True)