Python cv2.FileStorage() Examples
The following are 7
code examples of cv2.FileStorage().
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: calibration_store.py From stereoDepth with Apache License 2.0 | 7 votes |
def load_stereo_coefficients(path): """ Loads stereo matrix coefficients. """ # FILE_STORAGE_READ cv_file = cv2.FileStorage(path, cv2.FILE_STORAGE_READ) # note we also have to specify the type to retrieve other wise we only get a # FileNode object back instead of a matrix K1 = cv_file.getNode("K1").mat() D1 = cv_file.getNode("D1").mat() K2 = cv_file.getNode("K2").mat() D2 = cv_file.getNode("D2").mat() R = cv_file.getNode("R").mat() T = cv_file.getNode("T").mat() E = cv_file.getNode("E").mat() F = cv_file.getNode("F").mat() R1 = cv_file.getNode("R1").mat() R2 = cv_file.getNode("R2").mat() P1 = cv_file.getNode("P1").mat() P2 = cv_file.getNode("P2").mat() Q = cv_file.getNode("Q").mat() cv_file.release() return [K1, D1, K2, D2, R, T, E, F, R1, R2, P1, P2, Q]
Example #2
Source File: lanenet_postprocess.py From lanenet-lane-detection with Apache License 2.0 | 6 votes |
def _load_remap_matrix(self): """ :return: """ fs = cv2.FileStorage(self._ipm_remap_file_path, cv2.FILE_STORAGE_READ) remap_to_ipm_x = fs.getNode('remap_ipm_x').mat() remap_to_ipm_y = fs.getNode('remap_ipm_y').mat() ret = { 'remap_to_ipm_x': remap_to_ipm_x, 'remap_to_ipm_y': remap_to_ipm_y, } fs.release() return ret
Example #3
Source File: calibration_store.py From stereoDepth with Apache License 2.0 | 6 votes |
def save_coefficients(mtx, dist, path): """ Save the camera matrix and the distortion coefficients to given path/file. """ cv_file = cv2.FileStorage(path, cv2.FILE_STORAGE_WRITE) cv_file.write("K", mtx) cv_file.write("D", dist) # note you *release* you don't close() a FileStorage object cv_file.release()
Example #4
Source File: calibration_store.py From stereoDepth with Apache License 2.0 | 6 votes |
def save_stereo_coefficients(path, K1, D1, K2, D2, R, T, E, F, R1, R2, P1, P2, Q): """ Save the stereo coefficients to given path/file. """ cv_file = cv2.FileStorage(path, cv2.FILE_STORAGE_WRITE) cv_file.write("K1", K1) cv_file.write("D1", D1) cv_file.write("K2", K2) cv_file.write("D2", D2) cv_file.write("R", R) cv_file.write("T", T) cv_file.write("E", E) cv_file.write("F", F) cv_file.write("R1", R1) cv_file.write("R2", R2) cv_file.write("P1", P1) cv_file.write("P2", P2) cv_file.write("Q", Q) cv_file.release()
Example #5
Source File: calibration_store.py From stereoDepth with Apache License 2.0 | 6 votes |
def load_coefficients(path): """ Loads camera matrix and distortion coefficients. """ # FILE_STORAGE_READ cv_file = cv2.FileStorage(path, cv2.FILE_STORAGE_READ) # note we also have to specify the type to retrieve other wise we only get a # FileNode object back instead of a matrix camera_matrix = cv_file.getNode("K").mat() dist_matrix = cv_file.getNode("D").mat() cv_file.release() return [camera_matrix, dist_matrix]
Example #6
Source File: common.py From lightnet with MIT License | 5 votes |
def add_argument(zoo, parser, name, help, required=False, default=None, type=None, action=None, nargs=None): if len(sys.argv) <= 1: return modelName = sys.argv[1] if os.path.isfile(zoo): fs = cv.FileStorage(zoo, cv.FILE_STORAGE_READ) node = fs.getNode(modelName) if not node.empty(): value = node.getNode(name) if not value.empty(): if value.isReal(): default = value.real() elif value.isString(): default = value.string() elif value.isInt(): default = int(value.real()) elif value.isSeq(): default = [] for i in range(value.size()): v = value.at(i) if v.isInt(): default.append(int(v.real())) elif v.isReal(): default.append(v.real()) else: print('Unexpected value format') exit(0) else: print('Unexpected field format') exit(0) required = False if action == 'store_true': default = 1 if default == 'true' else (0 if default == 'false' else default) assert(default is None or default == 0 or default == 1) parser.add_argument('--' + name, required=required, help=help, default=bool(default), action=action) else: parser.add_argument('--' + name, required=required, help=help, default=default, action=action, nargs=nargs, type=type)
Example #7
Source File: common.py From lightnet with MIT License | 5 votes |
def add_preproc_args(zoo, parser, sample): aliases = [] if os.path.isfile(zoo): fs = cv.FileStorage(zoo, cv.FILE_STORAGE_READ) root = fs.root() for name in root.keys(): model = root.getNode(name) if model.getNode('sample').string() == sample: aliases.append(name) parser.add_argument('alias', nargs='?', choices=aliases, help='An alias name of model to extract preprocessing parameters from models.yml file.') add_argument(zoo, parser, 'model', required=True, help='Path to a binary file of model contains trained weights. ' 'It could be a file with extensions .caffemodel (Caffe), ' '.pb (TensorFlow), .t7 or .net (Torch), .weights (Darknet), .bin (OpenVINO)') add_argument(zoo, parser, 'config', help='Path to a text file of model contains network configuration. ' 'It could be a file with extensions .prototxt (Caffe), .pbtxt or .config (TensorFlow), .cfg (Darknet), .xml (OpenVINO)') add_argument(zoo, parser, 'mean', nargs='+', type=float, default=[0, 0, 0], help='Preprocess input image by subtracting mean values. ' 'Mean values should be in BGR order.') add_argument(zoo, parser, 'scale', type=float, default=1.0, help='Preprocess input image by multiplying on a scale factor.') add_argument(zoo, parser, 'width', type=int, help='Preprocess input image by resizing to a specific width.') add_argument(zoo, parser, 'height', type=int, help='Preprocess input image by resizing to a specific height.') add_argument(zoo, parser, 'rgb', action='store_true', help='Indicate that model works with RGB input images instead BGR ones.') add_argument(zoo, parser, 'classes', help='Optional path to a text file with names of classes to label detected objects.')