Python cv2.IMREAD_ANYDEPTH Examples
The following are 30
code examples of cv2.IMREAD_ANYDEPTH().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
cv2
, or try the search function
.
Example #1
Source File: doc3dwc_loader.py From DewarpNet with MIT License | 7 votes |
def __getitem__(self, index): im_name = self.files[self.split][index] # 1/824_8-cp_Page_0503-7Nw0001 im_path = pjoin(self.root, 'img', im_name + '.png') lbl_path=pjoin(self.root, 'wc', im_name + '.exr') im = m.imread(im_path,mode='RGB') im = np.array(im, dtype=np.uint8) lbl = cv2.imread(lbl_path, cv2.IMREAD_ANYCOLOR | cv2.IMREAD_ANYDEPTH) lbl = np.array(lbl, dtype=np.float) if 'val' in self.split: im, lbl=tight_crop(im/255.0,lbl) if self.augmentations: #this is for training, default false for validation\ tex_id=random.randint(0,len(self.txpths)-1) txpth=self.txpths[tex_id] tex=cv2.imread(os.path.join(self.root[:-7],txpth)).astype(np.uint8) bg=cv2.resize(tex,self.img_size,interpolation=cv2.INTER_NEAREST) im,lbl=data_aug(im,lbl,bg) if self.is_transform: im, lbl = self.transform(im, lbl) return im, lbl
Example #2
Source File: process.py From deepdiy with MIT License | 6 votes |
def run_tiff(file_path,progress_percent): progress_percent angle = 0 ret,video=cv2.imreadmulti(file_path,flags=cv2.IMREAD_ANYDEPTH) video_labeled,table=[],[] idx=1 for frame in video[:]: img_label,angle_new=process(frame) angle_new = float('{0:.2f}'.format(angle_new)) rotation=cal_rotation(angle,angle_new) rotation = float('{0:.2f}'.format(rotation)) table.append([angle,rotation,angle_new]) video_labeled.append(img_label) angle=angle_new idx+=1 progress_percent['value']=idx/len(video)*100 # print(table[-1]) # cv2.imshow('img',cv2.resize(img_label,(512,512))) # if cv2.waitKey(0) & 0xFF == ord('q'): # break return video_labeled,table
Example #3
Source File: dataset_util.py From Gated2Depth with MIT License | 6 votes |
def read_gated_image(base_dir, gta_pass, img_id, data_type, num_bits=10, scale_images=False, scaled_img_width=None, scaled_img_height=None, normalize_images=False): gated_imgs = [] normalizer = 2 ** num_bits - 1. for gate_id in range(3): gate_dir = os.path.join(base_dir, gta_pass, 'gated%d_10bit' % gate_id) img = cv2.imread(os.path.join(gate_dir, img_id + '.png'), cv2.IMREAD_ANYCOLOR | cv2.IMREAD_ANYDEPTH) if data_type == 'real': img = img[crop_size:(img.shape[0] - crop_size), crop_size:(img.shape[1] - crop_size)] img = img.copy() img[img > 2 ** 10 - 1] = normalizer img = np.float32(img / normalizer) gated_imgs.append(np.expand_dims(img, axis=2)) img = np.concatenate(gated_imgs, axis=2) if normalize_images: mean = np.mean(img, axis=2, keepdims=True) std = np.std(img, axis=2, keepdims=True) img = (img - mean) / (std + np.finfo(float).eps) if scale_images: img = cv2.resize(img, dsize=(scaled_img_width, scaled_img_height), interpolation=cv2.INTER_AREA) return np.expand_dims(img, axis=0)
Example #4
Source File: io.py From pydlt with BSD 3-Clause Clear License | 6 votes |
def imread(filename): """Reads an image file from disk into a Numpy Array (OpenCV view). Args: filename (str): Name of pfm image file. """ filename = process(filename) ext = os.path.splitext(filename)[1] if ext.lower() == '.pfm': return load_pfm(filename) elif ext.lower() == '.dng': return load_dng(filename) else: loaded = cv2.imread(filename, flags=cv2.IMREAD_ANYDEPTH + cv2.IMREAD_COLOR) if loaded is None: raise IOError('Could not read {0}'.format(filename)) else: return loaded
Example #5
Source File: depth_fill.py From sanet_relocal_demo with GNU General Public License v3.0 | 5 votes |
def read_7scenese_depth(png_file_path): depth = cv2.imread(png_file_path, cv2.IMREAD_ANYDEPTH).astype(np.float32) depth[depth >= 65535] = 0 return depth / 1000.0
Example #6
Source File: test_flownet_2012.py From DF-Net with MIT License | 5 votes |
def get_flow(path): bgr = cv2.imread(path, cv2.IMREAD_ANYCOLOR | cv2.IMREAD_ANYDEPTH) invalid = bgr[:, :, 0] == 0 out_flow = (bgr[:, :, 2:0:-1].astype('f4') - 2**15) / 64. out_flow[invalid] = 0 return out_flow, bgr[:, :, 0]
Example #7
Source File: test_flownet_2015.py From DF-Net with MIT License | 5 votes |
def get_flow(path): bgr = cv2.imread(path, cv2.IMREAD_ANYCOLOR | cv2.IMREAD_ANYDEPTH) invalid = bgr[:, :, 0] == 0 out_flow = (bgr[:, :, 2:0:-1].astype('f4') - 2**15) / 64. out_flow[invalid] = 0 return out_flow, bgr[:, :, 0]
Example #8
Source File: depth_io.py From sanet_relocal_demo with GNU General Public License v3.0 | 5 votes |
def load_depth_from_tiff(tiff_file_path, div_factor=1000.0): depth = cv2.imread(tiff_file_path, cv2.IMREAD_ANYDEPTH).astype(np.float32) return depth / div_factor
Example #9
Source File: depth_io.py From sanet_relocal_demo with GNU General Public License v3.0 | 5 votes |
def load_depth_from_png(png_file_path, div_factor=1000.0): depth = cv2.imread(png_file_path, cv2.IMREAD_ANYDEPTH).astype(np.float32) return depth / div_factor
Example #10
Source File: read_util.py From sanet_relocal_demo with GNU General Public License v3.0 | 5 votes |
def read_7scenese_depth(png_file_path): depth = cv2.imread(png_file_path, cv2.IMREAD_ANYDEPTH).astype(np.float32) depth[depth >= 65535] = 0 return depth / 1000.0
Example #11
Source File: read_util.py From sanet_relocal_demo with GNU General Public License v3.0 | 5 votes |
def read_7scenese_depth(png_file_path): depth = cv2.imread(png_file_path, cv2.IMREAD_ANYDEPTH).astype(np.float32) depth[depth >= 65535] = 0 return depth / 1000.0
Example #12
Source File: read_util.py From sanet_relocal_demo with GNU General Public License v3.0 | 5 votes |
def read_sun3d_depth(filename, min_depth_thres=1e-5): """ Read depth from a sun3d depth file :param filename: str :return depth as np.float32 array """ depth_pil = cv2.imread(filename, cv2.IMREAD_ANYDEPTH).astype(np.uint16) depth_shifted = (depth_pil >> 3) | (depth_pil << 13) depth_shifted = depth_shifted.astype(np.float32) depth_float = (depth_shifted / 1000) # depth_float[depth_float < min_depth_thres] = min_depth_thres return depth_float
Example #13
Source File: gen_lmdb_cache.py From sanet_relocal_demo with GNU General Public License v3.0 | 5 votes |
def read_raw_depth_uint16(filename): depth_pil = cv2.imread(filename, cv2.IMREAD_ANYDEPTH).astype(np.uint16) depth_shifted = (depth_pil >> 3) | (depth_pil << 13) return depth_shifted
Example #14
Source File: gen_lmdb_cache.py From sanet_relocal_demo with GNU General Public License v3.0 | 5 votes |
def read_depth(self, depth_key, min_depth_thres=1e-5): depth_str = np.fromstring(self.read_by_key(depth_key), dtype=np.uint8) depth = np.asarray(cv2.imdecode(depth_str, cv2.IMREAD_ANYDEPTH)).reshape((240, 320)) # print(depth.dtype) depth = depth.astype(np.float32) depth = (depth / 1000) # depth[depth < min_depth_thres] = min_depth_thres return depth
Example #15
Source File: util.py From in-silico-labeling with Apache License 2.0 | 5 votes |
def read_image(path: str) -> np.ndarray: """Reads a 16-bit grayscale image and converts to floating point.""" logging.info('Reading image: %s', path) image = cv2.imread(path, cv2.IMREAD_ANYDEPTH) assert image is not None assert len(image.shape) == 2, image.shape assert image.dtype == np.uint8 or image.dtype == np.uint16 image = image.astype(np.float32) / np.iinfo(image.dtype).max assert image.min() >= 0, image.min() assert image.max() <= 1.0, image.max() return image
Example #16
Source File: obj_utils.py From monopsr with MIT License | 5 votes |
def get_stereo_point_cloud(sample_name, calib_dir, disp_dir): """ Gets the point cloud for an image calculated from the disparity map :param sample_name: sample name :param calib_dir: directory with calibration files :param disp_dir: directory with disparity images :return: (3, N) point_cloud in the form [[x,...][y,...][z,...]] """ # Read calibration info frame_calib = calib_utils.get_frame_calib(calib_dir, sample_name) stereo_calibration_info = calib_utils.get_stereo_calibration(frame_calib.p2, frame_calib.p3) # Read disparity disp = cv2.imread(disp_dir + '/{}.png'.format(sample_name), cv2.IMREAD_ANYDEPTH) disp = np.float32(disp) disp = np.divide(disp, 256) disp[disp == 0] = 0.1 # Calculate the point cloud point_cloud = calib_utils.depth_from_disparity(disp, stereo_calibration_info) return point_cloud
Example #17
Source File: calib_utils.py From monopsr with MIT License | 5 votes |
def read_disparity(disp_dir, img_idx): """Reads in Disparity file from Kitti Dataset. Keyword Arguments: ------------------ calib_dir : Str Directory of the disparity files. img_idx : Int Index of the image. Returns: -------- disp_img : Numpy Array Contains the disparity image. [] : if file is not found """ disp_path = disp_dir + "/%06d_left_disparity.png" % img_idx if os.path.exists(disp_path): disp_img = cv2.imread(disp_path, cv2.IMREAD_ANYDEPTH) return disp_img else: raise FileNotFoundError('Disparity map not found')
Example #18
Source File: depth_map_utils.py From monopsr with MIT License | 5 votes |
def read_depth_map(depth_map_path): depth_image = cv2.imread(depth_map_path, cv2.IMREAD_ANYDEPTH) depth_map = depth_image / 256.0 # Discard depths less than 10cm from the camera depth_map[depth_map < 0.1] = 0.0 return depth_map.astype(np.float32)
Example #19
Source File: dataset_360D.py From SphericalViewSynthesis with BSD 2-Clause "Simplified" License | 5 votes |
def loadItemMono(self, idx): item = {} if (idx >= self.length): print("Index [{}] out of range. Dataset length: {}".format(idx, self.length)) else: dtmp = np.array(cv2.imread(self.sample["leftDepth"][idx], cv2.IMREAD_ANYDEPTH)) left_depth = torch.from_numpy(dtmp) left_depth.unsqueeze_(0) if self.rescaled: dtmp2 = cv2.resize(dtmp, (dtmp.shape[1] // 2, dtmp.shape[0] // 2)) dtmp4 = cv2.resize(dtmp, (dtmp.shape[1] // 4, dtmp.shape[0] // 4)) left_depth2 = torch.from_numpy(dtmp2) left_depth2.unsqueeze_(0) left_depth4 = torch.from_numpy(dtmp4) left_depth4.unsqueeze_(0) pilRGB = Image.open(self.sample["leftRGB"][idx]) rgb = self.pilToTensor(pilRGB) if self.rescaled: rgb2 = self.pilToTensor(self.resize2(pilRGB)) rgb4 = self.pilToTensor(self.resize4(pilRGB)) item = { "leftRGB": rgb, "leftRGB2": rgb2, "leftRGB4": rgb4, "leftDepth": left_depth, "leftDepth2": left_depth2, "leftDepth4": left_depth4, "leftDepth_filename": os.path.basename(self.sample["leftDepth"][idx][:-4]) } if self.rescaled else { "leftRGB": rgb, "leftDepth": left_depth, "leftDepth_filename": os.path.basename(self.sample["leftDepth"][idx][:-4]) } return item # loads sample from dataset lr mode
Example #20
Source File: util.py From hdr-expandnet with BSD 3-Clause Clear License | 5 votes |
def __getitem__(self, index): dpoint = cv2.imread( self.file_list[index], flags=cv2.IMREAD_ANYDEPTH + cv2.IMREAD_COLOR ) if self.preprocess is not None: dpoint = self.preprocess(dpoint) return dpoint
Example #21
Source File: create_kitti_tf_record.py From motion-rcnn with MIT License | 5 votes |
def _read_flow(flow_fn): "Convert from .png to (h, w, 2) (flow_x, flow_y) float32 array" # read png to bgr in 16 bit unsigned short bgr = cv2.imread(flow_fn, cv2.IMREAD_ANYCOLOR | cv2.IMREAD_ANYDEPTH) rgb = cv2.cvtColor(bgr, cv2.COLOR_BGR2RGB) h, w, _c = rgb.shape assert rgb.dtype == np.uint16 and _c == 3 invalid = rgb[:, :, 2] == 0 # g,r == flow_y,x normalized by height,width and scaled to [0;2**16 - 1] out_flow = (rgb[:, :, :2] - 2 ** 15) / 64.0 print(out_flow.shape, invalid.shape) out_flow[invalid] = np.nan # 0 or another value (e.g., np.nan) return out_flow
Example #22
Source File: create_kitti_tf_record.py From motion-rcnn with MIT License | 5 votes |
def _read_image(filename, rgb=False): "Read (h, w, 3) image from .png." if not rgb: with open(filename, 'rb') as f: image = f.read() return image image = cv2.imread(filename, cv2.IMREAD_ANYCOLOR | cv2.IMREAD_ANYDEPTH) h, w, _c = image.shape assert image.dtype == np.uint8 and _c == 3 if rgb: image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) return image
Example #23
Source File: create_kitti_tf_record.py From motion-rcnn with MIT License | 5 votes |
def _read_disparity_image(filename): "Read (h, w, 1) uint16 KITTI disparity image from .png." image = cv2.imread(filename, cv2.IMREAD_ANYCOLOR | cv2.IMREAD_ANYDEPTH) h, w = image.shape[:2] assert image.dtype == np.uint16 and len(image.shape) == 2 return image
Example #24
Source File: create_vkitti_tf_record.py From motion-rcnn with MIT License | 5 votes |
def _read_flow(flow_fn): "Convert from .png to (h, w, 2) (flow_x, flow_y) float32 array" # read png to bgr in 16 bit unsigned short bgr = cv2.imread(flow_fn, cv2.IMREAD_ANYCOLOR | cv2.IMREAD_ANYDEPTH) h, w, _c = bgr.shape assert bgr.dtype == np.uint16 and _c == 3 # b == invalid flow flag == 0 for sky or other invalid flow invalid = bgr[..., 0] == 0 # g,r == flow_y,x normalized by height,width and scaled to [0;2**16 - 1] out_flow = 2.0 / (2**16 - 1.0) * bgr[..., 2:0:-1].astype('f4') - 1 out_flow[..., 0] *= w - 1 out_flow[..., 1] *= h - 1 out_flow[invalid] = np.nan # 0 or another value (e.g., np.nan) return out_flow
Example #25
Source File: create_vkitti_tf_record.py From motion-rcnn with MIT License | 5 votes |
def _read_image(filename, rgb=False): "Read (h, w, 3) image from .png." if not rgb: with open(filename, 'rb') as f: image = f.read() return image image = cv2.imread(filename, cv2.IMREAD_ANYCOLOR | cv2.IMREAD_ANYDEPTH) h, w, _c = image.shape assert image.dtype == np.uint8 and _c == 3 if rgb: image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) return image
Example #26
Source File: nyuv2.py From DeepV2D with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __getitem__(self, index): data_blob = self.dataset_index[index] num_frames = data_blob['n_frames'] num_samples = self.n_frames inds = np.random.choice(num_frames, num_samples, replace=False) keyframe_index = inds[0] images = [] for i in inds: image_file = data_blob['images'][i] images.append(cv2.imread(image_file)) depth_file = data_blob['depths'][keyframe_index] depth = cv2.imread(depth_file, cv2.IMREAD_ANYDEPTH) depth = (depth.astype(np.float32)) / 5000.0 filled = fill_depth(depth) frameid = data_blob['ids'][keyframe_index] frameid = np.int32(frameid) poses = [] for i in inds: pose_vec = data_blob['poses'][i] pose_mat = pose_vec2mat(pose_vec) poses.append(np.linalg.inv(pose_mat)) images = np.stack(images, axis=0).astype(np.uint8) poses = np.stack(poses, axis=0).astype(np.float32) kvec = intrinsics.copy() return images, poses, depth, filled, filled, kvec, frameid
Example #27
Source File: utls.py From MBLLEN with Apache License 2.0 | 5 votes |
def imread_color(path): img = cv.imread(path, cv.IMREAD_COLOR | cv.IMREAD_ANYDEPTH) / 255. b, g, r = cv.split(img) img_rgb = cv.merge([r, g, b]) return img_rgb # return scipy.misc.imread(path, mode='RGB').astype(np.float) / 255.
Example #28
Source File: dataset_sparsity.py From ip_basic with MIT License | 5 votes |
def main(): input_depth_dir = os.path.expanduser( '~/Kitti/depth/val_selection_cropped/velodyne_raw') images_to_use = sorted(glob.glob(input_depth_dir + '/*')) # Process depth images num_images = len(images_to_use) all_sparsities = np.zeros(num_images) for i in range(num_images): # Print progress sys.stdout.write('\rProcessing index {} / {}'.format(i, num_images - 1)) sys.stdout.flush() depth_image_path = images_to_use[i] # Load depth from image depth_image = cv2.imread(depth_image_path, cv2.IMREAD_ANYDEPTH) # Divide by 256 depth_map = depth_image / 256.0 num_valid_pixels = len(np.where(depth_map > 0.0)[0]) num_pixels = depth_image.shape[0] * depth_image.shape[1] sparsity = num_valid_pixels / (num_pixels * 2/3) all_sparsities[i] = sparsity print('') print('Sparsity') print('Min: ', np.amin(all_sparsities)) print('Max: ', np.amax(all_sparsities)) print('Mean: ', np.mean(all_sparsities)) print('Median: ', np.median(all_sparsities)) plt.hist(all_sparsities, bins=20) plt.show()
Example #29
Source File: distill_dataset.py From Learning-Monocular-Depth-by-Stereo with MIT License | 5 votes |
def read_image_scale(image_path, scale): img = cv2.imread(image_path, cv2.IMREAD_ANYDEPTH) if img is None: print("not finding {}".format(image_path)) img = img.astype(np.float32) / scale return img
Example #30
Source File: create_npy.py From vkitti3D-dataset with MIT License | 5 votes |
def process_frame(image_path: str) -> Tuple[np.ndarray, np.ndarray, str, str]: """ fix given frame :param image_path: path to frame which should be fixed :return: fixed frame """ seq_no = image_path.split('/')[-3] img_no = image_path.split('/')[-1].split('.')[0] depth_path = f"{depth_root}/{seq_no}/clone/{img_no}.png" semantic_path = f"{labels_root}/{seq_no}/clone/{img_no}.png" # BGR -> RGB rgb_map = cv2.imread(image_path)[:, :, (2, 1, 0)] # convert centimeters to meters depth_map = cv2.imread(depth_path, cv2.IMREAD_ANYCOLOR | cv2.IMREAD_ANYDEPTH) / 100. # semantic image semantic_map = cv2.imread(semantic_path)[:, :, (2, 1, 0)] label_map = np.apply_along_axis(lambda r: rgb2label[tuple(r)], 2, semantic_map) # backprojection to camera space x3 = (xv - center_x) / focal_x * depth_map y3 = (yv - center_y) / focal_y * depth_map erg = np.stack((depth_map, -x3, -y3), axis=-1).reshape((-1, 3)) erg = np.hstack((erg, rgb_map.reshape(-1, 3), label_map.reshape(-1, 1))) # delete sky points erg = distance_cutoff(erg, g_cutoff) if g_is_v1: return None, erg, seq_no, img_no else: erg = remove_car_shadows(erg, img_no, g_bb_eps) worldspace = transform2worldspace(erg, img_no) return worldspace, erg, seq_no, img_no