Skip to content

Commit

Permalink
Create readyaml.py
Browse files Browse the repository at this point in the history
  • Loading branch information
zsirui authored Mar 28, 2017
1 parent 717dcbd commit c6b5c79
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions 4/readyaml.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit c6b5c79

Please sign in to comment.