From c6b5c79b2cc887bdf1b64d20a4cb4025363cb3df Mon Sep 17 00:00:00 2001 From: Ray Date: Tue, 28 Mar 2017 09:26:08 +0800 Subject: [PATCH] Create readyaml.py --- 4/readyaml.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 4/readyaml.py diff --git a/4/readyaml.py b/4/readyaml.py new file mode 100644 index 0000000..33a996b --- /dev/null +++ b/4/readyaml.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import yaml, sys +import numpy as np + +def fixYamlFile(filename): + with open(filename, 'rb') as f: + lines = f.readlines() + if lines[0] != '%YAML 1.0\n': + lines[0] = '%YAML 1.0\n' + for line in lines: + if ' !!opencv-matrix' in line: + lines[lines.index(line)] = line.split(' !!opencv-matrix')[0] + '\n' + with open(filename, 'wb') as fw: + fw.writelines(lines) + +def parseYamlFile(filename): + fixYamlFile(filename) + f = open(filename) + x = yaml.load(f) + f.close() + CameraIntrinsicData = np.array(x['camera_matrix']['data'], dtype = np.float32) + DistortionCoefficients = np.array(x['distortion_coefficients']['data'], dtype = np.float32) + return (CameraIntrinsicData.reshape(3, 3), DistortionCoefficients)