Ciclop开源3D扫描仪软件---Horus源码分析之src\horus\engine\calibration\calibration_data.py

来源:互联网 发布:java开发是做什么的 编辑:程序博客网 时间:2024/05/20 08:27
/****************************************************************************/
 *
 *                  (c)    光明工作室  2017-2037  COPYRIGHT
 *
 *   光明工作室团队成员大部分来自全国著名985、211工程院校。具有丰富的工程实践经验,
 *本工作室热忱欢迎大家的光临。工作室长期承接嵌入式开发、PCB设计、算法仿真等软硬件设计。
 *
 *
 *1)基于C8051、AVR、MSP430单片机开发。
 *2)基于STM32F103、STM32F407等ARM处理器开发。(IIC、SPI、485、WIFI等相关设计)
 *3)基于C6678、DM388等DSP处理器开发。(视频、网络、通信协议相关设计)
 *4)基于QT、C#软件开发。
 *5)基于OPENCV、OPENGL图像处理算法开发。(基于LINUX、WINDOWS、MATLAB等)
 *6)无人机飞控、地面站程序开发。(大疆、PIX、 qgroundcontrol、missionplanner、MAVLINK)
 *7) ROS机器人操作系统下相关开发。
 *8)LINUX、UCOSII、VXWORKS操作系统开发。
 *
 *
 *                                                 联系方式:
 *                                                 QQ:2468851091 call:18163325140
 *                                                 Email:2468851091@qq.com
 *

/ ****************************************************************************/ 




# -*- coding: utf-8 -*-# This file is part of the Horus Project__author__ = 'Jes煤s Arroyo Torrens <jesus.arroyo@bq.com>'__copyright__ = 'Copyright (C) 2014-2016 Mundo Reader S.L.'__license__ = 'GNU General Public License v2 http://www.gnu.org/licenses/gpl2.html'import md5import cv2import numpy as npfrom horus import Singletonclass LaserPlane(object):    def __init__(self):        self.normal = None        self.distance = None@Singletonclass CalibrationData(object):    def __init__(self):        self.width = 0        self.height = 0        self._camera_matrix = None        self._distortion_vector = None        self._roi = None        self._dist_camera_matrix = None        self._weight_matrix = None        self._md5_hash = None        self.laser_planes = [LaserPlane(), LaserPlane()]        self.platform_rotation = None        self.platform_translation = None    def set_resolution(self, width, height):        if self.width != width or self.height != height:            self.width = width            self.height = height            self._compute_weight_matrix()    @property    def camera_matrix(self):        return self._camera_matrix    @camera_matrix.setter    def camera_matrix(self, value):        self._camera_matrix = value        self._compute_dist_camera_matrix()    @property    def distortion_vector(self):        return self._distortion_vector    @distortion_vector.setter    def distortion_vector(self, value):        self._distortion_vector = value        self._compute_dist_camera_matrix()    @property    def roi(self):        return self._roi    @property    def dist_camera_matrix(self):        return self._dist_camera_matrix    @property    def weight_matrix(self):        return self._weight_matrix    def _compute_dist_camera_matrix(self):        if self._camera_matrix is not None and self._distortion_vector is not None:            self._dist_camera_matrix, self._roi = cv2.getOptimalNewCameraMatrix(                self._camera_matrix, self._distortion_vector,                (int(self.width), int(self.height)), alpha=1)            self._md5_hash = md5.new()            self._md5_hash.update(self._camera_matrix)            self._md5_hash.update(self._distortion_vector)            self._md5_hash = self._md5_hash.hexdigest()    def _compute_weight_matrix(self):        self._weight_matrix = np.array((np.matrix(np.linspace(0, self.width - 1, self.width)).T *                                        np.matrix(np.ones(self.height))).T)    def check_calibration(self):        if self.camera_matrix is None or self.distortion_vector is None:            return False        for plane in self.laser_planes:            if plane.distance is None or plane.normal is None:                return False            if plane.distance == 0.0 or self._is_zero(plane.normal):                return False        if self.platform_rotation is None or self.platform_translation is None:            return False        if self._is_zero(self.platform_rotation) or self._is_zero(self.platform_translation):            return False        return True    def _is_zero(self, array):        return np.all(array == 0.0)    def md5_hash(self):        return self._md5_hash



# -*- coding: utf-8 -*-# This file is part of the Horus Project__author__ = 'Jes煤s Arroyo Torrens <jesus.arroyo@bq.com>'__copyright__ = 'Copyright (C) 2014-2016 Mundo Reader S.L.'__license__ = 'GNU General Public License v2 http://www.gnu.org/licenses/gpl2.html'import md5import cv2import numpy as npfrom horus import Singletonclass LaserPlane(object):    def __init__(self):##初始化类        self.normal = None        self.distance = None@Singletonclass CalibrationData(object):##初始化标定数据    def __init__(self):        self.width = 0##宽        self.height = 0##高        self._camera_matrix = None##摄像头图像矩阵        self._distortion_vector = None##旋转向量        self._roi = None##感兴趣区域        self._dist_camera_matrix = None##摄像头矩阵距离        self._weight_matrix = None##宽度矩阵        self._md5_hash = None##MD5哈希矩阵        self.laser_planes = [LaserPlane(), LaserPlane()]##左右激光        self.platform_rotation = None        self.platform_translation = None    def set_resolution(self, width, height):        if self.width != width or self.height != height:            self.width = width            self.height = height            self._compute_weight_matrix()    @property    def camera_matrix(self):##摄像头矩阵        return self._camera_matrix    @camera_matrix.setter    def camera_matrix(self, value):##摄像头矩阵值        self._camera_matrix = value        self._compute_dist_camera_matrix()    @property    def distortion_vector(self):##旋转矩阵        return self._distortion_vector    @distortion_vector.setter    def distortion_vector(self, value):##旋转矩阵的值        self._distortion_vector = value        self._compute_dist_camera_matrix()    @property    def roi(self):        return self._roi    @property    def dist_camera_matrix(self):##摄像头矩阵距离        return self._dist_camera_matrix    @property    def weight_matrix(self):        return self._weight_matrix    def _compute_dist_camera_matrix(self):        if self._camera_matrix is not None and self._distortion_vector is not None:            self._dist_camera_matrix, self._roi = cv2.getOptimalNewCameraMatrix(##getOptimalNewCameraMatrix得到自由比例参数的新摄像机矩阵                self._camera_matrix, self._distortion_vector,                (int(self.width), int(self.height)), alpha=1)            self._md5_hash = md5.new()            self._md5_hash.update(self._camera_matrix)            self._md5_hash.update(self._distortion_vector)            self._md5_hash = self._md5_hash.hexdigest()    def _compute_weight_matrix(self):        self._weight_matrix = np.array((np.matrix(np.linspace(0, self.width - 1, self.width)).T *                                        np.matrix(np.ones(self.height))).T)    def check_calibration(self):        if self.camera_matrix is None or self.distortion_vector is None:            return False        for plane in self.laser_planes:            if plane.distance is None or plane.normal is None:                return False            if plane.distance == 0.0 or self._is_zero(plane.normal):                return False        if self.platform_rotation is None or self.platform_translation is None:            return False        if self._is_zero(self.platform_rotation) or self._is_zero(self.platform_translation):            return False        return True    def _is_zero(self, array):        return np.all(array == 0.0)    def md5_hash(self):        return self._md5_hash


阅读全文
0 0
原创粉丝点击