Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

[a34150]: contrib / brl / bseg / boxm2 / pyscripts / vpgl_adaptor.py Maximize Restore History

Download this file

vpgl_adaptor.py    662 lines (615 with data), 26.5 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
from boxm2_register import boxm2_batch, dbvalue;
#import math, numpy;
import math;
###################;
#camera loading;
###################;
def load_perspective_camera(file_path) :
boxm2_batch.init_process("vpglLoadPerspectiveCameraProcess");
boxm2_batch.set_input_string(0, file_path);
boxm2_batch.run_process();
(id,type) = boxm2_batch.commit_output(0);
cam = dbvalue(id,type);
return cam;
def load_affine_camera(file_path) :
boxm2_batch.init_process("vpglLoadAffineCameraProcess");
boxm2_batch.set_input_string(0, file_path);
boxm2_batch.run_process();
(id,type) = boxm2_batch.commit_output(0);
cam = dbvalue(id,type);
return cam;
def load_projective_camera(file_path) :
boxm2_batch.init_process("vpglLoadProjCameraProcess");
boxm2_batch.set_input_string(0, file_path);
boxm2_batch.run_process();
(id,type) = boxm2_batch.commit_output(0);
cam = dbvalue(id,type);
return cam;
#Scale = (scale_u, scale_v), ppoint = (u,v), center = (x,y,z), look_pt = (x,y,z), up = (x,y,z);
def create_perspective_camera( scale, ppoint, center, look_pt,up = [0,1,0] ) :
boxm2_batch.init_process("vpglCreatePerspectiveCameraProcess");
boxm2_batch.set_input_double(0, scale[0]);
boxm2_batch.set_input_double(1, ppoint[0]);
boxm2_batch.set_input_double(2, scale[1]);
boxm2_batch.set_input_double(3, ppoint[1]);
boxm2_batch.set_input_double(4, center[0]);
boxm2_batch.set_input_double(5, center[1]);
boxm2_batch.set_input_double(6, center[2]);
boxm2_batch.set_input_double(7, look_pt[0]);
boxm2_batch.set_input_double(8, look_pt[1]);
boxm2_batch.set_input_double(9, look_pt[2]);
boxm2_batch.run_process();
(id,type) = boxm2_batch.commit_output(0);
cam = dbvalue(id,type);
return cam;
def create_perspective_camera_from_kml(ni, nj, right_fov, top_fov, altitude, heading, tilt, roll, cent_x, cent_y) :
boxm2_batch.init_process("vpglCreatePerspCameraFromKMLProcess");
boxm2_batch.set_input_unsigned(0, ni);
boxm2_batch.set_input_unsigned(1, nj);
boxm2_batch.set_input_double(2, right_fov);
boxm2_batch.set_input_double(3, top_fov);
boxm2_batch.set_input_double(4, altitude);
boxm2_batch.set_input_double(5, heading);
boxm2_batch.set_input_double(6, tilt);
boxm2_batch.set_input_double(7, roll);
boxm2_batch.set_input_double(8, cent_x);
boxm2_batch.set_input_double(9, cent_y);
boxm2_batch.run_process();
(id,type) = boxm2_batch.commit_output(0);
cam = dbvalue(id,type);
return cam;
def load_perspective_camera_from_kml_file(NI, NJ, kml_file) :
boxm2_batch.init_process("vpglLoadPerspCameraFromKMLFileProcess");
boxm2_batch.set_input_unsigned(0, NI);
boxm2_batch.set_input_unsigned(1, NJ);
boxm2_batch.set_input_string(2, kml_file);
boxm2_batch.run_process();
(id,type) = boxm2_batch.commit_output(0);
cam = dbvalue(id,type);
(id,type) = boxm2_batch.commit_output(1);
longitude = boxm2_batch.get_output_double(id);
(id,type) = boxm2_batch.commit_output(2);
latitude = boxm2_batch.get_output_double(id);
(id,type) = boxm2_batch.commit_output(3);
altitude = boxm2_batch.get_output_double(id);
return cam, longitude, latitude, altitude;
#resize a camera from size0 =(ni,nj) to size1 (ni_1, nj_1);
def resample_perspective_camera( cam, size0, size1 ):
boxm2_batch.init_process("vpglResamplePerspectiveCameraProcess");
boxm2_batch.set_input_from_db(0, cam);
boxm2_batch.set_input_int(1, size0[0]);
boxm2_batch.set_input_int(2, size0[1]);
boxm2_batch.set_input_int(3, size1[0]);
boxm2_batch.set_input_int(4, size1[1]);
boxm2_batch.run_process();
(id,type) = boxm2_batch.commit_output(0);
out = dbvalue(id,type);
return out;
#resize a camera from size0 =(ni,nj) to size1 (ni_1, nj_1);
def get_perspective_camera_center( cam):
boxm2_batch.init_process("vpglGetPerspectiveCamCenterProcess");
boxm2_batch.set_input_from_db(0, cam);
boxm2_batch.run_process();
(id, type) = boxm2_batch.commit_output(0);
x=boxm2_batch.get_output_float(id);
(id, type) = boxm2_batch.commit_output(1);
y=boxm2_batch.get_output_float(id);
(id, type) = boxm2_batch.commit_output(2);
z=boxm2_batch.get_output_float(id);
return x,y,z;
# returns cartesian cam center from azimuth (degrees), elevation (degrees), radius, look point;
def get_camera_center( azimuth, elevation, radius, lookPt) :
deg_to_rad = math.pi/180.0;
el = elevation*deg_to_rad;
az = azimuth*deg_to_rad;
cx = radius*math.sin(el)*math.cos(az);
cy = radius*math.sin(el)*math.sin(az);
cz = radius*math.cos(el);
center = (cx + lookPt[0], cy + lookPt[1], cz + lookPt[2]);
return center;
#returns spherical coordinates about sCenter given cartesian point;
def cart2sphere(cartPt, sCenter):
#offset cart point;
cartPt = numpy.subtract(cartPt, sCenter);
rad = math.sqrt( sum(cartPt*cartPt) );
az = math.atan2(cartPt[1],cartPt[0]);
el = math.acos(cartPt[2]/rad);
return (math.degrees(az), math.degrees(el), rad);
def load_rational_camera(file_path) :
boxm2_batch.init_process("vpglLoadRationalCameraProcess");
boxm2_batch.set_input_string(0, file_path);
boxm2_batch.run_process();
(id,type) = boxm2_batch.commit_output(0);
cam = dbvalue(id,type);
return cam;
def load_rational_camera_nitf(file_path) :
boxm2_batch.init_process("vpglLoadRationalCameraNITFProcess");
boxm2_batch.set_input_string(0, file_path);
boxm2_batch.run_process();
(id,type) = boxm2_batch.commit_output(0);
cam = dbvalue(id,type);
return cam;
def load_local_rational_camera(file_path) :
boxm2_batch.init_process("vpglLoadLocalRationalCameraProcess");
boxm2_batch.set_input_string(0, file_path);
boxm2_batch.run_process();
(id,type) = boxm2_batch.commit_output(0);
cam = dbvalue(id,type);
return cam;
def convert_local_rational_perspective_camera(local_cam) :
boxm2_batch.init_process("vpglConvertLocalRationalToPerspectiveProcess");
boxm2_batch.set_input_from_db(0, local_cam);
boxm2_batch.run_process();
(id,type) = boxm2_batch.commit_output(0);
cam = dbvalue(id,type);
return cam;
def create_local_rational_camera(rational_cam_fname, lvcs_fname):
boxm2_batch.init_process('vpglCreateLocalRationalCameraProcess');
boxm2_batch.set_input_string(0,rational_cam_fname);
boxm2_batch.set_input_string(1,lvcs_fname);
boxm2_batch.run_process();
(id,type) = boxm2_batch.commit_output(0);
cam = dbvalue(id,type);
return cam;
###################;
#camera saving;
###################;
def save_rational_camera(camera,path) :
boxm2_batch.init_process("vpglSaveRationalCameraProcess");
boxm2_batch.set_input_from_db(0,camera);
boxm2_batch.set_input_string(1,path);
boxm2_batch.run_process();
def save_perspective_camera(camera,path) :
boxm2_batch.init_process("vpglSavePerspectiveCameraProcess");
boxm2_batch.set_input_from_db(0,camera);
boxm2_batch.set_input_string(1,path);
boxm2_batch.run_process();
def save_perspective_camera_vrml(camera,path) :
boxm2_batch.init_process("vpglSavePerspectiveCameraVrmlProcess");
boxm2_batch.set_input_from_db(0,camera);
boxm2_batch.set_input_string(1,path);
boxm2_batch.set_input_float(2,5.0);
boxm2_batch.run_process();
def save_perspective_cameras_vrml(camerafolder,path) :
boxm2_batch.init_process("vpglSavePerspectiveCamerasVrmlProcess");
boxm2_batch.set_input_string(0,camerafolder);
boxm2_batch.set_input_string(1,path);
boxm2_batch.set_input_float(2,5.0);
boxm2_batch.run_process();
def save_proj_camera(camera, path):
boxm2_batch.init_process("vpglSaveProjectiveCameraProcess");
boxm2_batch.set_input_from_db(0, camera);
boxm2_batch.set_input_string(1, path);
boxm2_batch.run_process();
#################################################;
# perspective go generic conversion;
#################################################;
def persp2gen(pcam, ni, nj, level=0) :
boxm2_batch.init_process("vpglConvertToGenericCameraProcess");
boxm2_batch.set_input_from_db(0, pcam);
boxm2_batch.set_input_unsigned(1, ni);
boxm2_batch.set_input_unsigned(2, nj);
boxm2_batch.set_input_unsigned(3, level);
boxm2_batch.run_process();
(id,type) = boxm2_batch.commit_output(0);
gcam = dbvalue(id,type);
return gcam;
def persp2genWmargin(pcam, ni, nj, margin, level=0) :
boxm2_batch.init_process("vpglConvertToGenericCameraWithMarginProcess");
boxm2_batch.set_input_from_db(0, pcam);
boxm2_batch.set_input_unsigned(1, ni);
boxm2_batch.set_input_unsigned(2, nj);
boxm2_batch.set_input_unsigned(3, level);
boxm2_batch.set_input_int(4, margin);
boxm2_batch.run_process();
(id,type) = boxm2_batch.commit_output(0);
gcam = dbvalue(id,type);
(id,type) = boxm2_batch.commit_output(1);
ni = boxm2_batch.get_output_unsigned(id);
(id,type) = boxm2_batch.commit_output(2);
nj = boxm2_batch.get_output_unsigned(id);
(id,type) = boxm2_batch.commit_output(3);
new_pers_cam = dbvalue(id,type);
return (gcam, ni, nj, new_pers_cam);
def write_generic_to_vrml(cam, out_file_name, level=0):
boxm2_batch.init_process("vpglWriteGenericCameraProcess");
boxm2_batch.set_input_from_db(0, cam);
boxm2_batch.set_input_string(1, out_file_name);
boxm2_batch.set_input_unsigned(2, level);
boxm2_batch.run_process();
#gets bounding box from a directory of cameras... (incomplete)_;
def camera_dir_planar_bbox(dir_name) :
boxm2_batch.init_process("vpglGetBoundingBoxProcess");
boxm2_batch.set_input_string(0, dir_name);
boxm2_batch.run_process();
def project_point(camera,x,y,z):
boxm2_batch.init_process('vpglProjectProcess');
boxm2_batch.set_input_from_db(0,camera);
boxm2_batch.set_input_float(1,x);
boxm2_batch.set_input_float(2,y);
boxm2_batch.set_input_float(3,z);
boxm2_batch.run_process();
(id,type) = boxm2_batch.commit_output(0);
u = boxm2_batch.get_output_float(id);
(id,type) = boxm2_batch.commit_output(1);
v = boxm2_batch.get_output_float(id);
return (u,v);
# gets view direction at a point for a perspective camera;
def get_view_at_point(persp_cam,x,y,z):
boxm2_batch.init_process("vpglGetViewDirectionAtPointProcess");
boxm2_batch.set_input_from_db(0,persp_cam);
boxm2_batch.set_input_float(1,x);
boxm2_batch.set_input_float(2,y);
boxm2_batch.set_input_float(3,z);
boxm2_batch.run_process();
(id,type) = boxm2_batch.commit_output(0);
theta=boxm2_batch.get_output_float(id);
(id,type) = boxm2_batch.commit_output(1);
phi=boxm2_batch.get_output_float(id);
return theta, phi;
def get_3d_from_depth(persp_cam,u,v,t) :
boxm2_batch.init_process("vpglGenerate3dPointFromDepthProcess");
boxm2_batch.set_input_from_db(0,persp_cam);
boxm2_batch.set_input_float(1,u);
boxm2_batch.set_input_float(2,v);
boxm2_batch.set_input_float(3,t);
boxm2_batch.run_process();
(id, type) = boxm2_batch.commit_output(0);
x=boxm2_batch.get_output_float(id);
(id, type) = boxm2_batch.commit_output(1);
y=boxm2_batch.get_output_float(id);
(id, type) = boxm2_batch.commit_output(2);
z=boxm2_batch.get_output_float(id);
return x,y,z;
# triangulates a list of cams and a list of points;
def get_3d_from_cams( cams, points ):
assert( len(cams) == len(points) and len(cams) > 1 );
#list of points will just be [u1,v1,u2,v2...];
ptlist = [];
for p in points:
ptlist.append(p[0]);
ptlist.append(p[1]);
#list of cam ids (type will be checked in C++);
camlist = [];
for cam in cams:
camlist.append(cam.id);
boxm2_batch.init_process("vpglGenerate3dPointFromCamsProcess");
boxm2_batch.set_input_unsigned_array(0, camlist);
boxm2_batch.set_input_int_array(1, ptlist);
boxm2_batch.run_process();
(id, type) = boxm2_batch.commit_output(0);
x=boxm2_batch.get_output_float(id);
(id, type) = boxm2_batch.commit_output(1);
y=boxm2_batch.get_output_float(id);
(id, type) = boxm2_batch.commit_output(2);
z=boxm2_batch.get_output_float(id);
return x,y,z;
# create a generic camera;
def convert_to_generic_camera(cam_in, ni, nj, level=0):
boxm2_batch.init_process('vpglConvertToGenericCameraProcess');
boxm2_batch.set_input_from_db(0,cam_in);
boxm2_batch.set_input_unsigned(1,ni);
boxm2_batch.set_input_unsigned(2,nj);
boxm2_batch.set_input_unsigned(3,level);
boxm2_batch.run_process();
(id,type) = boxm2_batch.commit_output(0);
generic_cam = dbvalue(id,type);
return generic_cam;
# create a generic camera from a local rational with user-specified z range;
def convert_local_rational_to_generic(cam_in, ni, nj, min_z, max_z, level=0):
boxm2_batch.init_process('vpglConvertLocalRationalToGenericProcess');
boxm2_batch.set_input_from_db(0,cam_in);
boxm2_batch.set_input_unsigned(1,ni);
boxm2_batch.set_input_unsigned(2,nj);
boxm2_batch.set_input_float(3,min_z);
boxm2_batch.set_input_float(4,max_z);
boxm2_batch.set_input_unsigned(5,level);
if not boxm2_batch.run_process():
return None;
(id,type) = boxm2_batch.commit_output(0);
generic_cam = dbvalue(id,type);
return generic_cam;
# correct a rational camera;
def correct_rational_camera(cam_in, offset_x, offset_y):
boxm2_batch.init_process('vpglCorrectRationalCameraProcess');
boxm2_batch.set_input_from_db(0,cam_in);
boxm2_batch.set_input_double(1,offset_x);
boxm2_batch.set_input_double(2,offset_y);
boxm2_batch.run_process();
(id,type) = boxm2_batch.commit_output(0);
corrected_cam = dbvalue(id,type);
return corrected_cam;
def get_rational_camera_offsets(cam_in):
boxm2_batch.init_process('vpglGetRationalCameraOffsetsProcess');
boxm2_batch.set_input_from_db(0,cam_in);
boxm2_batch.run_process();
(id,type) = boxm2_batch.commit_output(0);
offset_u = boxm2_batch.get_output_double(id);
boxm2_batch.remove_data(id);
(id,type) = boxm2_batch.commit_output(1);
offset_v = boxm2_batch.get_output_double(id);
boxm2_batch.remove_data(id);
return (offset_u,offset_v);
def find_offset_and_correct_rational_camera(cam_orig, cam_corrected, cam_to_be_corrected):
offset_u, offset_v = get_rational_camera_offsets(cam_orig);
offset_u_c, offset_v_c = get_rational_camera_offsets(cam_corrected);
diff_u = offset_u_c - offset_u;
diff_v = offset_v_c - offset_v;
cam_out = correct_rational_camera(cam_to_be_corrected, diff_u, diff_v);
return cam_out
# convert lat,lon,el to local coordinates;
def convert_to_local_coordinates(lvcs_filename,lat,lon,el):
boxm2_batch.init_process('vpglConvertToLocalCoordinatesProcess');
boxm2_batch.set_input_string(0,lvcs_filename);
boxm2_batch.set_input_float(1,lat);
boxm2_batch.set_input_float(2,lon);
boxm2_batch.set_input_float(3,el);
boxm2_batch.run_process();
(id,type) = boxm2_batch.commit_output(0);
x = boxm2_batch.get_output_float(id);
boxm2_batch.remove_data(id);
(id,type) = boxm2_batch.commit_output(1);
y = boxm2_batch.get_output_float(id);
boxm2_batch.remove_data(id);
(id,type) = boxm2_batch.commit_output(2);
z = boxm2_batch.get_output_float(id);
boxm2_batch.remove_data(id);
return (x,y,z);
# convert lat,lon,el to local coordinates;
def convert_to_local_coordinates2(lvcs,lat,lon,el):
boxm2_batch.init_process('vpglConvertToLocalCoordinatesProcess2');
boxm2_batch.set_input_from_db(0,lvcs);
boxm2_batch.set_input_float(1,lat);
boxm2_batch.set_input_float(2,lon);
boxm2_batch.set_input_float(3,el);
boxm2_batch.run_process();
(id,type) = boxm2_batch.commit_output(0);
x = boxm2_batch.get_output_float(id);
boxm2_batch.remove_data(id);
(id,type) = boxm2_batch.commit_output(1);
y = boxm2_batch.get_output_float(id);
boxm2_batch.remove_data(id);
(id,type) = boxm2_batch.commit_output(2);
z = boxm2_batch.get_output_float(id);
boxm2_batch.remove_data(id);
return (x,y,z);
# convert lat,lon,el to local coordinates;
def convert_local_to_global_coordinates(lvcs,x,y,z):
boxm2_batch.init_process('vpglConvertLocalToGlobalCoordinatesProcess');
boxm2_batch.set_input_from_db(0,lvcs);
boxm2_batch.set_input_float(1,x);
boxm2_batch.set_input_float(2,y);
boxm2_batch.set_input_float(3,z);
boxm2_batch.run_process();
(id,type) = boxm2_batch.commit_output(0);
lat = boxm2_batch.get_output_float(id);
boxm2_batch.remove_data(id);
(id,type) = boxm2_batch.commit_output(1);
lon = boxm2_batch.get_output_float(id);
boxm2_batch.remove_data(id);
(id,type) = boxm2_batch.commit_output(2);
el = boxm2_batch.get_output_float(id);
boxm2_batch.remove_data(id);
return (lat,lon,el);
# convert lat,lon,el to local coordinates;
def create_lvcs(lat,lon,el,csname):
boxm2_batch.init_process('vpglCreateLVCSProcess');
boxm2_batch.set_input_float(0,lat);
boxm2_batch.set_input_float(1,lon);
boxm2_batch.set_input_float(2,el);
boxm2_batch.set_input_string(3,csname);
boxm2_batch.run_process();
(id,type) = boxm2_batch.commit_output(0);
lvcs = dbvalue(id,type);
return lvcs;
# randomly sample a camera rotated around principle axis;
def perturb_camera(cam_in, angle, rng):
boxm2_batch.init_process('vpglPerturbPerspCamOrientProcess');
boxm2_batch.set_input_from_db(0,cam_in);
boxm2_batch.set_input_float(1,angle);
boxm2_batch.set_input_from_db(2,rng);
boxm2_batch.run_process();
(id,type) = boxm2_batch.commit_output(0);
pert_cam = dbvalue(id,type);
(theta_id,type) = boxm2_batch.commit_output(1);
(phi_id,type) = boxm2_batch.commit_output(2);
theta = boxm2_batch.get_output_float(theta_id);
phi = boxm2_batch.get_output_float(phi_id);
return pert_cam, theta, phi;
def write_perspective_cam_vrml(vrml_filename, pcam, camera_rad, axis_length, r, g, b):
boxm2_batch.init_process("bvrmlWritePerspectiveCamProcess");
boxm2_batch.set_input_string(0,vrml_filename);
boxm2_batch.set_input_from_db(1,pcam);
boxm2_batch.set_input_float(2,camera_rad);
boxm2_batch.set_input_float(3,axis_length);
boxm2_batch.set_input_float(4,r);
boxm2_batch.set_input_float(5,g);
boxm2_batch.set_input_float(6,b);
boxm2_batch.run_process();
# rotate a camera around principle axis;
def rotate_perspective_camera(cam_in, theta, phi):
boxm2_batch.init_process('vpglRotatePerspCamProcess');
boxm2_batch.set_input_from_db(0,cam_in);
boxm2_batch.set_input_float(1,theta);
boxm2_batch.set_input_float(2,phi);
boxm2_batch.run_process();
(id,type) = boxm2_batch.commit_output(0);
rot_cam = dbvalue(id,type);
return rot_cam;
def get_perspective_cam_center(pcam):
boxm2_batch.init_process("vpglGetPerspectiveCamCenterProcess");
boxm2_batch.set_input_from_db(0, pcam);
boxm2_batch.run_process();
(x_id,x_type) = boxm2_batch.commit_output(0);
x = boxm2_batch.get_output_float(x_id);
(y_id,type) = boxm2_batch.commit_output(1);
y = boxm2_batch.get_output_float(y_id);
(z_id,type) = boxm2_batch.commit_output(2);
z = boxm2_batch.get_output_float(z_id);
return x, y, z;
def create_perspective_camera2(pcam, cent_x, cent_y, cent_z):
boxm2_batch.init_process("vpglCreatePerspectiveCameraProcess2");
boxm2_batch.set_input_from_db(0, pcam);
boxm2_batch.set_input_float(1, cent_x);
boxm2_batch.set_input_float(2, cent_y);
boxm2_batch.set_input_float(3, cent_z);
boxm2_batch.run_process();
(c_id,c_type) = boxm2_batch.commit_output(0);
cam = dbvalue(c_id,c_type);
return cam;
def create_perspective_camera_with_rot(pcam, phi, theta, cent_x, cent_y, cent_z):
boxm2_batch.init_process("vpglCreatePerspectiveCameraProcess3");
boxm2_batch.set_input_from_db(0, pcam);
boxm2_batch.set_input_float(1, phi);
boxm2_batch.set_input_float(2, theta);
boxm2_batch.set_input_float(3, cent_x);
boxm2_batch.set_input_float(4, cent_y);
boxm2_batch.set_input_float(5, cent_z);
boxm2_batch.run_process();
(c_id,c_type) = boxm2_batch.commit_output(0);
cam = dbvalue(c_id,c_type);
return cam;
def get_nitf_footprint(nitf_list_filename, out_kml_filename):
boxm2_batch.init_process('vpglNITFFootprintProcess');
boxm2_batch.set_input_string(0,nitf_list_filename);
boxm2_batch.set_input_string(1,out_kml_filename);
boxm2_batch.run_process();
def get_geocam_footprint(geocam, geotiff_filename, out_kml_filename,init_finish=True):
boxm2_batch.init_process('vpglGeoFootprintProcess');
boxm2_batch.set_input_from_db(0,geocam);
boxm2_batch.set_input_string(1,geotiff_filename);
boxm2_batch.set_input_string(2,out_kml_filename);
boxm2_batch.set_input_bool(3,init_finish);
boxm2_batch.run_process();
def load_geotiff_cam(tfw_filename, lvcs=0, utm_zone=0, utm_hemisphere=0):
boxm2_batch.init_process("vpglLoadGeoCameraProcess");
boxm2_batch.set_input_string(0, tfw_filename);
if lvcs != 0:
boxm2_batch.set_input_from_db(1, lvcs);
boxm2_batch.set_input_int(2, utm_zone);
boxm2_batch.set_input_unsigned(3, utm_hemisphere);
boxm2_batch.run_process();
(c_id,c_type) = boxm2_batch.commit_output(0);
cam = dbvalue(c_id,c_type);
return cam;
def save_geocam_to_tfw(cam, tfw_filename):
boxm2_batch.init_process("vpglSaveGeoCameraTFWProcess");
boxm2_batch.set_input_from_db(0, cam);
boxm2_batch.set_input_string(1, tfw_filename);
boxm2_batch.run_process();
def load_geotiff_cam2(filename, ni, nj):
boxm2_batch.init_process("vpglLoadGeoCameraProcess2");
boxm2_batch.set_input_string(0, filename);
boxm2_batch.set_input_unsigned(1, ni);
boxm2_batch.set_input_unsigned(2, nj);
boxm2_batch.run_process();
(c_id,c_type) = boxm2_batch.commit_output(0);
cam = dbvalue(c_id,c_type);
return cam;
def load_geotiff_from_header(filename, lvcs=0):
boxm2_batch.init_process("vpglLoadGeotiffCamFromHeaderProcess");
boxm2_batch.set_input_string(0, filename);
if lvcs != 0:
boxm2_batch.set_input_from_db(1, lvcs);
boxm2_batch.run_process();
(c_id,c_type) = boxm2_batch.commit_output(0);
cam = dbvalue(c_id,c_type);
return cam;
def translate_geo_camera(geocam, x, y):
boxm2_batch.init_process("vpglTranslateGeoCameraProcess");
boxm2_batch.set_input_from_db(0, geocam);
boxm2_batch.set_input_double(1, x);
boxm2_batch.set_input_double(2, y);
boxm2_batch.run_process();
(c_id, c_type) = boxm2_batch.commit_output(0);
cam = dbvalue(c_id, c_type);
return cam;
def geo2generic(geocam, ni, nj, scene_height, level):
boxm2_batch.init_process("vpglConvertGeoCameraToGenericProcess");
boxm2_batch.set_input_from_db(0, geocam);
boxm2_batch.set_input_int(1, ni);
boxm2_batch.set_input_int(2, nj);
boxm2_batch.set_input_double(3, scene_height);
boxm2_batch.set_input_int(4, level);
boxm2_batch.run_process();
(c_id, c_type) = boxm2_batch.commit_output(0);
cam = dbvalue(c_id, c_type);
return cam;
def save_lvcs(lat,lon,hae,lvcs_filename):
boxm2_batch.init_process("vpglSaveLVCSProcess");
boxm2_batch.set_input_float(0,lat);
boxm2_batch.set_input_float(1,lon);
boxm2_batch.set_input_float(2,hae);
boxm2_batch.set_input_string(3,lvcs_filename);
boxm2_batch.run_process();
return;
def load_lvcs(lvcs_filename):
boxm2_batch.init_process("vpglLoadLVCSProcess");
boxm2_batch.set_input_string(0, lvcs_filename);
boxm2_batch.run_process();
(lvcs_id, lvcs_type) = boxm2_batch.commit_output(0);
lvcs = dbvalue(lvcs_id, lvcs_type);
return lvcs;
def geo_cam_global_to_img(geocam, lon, lat):
boxm2_batch.init_process("vpglGeoGlobalToImgProcess");
boxm2_batch.set_input_from_db(0, geocam);
boxm2_batch.set_input_double(1, lon);
boxm2_batch.set_input_double(2, lat);
boxm2_batch.run_process();
(id, type) = boxm2_batch.commit_output(0);
u = boxm2_batch.get_output_int(id);
(id, type) = boxm2_batch.commit_output(1);
v = boxm2_batch.get_output_int(id);
return u, v;
def convert_perspective_to_nvm(cams_dir,imgs_dir, output_nvm):
boxm2_batch.init_process("vpglExportCamerasToNvmProcess");
boxm2_batch.set_input_string(0, cams_dir);
boxm2_batch.set_input_string(1, imgs_dir);
boxm2_batch.set_input_string(2, output_nvm);
return boxm2_batch.run_process();
def interpolate_perspective_cameras(cam0,cam1,ncams,outdir):
boxm2_batch.init_process("vpglInterpolatePerspectiveCamerasProcess");
boxm2_batch.set_input_from_db(0, cam0);
boxm2_batch.set_input_from_db(1, cam1);
boxm2_batch.set_input_unsigned(2, ncams);
boxm2_batch.set_input_string(3, outdir);
return boxm2_batch.run_process();
def compute_affine_from_local_rational(cropped_cam, min_x, min_y, min_z, max_x, max_y, max_z, n_points=100):
boxm2_batch.init_process("vpglComputeAffineFromRationalProcess");
boxm2_batch.set_input_from_db(0, cropped_cam);
boxm2_batch.set_input_double(1, min_x);
boxm2_batch.set_input_double(2, min_y);
boxm2_batch.set_input_double(3, min_z);
boxm2_batch.set_input_double(4, max_x);
boxm2_batch.set_input_double(5, max_y);
boxm2_batch.set_input_double(6, max_z);
boxm2_batch.set_input_unsigned(7, n_points);
boxm2_batch.run_process();
(id, type) = boxm2_batch.commit_output(0);
out_cam = dbvalue(id, type);
return out_cam
## use the affine cameras of the images to compute an affine fundamental matrix and rectify them (flatten epipolar lines to scan lines and align them)
## use the 3-d box that the cameras see to compute correspondences for minimally distortive alignment
def affine_rectify_images(img1, affine_cam1, img2, affine_cam2, min_x, min_y, min_z, max_x, max_y, max_z, n_points=100):
boxm2_batch.init_process("vpglAffineRectifyImagesProcess");
boxm2_batch.set_input_from_db(0, img1);
boxm2_batch.set_input_from_db(1, affine_cam1);
boxm2_batch.set_input_from_db(2, img2);
boxm2_batch.set_input_from_db(3, affine_cam2);
boxm2_batch.set_input_double(4, min_x);
boxm2_batch.set_input_double(5, min_y);
boxm2_batch.set_input_double(6, min_z);
boxm2_batch.set_input_double(7, max_x);
boxm2_batch.set_input_double(8, max_y);
boxm2_batch.set_input_double(9, max_z);
boxm2_batch.set_input_unsigned(10, n_points);
boxm2_batch.run_process();
(id, type) = boxm2_batch.commit_output(0);
out_img1 = dbvalue(id, type);
(id, type) = boxm2_batch.commit_output(1);
out_cam1 = dbvalue(id, type);
(id, type) = boxm2_batch.commit_output(2);
out_img2 = dbvalue(id, type);
(id, type) = boxm2_batch.commit_output(3);
out_cam2 = dbvalue(id, type);
return out_img1, out_cam1, out_img2, out_cam2