def test_classifier_clouds(tclsf, dictionary_name, image_resource, i, j, width, height, block_size, percent_cat_name, category_id_file=""): boxm2_batch.init_process("sdetTextureClassifySatelliteCloudsProcess"); boxm2_batch.set_input_from_db(0, tclsf); boxm2_batch.set_input_string(1, dictionary_name); boxm2_batch.set_input_from_db(2, image_resource); boxm2_batch.set_input_unsigned(3, i); boxm2_batch.set_input_unsigned(4, j); boxm2_batch.set_input_unsigned(5, width); boxm2_batch.set_input_unsigned(6, height); boxm2_batch.set_input_unsigned(7, block_size); boxm2_batch.set_input_string(8, category_id_file); boxm2_batch.set_input_string(9, percent_cat_name); status = boxm2_batch.run_process(); if status: (out_id, out_type)=boxm2_batch.commit_output(0); out_crop = dbvalue(out_id, out_type); (out_id, out_type)=boxm2_batch.commit_output(1); out_id_map = dbvalue(out_id, out_type); (out_id, out_type)=boxm2_batch.commit_output(2); out_rgb_map = dbvalue(out_id, out_type); (percent_id, percent_type) = boxm2_batch.commit_output(3); percent = boxm2_batch.get_output_float(percent_id); boxm2_batch.remove_data(percent_id) return out_crop, out_id_map, out_rgb_map, percent else: out_crop = 0; out_id_map = 0; out_rgb_map = 0; percent = 100; return out_crop, out_id_map, out_rgb_map, percent
def image_mean(img): boxm2_batch.init_process("vilImageMeanProcess") boxm2_batch.set_input_from_db(0, img) boxm2_batch.run_process() (id, type) = boxm2_batch.commit_output(0) mean_val = boxm2_batch.get_output_float(id) boxm2_batch.remove_data(id) return mean_val
def texture_classifier_kernel_margin(dictionary): boxm2_batch.init_process("sdetTextureClassifierKernelMarginProcess") boxm2_batch.set_input_string(0, dictionary) boxm2_batch.run_process() (m_id, m_type) = boxm2_batch.commit_output(0) margin = boxm2_batch.get_output_int(m_id) boxm2_batch.remove_data(m_id) return margin
def get_number_of_planes(img): boxm2_batch.init_process("vilGetNumberOfPlanesProcess") boxm2_batch.set_input_from_db(0, img) boxm2_batch.run_process() (id, type) = boxm2_batch.commit_output(0) n_planes = boxm2_batch.get_output_unsigned(id) boxm2_batch.remove_data(id) return n_planes
def img_sum(img, plane_index=0): boxm2_batch.init_process("vilImageSumProcess") boxm2_batch.set_input_from_db(0, img) boxm2_batch.set_input_unsigned(1, plane_index) boxm2_batch.run_process() (id, type) = boxm2_batch.commit_output(0) value = boxm2_batch.get_output_double(id) boxm2_batch.remove_data(id) return value
def sun_dir_bin(meta, illum_bin_filename): boxm2_batch.init_process("bradSunDirBinProcess") boxm2_batch.set_input_from_db(0, meta) boxm2_batch.set_input_string(1, illum_bin_filename) boxm2_batch.run_process() (id, type) = boxm2_batch.commit_output(0) bin = boxm2_batch.get_output_int(id) boxm2_batch.remove_data(id) return bin
def arf_stream(file_path): boxm2_batch.init_process("bilCreateArfImageIstreamProcess") boxm2_batch.set_input_string(0, file_path) boxm2_batch.run_process() (id, type) = boxm2_batch.commit_output(0) stream = dbvalue(id, type) (id, type) = boxm2_batch.commit_output(1) numImgs = boxm2_batch.get_output_int(id) boxm2_batch.remove_data(id) return stream, numImgs
def arf_next_frame(rawStream): boxm2_batch.init_process("bilArfReadFrameProcess") boxm2_batch.set_input_from_db(0, rawStream) boxm2_batch.run_process() (id, type) = boxm2_batch.commit_output(0) img = dbvalue(id, type) (id, type) = boxm2_batch.commit_output(1) time = boxm2_batch.get_output_unsigned(id) boxm2_batch.remove_data(id) return img, time
def pixel(img, point): boxm2_batch.init_process("vilPixelValueProcess") boxm2_batch.set_input_from_db(0, img) boxm2_batch.set_input_int(1, int(point[0])) boxm2_batch.set_input_int(2, int(point[1])) boxm2_batch.run_process() (id, type) = boxm2_batch.commit_output(0) val = boxm2_batch.get_output_float(id) boxm2_batch.remove_data(id) return val
def compute_camera_to_world_homography(cam,plane,inverse = False): boxm2_batch.init_process("vpglComputeImageToWorldHomographyProcess"); boxm2_batch.set_input_from_db(0, cam); boxm2_batch.set_input_float_array(1, plane); boxm2_batch.set_input_bool(2, inverse); boxm2_batch.run_process(); (id, type) = boxm2_batch.commit_output(0); homg2d = boxm2_batch.get_bbas_1d_array_float(id); boxm2_batch.remove_data(id) return homg2d
def mutual_information(img0, img1, mask): boxm2_batch.init_process('ihogMutualInformationProcess') boxm2_batch.set_input_from_db(0,img0) boxm2_batch.set_input_from_db(1,img1) boxm2_batch.set_input_from_db(2,mask) boxm2_batch.run_process() (id,type) = boxm2_batch.commit_output(0) minfo = boxm2_batch.get_output_float(id) boxm2_batch.remove_data(id) return minfo
def arf_seek_frame(rawStream, frame) : boxm2_batch.init_process("bilArfSeekFrameProcess") boxm2_batch.set_input_from_db(0,rawStream); boxm2_batch.set_input_unsigned(1,frame); boxm2_batch.run_process(); (id, type) = boxm2_batch.commit_output(0); img = dbvalue(id,type); (id, type) = boxm2_batch.commit_output(1); time = boxm2_batch.get_output_unsigned(id); boxm2_batch.remove_data(id); return img, time
def image_size(img): boxm2_batch.init_process('vilImageSizeProcess') boxm2_batch.set_input_from_db(0, img) boxm2_batch.run_process() (id, type) = boxm2_batch.commit_output(0) ni = boxm2_batch.get_output_unsigned(id) boxm2_batch.remove_data(id) (id, type) = boxm2_batch.commit_output(1) nj = boxm2_batch.get_output_unsigned(id) boxm2_batch.remove_data(id) return ni, nj
def image_range(img): boxm2_batch.init_process('vilImageRangeProcess') boxm2_batch.set_input_from_db(0, img) boxm2_batch.run_process() (id, type) = boxm2_batch.commit_output(0) minVal = boxm2_batch.get_output_float(id) boxm2_batch.remove_data(id) (id, type) = boxm2_batch.commit_output(1) maxVal = boxm2_batch.get_output_float(id) boxm2_batch.remove_data(id) return minVal, maxVal
def prepare_mask_image_from_vis_image(vis_image, ni2, nj2, threshold): img_1 = init_float_img(ni2, nj2, 1, -1.0) vis_image_neg = binary_img_op(img_1, vis_image, "sum") scale_and_offset_values(vis_image_neg, -1.0, 0.0) exp_img_mask_f = threshold_image(vis_image_neg, threshold) sum = img_sum(exp_img_mask_f) # print "mask sum: " + str(sum) + " ratio of true: " + str(sum/(ni2*nj2)); ratio = sum / (ni2 * nj2) * 100 exp_img_mask = stretch_image(exp_img_mask_f, 0, 1, 'byte') boxm2_batch.remove_data(exp_img_mask_f.id) return exp_img_mask, img_1, vis_image_neg, ratio
def sun_angles(image_path): boxm2_batch.init_process('bbasSunAnglesProcess') boxm2_batch.set_input_string(0,image_path) boxm2_batch.run_process() (id,type) = boxm2_batch.commit_output(0) sun_el = boxm2_batch.get_output_float(id) boxm2_batch.remove_data(id) (id,type) = boxm2_batch.commit_output(1) sun_az = boxm2_batch.get_output_float(id) boxm2_batch.remove_data(id) return(sun_az, sun_el)
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 get_sun_angles(mdata): boxm2_batch.init_process("bradGetSunAnglesProcess") boxm2_batch.set_input_from_db(0,mdata) boxm2_batch.run_process() (id,type) = boxm2_batch.commit_output(0) sun_az = boxm2_batch.get_output_float(id) boxm2_batch.remove_data(id) (id,type) = boxm2_batch.commit_output(1) sun_el = boxm2_batch.get_output_float(id) boxm2_batch.remove_data(id) return sun_az, sun_el
def estimate_irradiance(image, sun_z, mean_albedo=1.0): boxm2_batch.init_process('bbasEstimateIrradianceProcess') boxm2_batch.set_input_from_db(0,image) boxm2_batch.set_input_float(1,sun_z) boxm2_batch.set_input_float(2,mean_albedo) boxm2_batch.run_process() (id,type) = boxm2_batch.commit_output(0) img_float = dbvalue(id,type) (id,type) = boxm2_batch.commit_output(1) irrad = boxm2_batch.get_output_float(id) boxm2_batch.remove_data(id) return(img_float, irrad)
def compute_transformed_box(min_pt, max_pt, matrix_as_array): boxm2_batch.init_process("vpglTransformBoxProcess") boxm2_batch.set_input_double_array(0, min_pt) boxm2_batch.set_input_double_array(1, max_pt) boxm2_batch.set_input_double_array(2, matrix_as_array) boxm2_batch.run_process() (id, type) = boxm2_batch.commit_output(0) out_min_pt = boxm2_batch.get_output_double_array(id) boxm2_batch.remove_data(id) (id, type) = boxm2_batch.commit_output(1) out_max_pt = boxm2_batch.get_output_double_array(id) boxm2_batch.remove_data(id) return out_min_pt, out_max_pt
def load_image(file_path): boxm2_batch.init_process("vilLoadImageViewProcess") boxm2_batch.set_input_string(0, file_path) boxm2_batch.run_process() (id, type) = boxm2_batch.commit_output(0) (ni_id, ni_type) = boxm2_batch.commit_output(1) (nj_id, nj_type) = boxm2_batch.commit_output(2) ni = boxm2_batch.get_output_unsigned(ni_id) nj = boxm2_batch.get_output_unsigned(nj_id) img = dbvalue(id, type) boxm2_batch.remove_data(ni_id) boxm2_batch.remove_data(nj_id) return img, ni, nj
def load_image(file_path) : boxm2_batch.init_process("vilLoadImageViewProcess"); boxm2_batch.set_input_string(0, file_path); boxm2_batch.run_process(); (id,type) = boxm2_batch.commit_output(0); (ni_id, ni_type) = boxm2_batch.commit_output(1); (nj_id, nj_type) = boxm2_batch.commit_output(2); ni = boxm2_batch.get_output_unsigned(ni_id); nj = boxm2_batch.get_output_unsigned(nj_id); img = dbvalue(id,type); boxm2_batch.remove_data(ni_id) boxm2_batch.remove_data(nj_id) return img, ni, nj;
def bae_raw_stream(file_path, ni=0, nj=0, pixelsize=0): boxm2_batch.init_process("bilCreateRawImageIstreamProcess") boxm2_batch.set_input_string(0, file_path) boxm2_batch.set_input_int(1, ni) boxm2_batch.set_input_int(2, nj) boxm2_batch.set_input_int(3, pixelsize) boxm2_batch.run_process() (id, type) = boxm2_batch.commit_output(0) stream = dbvalue(id, type) (id, type) = boxm2_batch.commit_output(1) numImgs = boxm2_batch.get_output_int(id) boxm2_batch.remove_data(id) return stream, numImgs
def calculate_nitf_gsd(rational_cam, lon1, lat1, elev1, distance = 1000.0): # create a local lvcs lvcs = create_lvcs(lat1, lon1, elev1, 'wgs84') lat2, lon2, elev2 = convert_local_to_global_coordinates(lvcs, distance, distance, 0.0) # calculate image pixel difference i1, j1 = project_point(rational_cam, lon1, lat1, elev1) i2, j2 = project_point(rational_cam, lon2, lat2, elev2) gsd_i = distance / (i2-i1) gsd_j = distance / (j2-j1) if (gsd_i < 0.0): gsd_i = -1*gsd_i if (gsd_j < 0.0): gsd_j = -1*gsd_j boxm2_batch.remove_data(lvcs.id) return gsd_i, gsd_j
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); boxm2_batch.remove_data(id); (id, type) = boxm2_batch.commit_output(1); v = boxm2_batch.get_output_int(id); boxm2_batch.remove_data(id); return u, v;
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) boxm2_batch.remove_data(id) (id, type) = boxm2_batch.commit_output(1) v = boxm2_batch.get_output_int(id) boxm2_batch.remove_data(id) return u, v
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) boxm2_batch.remove_data(id) (id, type) = boxm2_batch.commit_output(1) phi = boxm2_batch.get_output_float(id) boxm2_batch.remove_data(id) return theta, phi
def camera_angles(camera, x, y, z): boxm2_batch.init_process('bbasCameraAnglesProcess') 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) cam_az = boxm2_batch.get_output_float(id) boxm2_batch.remove_data(id) (id, type) = boxm2_batch.commit_output(1) cam_el = boxm2_batch.get_output_float(id) boxm2_batch.remove_data(id) return (cam_az, cam_el)
def find_sun_dir_bin(metadata, output_file): boxm2_batch.init_process("bradSunDirBinProcess"); boxm2_batch.set_input_from_db(0,metadata) boxm2_batch.set_input_string(1,output_file); status = boxm2_batch.run_process(); bin, angle = None, None if status: (bin_id,bin_type)=boxm2_batch.commit_output(0); bin = boxm2_batch.get_output_int(bin_id); boxm2_batch.remove_data(bin_id); (angle_id,angle_type)=boxm2_batch.commit_output(1); angle = boxm2_batch.get_output_float(angle_id); boxm2_batch.remove_data(angle_id); return bin, angle
def find_sun_dir_bin(metadata, output_file): boxm2_batch.init_process("bradSunDirBinProcess") boxm2_batch.set_input_from_db(0, metadata) boxm2_batch.set_input_string(1, output_file) status = boxm2_batch.run_process() bin, angle = None, None if status: (bin_id, bin_type) = boxm2_batch.commit_output(0) bin = boxm2_batch.get_output_int(bin_id) boxm2_batch.remove_data(bin_id) (angle_id, angle_type) = boxm2_batch.commit_output(1) angle = boxm2_batch.get_output_float(angle_id) boxm2_batch.remove_data(angle_id) return bin, angle
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) boxm2_batch.remove_data(id) (id, type) = boxm2_batch.commit_output(1) v = boxm2_batch.get_output_float(id) boxm2_batch.remove_data(id) return (u, v)
def offset_cam_using_3d_box(camera, lower_left_lon, lower_left_lat, lower_left_elev, upper_right_lon, upper_right_lat, upper_right_elev, uncertainty, lvcs=None): boxm2_batch.init_process("vpglOffsetCamUsing3DboxProcess"); boxm2_batch.set_input_from_db(0, camera); boxm2_batch.set_input_double(1, lower_left_lon); boxm2_batch.set_input_double(2, lower_left_lat); boxm2_batch.set_input_double(3, lower_left_elev); boxm2_batch.set_input_double(4, upper_right_lon); boxm2_batch.set_input_double(5, upper_right_lat); boxm2_batch.set_input_double(6, upper_right_elev); boxm2_batch.set_input_double(7, uncertainty); if lvcs: boxm2_batch.set_input_from_db(8, lvcs); status = boxm2_batch.run_process(); if status: (id, type) = boxm2_batch.commit_output(0); local_cam = dbvalue(id, type); (id, type) = boxm2_batch.commit_output(1); i0 = boxm2_batch.get_output_unsigned(id) boxm2_batch.remove_data(id); (id, type) = boxm2_batch.commit_output(2); j0 = boxm2_batch.get_output_unsigned(id) boxm2_batch.remove_data(id); (id, type) = boxm2_batch.commit_output(3); ni = boxm2_batch.get_output_unsigned(id) boxm2_batch.remove_data(id); (id, type) = boxm2_batch.commit_output(4); nj = boxm2_batch.get_output_unsigned(id) boxm2_batch.remove_data(id); return status, local_cam, i0, j0, ni, nj; else: return status, dbvalue(0, ""), 0, 0, 0, 0;
def calculate_nitf_gsd(rational_cam, lon1, lat1, elev1, distance=1000.0): # create a local lvcs lvcs = create_lvcs(lat1, lon1, elev1, 'wgs84') lat2, lon2, elev2 = convert_local_to_global_coordinates( lvcs, distance, distance, 0.0) # calculate image pixel difference i1, j1 = project_point(rational_cam, lon1, lat1, elev1) i2, j2 = project_point(rational_cam, lon2, lat2, elev2) gsd_i = distance / (i2 - i1) gsd_j = distance / (j2 - j1) if (gsd_i < 0.0): gsd_i = -1 * gsd_i if (gsd_j < 0.0): gsd_j = -1 * gsd_j boxm2_batch.remove_data(lvcs.id) return gsd_i, gsd_j
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); boxm2_batch.remove_data(id); (id,type) = boxm2_batch.commit_output(1); phi=boxm2_batch.get_output_float(id); boxm2_batch.remove_data(id); return theta, phi;
def crop_image_using_3d_box(img_res, camera, lower_left_lon, lower_left_lat, lower_left_elev, upper_right_lon, upper_right_lat, upper_right_elev, uncertainty, lvcs=0): boxm2_batch.init_process("vpglCropImgUsing3DboxProcess") boxm2_batch.set_input_from_db(0, img_res) boxm2_batch.set_input_from_db(1, camera) boxm2_batch.set_input_double(2, lower_left_lon) boxm2_batch.set_input_double(3, lower_left_lat) boxm2_batch.set_input_double(4, lower_left_elev) boxm2_batch.set_input_double(5, upper_right_lon) boxm2_batch.set_input_double(6, upper_right_lat) boxm2_batch.set_input_double(7, upper_right_elev) boxm2_batch.set_input_double(8, uncertainty) if lvcs: boxm2_batch.set_input_from_db(9, lvcs) status = boxm2_batch.run_process() if status: (id, type) = boxm2_batch.commit_output(0) local_cam = dbvalue(id, type) (id, type) = boxm2_batch.commit_output(1) i0 = boxm2_batch.get_output_unsigned(id) boxm2_batch.remove_data(id) (id, type) = boxm2_batch.commit_output(2) j0 = boxm2_batch.get_output_unsigned(id) boxm2_batch.remove_data(id) (id, type) = boxm2_batch.commit_output(3) ni = boxm2_batch.get_output_unsigned(id) boxm2_batch.remove_data(id) (id, type) = boxm2_batch.commit_output(4) nj = boxm2_batch.get_output_unsigned(id) boxm2_batch.remove_data(id) return status, local_cam, i0, j0, ni, nj else: return status, dbvalue(0, ""), 0, 0, 0, 0
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); boxm2_batch.remove_data(id); (id,type) = boxm2_batch.commit_output(1); v = boxm2_batch.get_output_float(id); boxm2_batch.remove_data(id); return (u,v);
def load_image_resource(file_path): boxm2_batch.init_process("vilLoadImageResourceProcess") boxm2_batch.set_input_string(0, file_path) status = boxm2_batch.run_process() img_res = ni = nj = None if status: (id, type) = boxm2_batch.commit_output(0) (ni_id, ni_type) = boxm2_batch.commit_output(1) (nj_id, nj_type) = boxm2_batch.commit_output(2) ni = boxm2_batch.get_output_unsigned(ni_id) nj = boxm2_batch.get_output_unsigned(nj_id) img_res = dbvalue(id, type) boxm2_batch.remove_data(ni_id) boxm2_batch.remove_data(nj_id) return img_res, ni, nj
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); boxm2_batch.remove_data(theta_id); boxm2_batch.remove_data(phi_id); return pert_cam, theta, phi;
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) boxm2_batch.remove_data(theta_id) boxm2_batch.remove_data(phi_id) return pert_cam, theta, phi
def bbox_from_ply(filename): minpoint = list() maxpoint = list() boxm2_batch.init_process('imeshPlyBboxProcess') boxm2_batch.set_input_string(0, filename) boxm2_batch.run_process() for i in (0, 1, 2): (id, type) = boxm2_batch.commit_output(i) minpoint.append(boxm2_batch.get_output_double(id)) boxm2_batch.remove_data(id) for i in (3, 4, 5): (id, type) = boxm2_batch.commit_output(i) maxpoint.append(boxm2_batch.get_output_double(id)) boxm2_batch.remove_data(id) return (minpoint, maxpoint)
def probe_intensities(scene, cpu_cache, str_cache, point): boxm2_batch.init_process("boxm2CppBatchProbeIntensitiesProcess") boxm2_batch.set_input_from_db(0, scene) boxm2_batch.set_input_from_db(1, cpu_cache) boxm2_batch.set_input_from_db(2, str_cache) boxm2_batch.set_input_float(3, point[0]) boxm2_batch.set_input_float(4, point[1]) boxm2_batch.set_input_float(5, point[2]) boxm2_batch.run_process() (id, type) = boxm2_batch.commit_output(0) intensities = boxm2_batch.get_bbas_1d_array_float(id) boxm2_batch.remove_data(id) (id, type) = boxm2_batch.commit_output(1) visibilities = boxm2_batch.get_bbas_1d_array_float(id) boxm2_batch.remove_data(id) return intensities, visibilities
def compute_sun_affine_camera(scene, sun_az, sun_el, astro_coords=True): boxm2_batch.init_process("boxm2ComputeSunAffineCameraProcess") boxm2_batch.set_input_from_db(0, scene) boxm2_batch.set_input_float(1, sun_el) boxm2_batch.set_input_float(2, sun_az) boxm2_batch.set_input_bool(3, astro_coords) boxm2_batch.run_process() (id, type) = boxm2_batch.commit_output(0) sun_cam = dbvalue(id, type) (ni_id, type) = boxm2_batch.commit_output(1) (nj_id, type) = boxm2_batch.commit_output(2) ni = boxm2_batch.get_output_unsigned(ni_id) nj = boxm2_batch.get_output_unsigned(nj_id) boxm2_batch.remove_data(ni_id) boxm2_batch.remove_data(nj_id) return sun_cam, ni, nj
def get_sun_angles_date_time(lat, lon, year, month, day, hour, minute): boxm2_batch.init_process("bradGetSunAnglesDateTimeProcess") boxm2_batch.set_input_float(0, lat) boxm2_batch.set_input_float(1, lon) boxm2_batch.set_input_int(2, year) boxm2_batch.set_input_int(3, month) boxm2_batch.set_input_int(4, day) boxm2_batch.set_input_int(5, hour) boxm2_batch.set_input_int(6, minute) boxm2_batch.run_process() (id, type) = boxm2_batch.commit_output(0) sun_az = boxm2_batch.get_output_float(id) boxm2_batch.remove_data(id) (id, type) = boxm2_batch.commit_output(1) sun_el = boxm2_batch.get_output_float(id) boxm2_batch.remove_data(id) return sun_az, sun_el
def compute_transformation(pts0_xs, pts0_ys, pts0_zs, pts1_xs, pts1_ys, pts1_zs, input_cam_folder, output_cam_folder): boxm2_batch.init_process("vpglTransformSpaceProcess") boxm2_batch.set_input_double_array(0, pts0_xs) boxm2_batch.set_input_double_array(1, pts0_ys) boxm2_batch.set_input_double_array(2, pts0_zs) boxm2_batch.set_input_double_array(3, pts1_xs) boxm2_batch.set_input_double_array(4, pts1_ys) boxm2_batch.set_input_double_array(5, pts1_zs) boxm2_batch.set_input_string(6, input_cam_folder) boxm2_batch.set_input_string(7, output_cam_folder) boxm2_batch.run_process() (id, type) = boxm2_batch.commit_output(0) matrix_as_array = boxm2_batch.get_output_double_array(id) boxm2_batch.remove_data(id) (id, type) = boxm2_batch.commit_output(1) scale = boxm2_batch.get_output_double(id) boxm2_batch.remove_data(id) return matrix_as_array, scale
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) boxm2_batch.remove_data(id) (id, type) = boxm2_batch.commit_output(2) nj = boxm2_batch.get_output_unsigned(id) boxm2_batch.remove_data(id) (id, type) = boxm2_batch.commit_output(3) new_pers_cam = dbvalue(id, type) return (gcam, ni, nj, new_pers_cam)
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) 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
def estimate_radiance_values(image, sun_el, sun_dist, sensor_el, solar_irrad=None, downwelled_irrad=None, optical_depth=None): boxm2_batch.init_process("bradEstimateRadianceValuesProcess") boxm2_batch.set_input_from_db(0, image) boxm2_batch.set_input_float(1, sun_el) boxm2_batch.set_input_float(2, sun_dist) boxm2_batch.set_input_float(3, sensor_el) if solar_irrad != None: boxm2_batch.set_input_float(4, solar_irrad) if downwelled_irrad != None: boxm2_batch.set_input_float(5, downwelled_irrad) if optical_depth != None: boxm2_batch.set_input_float(6, optical_depth) boxm2_batch.run_process() (id, type) = boxm2_batch.commit_output(0) airlight = boxm2_batch.get_output_float(id) boxm2_batch.remove_data(id) (id, type) = boxm2_batch.commit_output(1) ref_horizontal = boxm2_batch.get_output_float(id) boxm2_batch.remove_data(id) (id, type) = boxm2_batch.commit_output(2) ref_sun_facing = boxm2_batch.get_output_float(id) boxm2_batch.remove_data(id) return (airlight, ref_horizontal, ref_sun_facing)
def test_classifier_clouds(tclsf, dictionary_name, image_resource, i, j, width, height, block_size, percent_cat_name, category_id_file=""): boxm2_batch.init_process("sdetTextureClassifySatelliteCloudsProcess") boxm2_batch.set_input_from_db(0, tclsf) boxm2_batch.set_input_string(1, dictionary_name) boxm2_batch.set_input_from_db(2, image_resource) boxm2_batch.set_input_unsigned(3, i) boxm2_batch.set_input_unsigned(4, j) boxm2_batch.set_input_unsigned(5, width) boxm2_batch.set_input_unsigned(6, height) boxm2_batch.set_input_unsigned(7, block_size) boxm2_batch.set_input_string(8, category_id_file) boxm2_batch.set_input_string(9, percent_cat_name) status = boxm2_batch.run_process() if status: (out_id, out_type) = boxm2_batch.commit_output(0) out_crop = dbvalue(out_id, out_type) (out_id, out_type) = boxm2_batch.commit_output(1) out_id_map = dbvalue(out_id, out_type) (out_id, out_type) = boxm2_batch.commit_output(2) out_rgb_map = dbvalue(out_id, out_type) (percent_id, percent_type) = boxm2_batch.commit_output(3) percent = boxm2_batch.get_output_float(percent_id) boxm2_batch.remove_data(percent_id) return out_crop, out_id_map, out_rgb_map, percent else: out_crop = 0 out_id_map = 0 out_rgb_map = 0 percent = 100 return out_crop, out_id_map, out_rgb_map, percent
def nitf_date_time(image_filename): boxm2_batch.init_process("vilNITFDateTimeProcess") boxm2_batch.set_input_string(0, image_filename) status = boxm2_batch.run_process() year = month = day = hour = minute = None if status: (id, type) = boxm2_batch.commit_output(0) year = boxm2_batch.get_output_int(id) boxm2_batch.remove_data(id) (id, type) = boxm2_batch.commit_output(1) month = boxm2_batch.get_output_int(id) boxm2_batch.remove_data(id) (id, type) = boxm2_batch.commit_output(2) day = boxm2_batch.get_output_int(id) boxm2_batch.remove_data(id) (id, type) = boxm2_batch.commit_output(3) hour = boxm2_batch.get_output_int(id) boxm2_batch.remove_data(id) (id, type) = boxm2_batch.commit_output(4) minute = boxm2_batch.get_output_int(id) boxm2_batch.remove_data(id) return year, month, day, hour, minute
def get_single_nitf_footprint(nitf_filename, out_kml_filename="", isKml=False, metafolder=""): boxm2_batch.init_process('vpglNITFFootprintProcess2') boxm2_batch.set_input_string(0, nitf_filename) boxm2_batch.set_input_string(1, out_kml_filename) boxm2_batch.set_input_bool(2, isKml) boxm2_batch.set_input_string(3, metafolder) boxm2_batch.run_process() (id, type) = boxm2_batch.commit_output(0) llon = boxm2_batch.get_output_double(id) (id, type) = boxm2_batch.commit_output(1) llat = boxm2_batch.get_output_double(id) (id, type) = boxm2_batch.commit_output(2) lele = boxm2_batch.get_output_double(id) (id, type) = boxm2_batch.commit_output(3) rlon = boxm2_batch.get_output_double(id) (id, type) = boxm2_batch.commit_output(4) rlat = boxm2_batch.get_output_double(id) (id, type) = boxm2_batch.commit_output(5) rele = boxm2_batch.get_output_double(id) boxm2_batch.remove_data(id) return llon, llat, lele, rlon, rlat, rele
def query_cell(scene, cache, point, model_name, model_type): #Point should be 3 len, for a x, y, z coordinate OR #4 in lenght, blk_i, blk_j, blk_k, index if len(point) == 3: (blk, index) = get_index_from_3d_point(scene, cache, point) point = blk + (index, ) boxm2_batch.init_process("boxm2CppQueryCellProcess") boxm2_batch.set_input_from_db(0, scene) boxm2_batch.set_input_from_db(1, cache) boxm2_batch.set_input_int(2, point[0]) boxm2_batch.set_input_int(3, point[1]) boxm2_batch.set_input_int(4, point[2]) boxm2_batch.set_input_int(5, point[3]) boxm2_batch.set_input_string(6, model_name) boxm2_batch.set_input_string(7, model_type) boxm2_batch.run_process() (id, type) = boxm2_batch.commit_output(0) data = boxm2_batch.get_bbas_1d_array_float(id) boxm2_batch.remove_data(id) return data
def sun_position(image_path): boxm2_batch.init_process('bbasSunAnglesProcess') boxm2_batch.set_input_string(0, image_path) boxm2_batch.run_process() (id, type) = boxm2_batch.commit_output(0) sun_el = boxm2_batch.get_output_float(id) boxm2_batch.remove_data(id) (id, type) = boxm2_batch.commit_output(1) sun_az = boxm2_batch.get_output_float(id) boxm2_batch.remove_data(id) (id, type) = boxm2_batch.commit_output(2) sun_dist = boxm2_batch.get_output_float(id) boxm2_batch.remove_data(id) return (sun_az, sun_el, sun_dist)
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) boxm2_batch.remove_data(x_id) (y_id, type) = boxm2_batch.commit_output(1) y = boxm2_batch.get_output_float(y_id) boxm2_batch.remove_data(y_id) (z_id, type) = boxm2_batch.commit_output(2) z = boxm2_batch.get_output_float(z_id) boxm2_batch.remove_data(z_id) return x, y, z
def blob_intersection(mp_img, gt_img): boxm2_batch.init_process("bripBlobIntersectionProcess") boxm2_batch.set_input_from_db(0, mp_img) boxm2_batch.set_input_from_db(1, gt_img) boxm2_batch.run_process() (id, type) = boxm2_batch.commit_output(0) tp = boxm2_batch.get_output_int(id) boxm2_batch.remove_data(id) (id, type) = boxm2_batch.commit_output(1) fp = boxm2_batch.get_output_int(id) boxm2_batch.remove_data(id) (id, type) = boxm2_batch.commit_output(2) numBlobs = boxm2_batch.get_output_int(id) boxm2_batch.remove_data(id) return (tp, fp, numBlobs)
def get_backprojected_ray(cam, u, v): boxm2_batch.init_process("vpglGetBackprojectRayProcess") boxm2_batch.set_input_from_db(0, cam) boxm2_batch.set_input_float(1, u) boxm2_batch.set_input_float(2, v) 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
def pixel_wise_roc(cd_img, gt_img, mask_img=None): boxm2_batch.init_process("vilPixelwiseRocProcess") boxm2_batch.set_input_from_db(0, cd_img) boxm2_batch.set_input_from_db(1, gt_img) if mask_img: boxm2_batch.set_input_from_db(2, mask_img) boxm2_batch.run_process() (id, type) = boxm2_batch.commit_output(0) tp = boxm2_batch.get_bbas_1d_array_float(id) boxm2_batch.remove_data(id) (id, type) = boxm2_batch.commit_output(1) tn = boxm2_batch.get_bbas_1d_array_float(id) boxm2_batch.remove_data(id) (id, type) = boxm2_batch.commit_output(2) fp = boxm2_batch.get_bbas_1d_array_float(id) boxm2_batch.remove_data(id) (id, type) = boxm2_batch.commit_output(3) fn = boxm2_batch.get_bbas_1d_array_float(id) boxm2_batch.remove_data(id) (id, type) = boxm2_batch.commit_output(6) outimg = dbvalue(id, type) # return tuple of true positives, true negatives, false positives, etc.. return (tp, tn, fp, fn, outimg)
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)
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)