Source code for colorply.io.readxml

# -*- coding: utf-8 -*-
# Created on Sun Jul 14 10:17:54 2019
# @author: Cédric Perion | Arthur Dujardin

import warnings

warnings.warn("colorply.io.readxml module is deprecated. Use colorply.mm3d.functional instead.",
              DeprecationWarning)

import numpy as np
from lxml import etree


[docs]def read_orientation(nameIMGxml): """ This function extract the rotation matrix from the xml file. Parameters ---------- nameIMGxml : str the name of the file generated by MM3D. Usually, it is "Orientation-Im[n°i].JPG.xml" Returns ------- numpy.ndarray: the rotation of the img (size 3*3) """ tree = etree.parse(nameIMGxml) # The lines of the matrix for user in tree.xpath("/ExportAPERO/OrientationConique/Externe/ParamRotation/CodageMatr/L1"): # print(user.text) L1 = user.text.split(" ") for user in tree.xpath("/ExportAPERO/OrientationConique/Externe/ParamRotation/CodageMatr/L2"): # print(user.text) L2 = user.text.split(" ") for user in tree.xpath("/ExportAPERO/OrientationConique/Externe/ParamRotation/CodageMatr/L3"): # print(user.text) L3 = user.text.split(" ") matrix_rotation = np.array([L1, L2, L3], float) return matrix_rotation
[docs]def read_S(nameIMGxml): """ This function extract the images's center from the xml file. Parameters ---------- nameIMGxml : str the name of the file generated by MM3D. Usually, it is "Orientation-Im[n°i].JPG.xml" Returns ------- numpy.ndarray: the center of the IMG (size 1*3) """ tree = etree.parse(nameIMGxml) for user in tree.xpath("/ExportAPERO/OrientationConique/Externe/Centre"): # print(user.text) S = user.text.split(" ") center = np.array(S, float) return np.transpose(center)
[docs]def read_ori(nameIMGxml): """ This function extract the rotation matrix from the xml file and extract the images's center from the xml file. Parameters ---------- nameIMGxml : str the name of the file generated by MM3D. Usually, it is "Orientation-Im[n°i].JPG.xml" Returns ------- tuple : the rotation of the img, the center of the IMG, (matrix rotation, coord S). """ tree = etree.parse(nameIMGxml) # The lines of the matrix for user in tree.xpath("/ExportAPERO/OrientationConique/Externe/ParamRotation/CodageMatr/L1"): # print(user.text) L1 = user.text.split(" ") for user in tree.xpath("/ExportAPERO/OrientationConique/Externe/ParamRotation/CodageMatr/L2"): # print(user.text) L2 = user.text.split(" ") for user in tree.xpath("/ExportAPERO/OrientationConique/Externe/ParamRotation/CodageMatr/L3"): # print(user.text) L3 = user.text.split(" ") matrix_rotation = np.array([L1, L2, L3], float) for user in tree.xpath("/ExportAPERO/OrientationConique/Externe/Centre"): # print(user.text) S = user.text.split(" ") center = np.array(S, float) return matrix_rotation, center
##
[docs]def read_calib_F(calibxml): """ This function extract the calibration parameters from the xml file. Parameters ---------- calibxml : str the name of the calibration file generated by MM3D. (ex: "AutoCal_Foc-24000_Cam-DSLRA850.xml") Returns ------- numpy.ndarray: coordinates of the point F (focale, units : pix), (size 1*) """ tree = etree.parse(calibxml) for user in tree.xpath("/ExportAPERO/CalibrationInternConique/PP"): PP = user.text.split(" ") for user in tree.xpath("/ExportAPERO/CalibrationInternConique/F"): F = user.text PP.append("-" + F) return np.transpose(np.array(PP, float))
[docs]def read_calib_PPS(calibxml): """ This function extract the calibration parameters from the xml file. Parameters ---------- calibxml : str the name of the calibration file generated by MM3D (ex: "AutoCal_Foc-24000_Cam-DSLRA850.xml"). Returns ------- numpy.ndarray: coordinates of the PPS (size 1*3) """ tree = etree.parse(calibxml) for user in tree.xpath("/ExportAPERO/CalibrationInternConique/CalibDistortion/ModRad/CDist"): PPS = user.text.split(" ") PPS.append("0") print(PPS) return np.transpose(np.array(PPS, float))
[docs]def read_calib_distorsion(calibxml): """ This function extract the calibration parameters from the xml file. Parameters ---------- calibxml : str the name of the calibration file generated by MM3D (ex: "AutoCal_Foc-24000_Cam-DSLRA850.xml"). Returns ------- numpy.ndarray: distorsion coefficients a, b, c (size 1*3) """ tree = etree.parse(calibxml) coeffDist = [] for user in tree.xpath("/ExportAPERO/CalibrationInternConique/CalibDistortion/ModRad/CoeffDist"): coeffDist.append(user.text) return np.array(coeffDist, float)
##
[docs]def read_size(calibxml): """ This function extract the size of an image from the xml file. Parameters ---------- calibxml : str the name of the calibration file generated by MM3D. Returns ------- numpy.ndarray: the size of the image resolution """ tree = etree.parse(calibxml) for user in tree.xpath("/ExportAPERO/CalibrationInternConique/SzIm"): size = user.text.split(" ") return np.array(size, int)
[docs]def read_calib(calibxml): """ This function extract the calibration parameters from the xml file. Parameters ---------- calibxml : str the name of the calibration file generated by MM3D (ex: "AutoCal_Foc-24000_Cam-DSLRA850.xml") Returns ------- tuple : F, PPS, distorsion coefficients a, b, c, size """ tree = etree.parse(calibxml) coeffDist = [] for user in tree.xpath("/ExportAPERO/CalibrationInternConique/CalibDistortion/ModRad/CoeffDist"): coeffDist.append(user.text) coeffDist = np.array(coeffDist, float) for user in tree.xpath("/ExportAPERO/CalibrationInternConique/CalibDistortion/ModRad/CDist"): PPS = user.text.split(" ") PPS.append("0") PPS = np.array(PPS, float) for user in tree.xpath("/ExportAPERO/CalibrationInternConique/PP"): PP = user.text.split(" ") for user in tree.xpath("/ExportAPERO/CalibrationInternConique/F"): F = user.text PP.append("-" + F) F = np.array(PP, float) for user in tree.xpath("/ExportAPERO/CalibrationInternConique/SzIm"): size = user.text.split(" ") size = np.array(size, int) return F, PPS, coeffDist, size