horus
* 联系方式:
* QQ:2468851091 call:18163325140
* Email:[email protected]
*
/ ****************************************************************************/
# -*- coding: utf-8 -*-
# This file is part of the horus Project
__author__ = 'Jes煤s Arroyo Torrens <[email protected]>'
__copyright__ = 'Copyright (C) 2014-2016 Mundo Reader S.L.'
__license__ = 'GNU General Public License v2 http://www.gnu.org/licenses/gpl2.html'
import cv2 ##导入OpenCV库存,因为三维扫描需要用到相机内参校正所以要用OPENCV.
from horus import Singleton
from horus.engine.driver.driver import Driver##导入驱动,这个驱动包括软件与硬件的所有引擎。因为本项目##还会有开源硬件。
from horus.engine.calibration.calibration_data import CalibrationData##精度数据校正,这个库主要是对相机
##内部畸变参数进行校正。
class Camerasettings(object):
def __init__(self):
self.driver = Driver()
self.selected = False
self.brightness = 0
self.contrast = 0
self.saturation = 0
self.exposure = 0
def set_brightness(self, value):##亮度
self.brightness = value
if self.selected:
self.driver.camera.set_brightness(value)
def set_contrast(self, value):##对比度
self.contrast = value
if self.selected:
self.driver.camera.set_contrast(value)
def set_saturation(self, value):##饱和度
self.saturation = value
if self.selected:
self.driver.camera.set_saturation(value)
def set_exposure(self, value):##曝光度
self.exposure = value
if self.selected:
self.driver.camera.set_exposure(value)
def send_all_settings(self):##图像各项数据发送
self.driver.camera.set_brightness(self.brightness)
self.driver.camera.set_contrast(self.contrast)
self.driver.camera.set_saturation(self.saturation)
self.driver.camera.set_exposure(self.exposure)
@Singleton
class ImageCapture(object):
def __init__(self):
self.driver = Driver()
self.calibration_data = CalibrationData()
self.texture_mode = Camerasettings()
self.laser_mode = CameraSettings()
self.pattern_mode = CameraSettings()
self.stream = True
self._mode = self.pattern_mode
self._mode.selected = True
self._remove_background = True
self._updating = False
self.use_distortion = False
def initialize(self):
self.texture_mode.initialize()
self.laser_mode.initialize()
self.pattern_mode.initialize()
def set_flush_values(self, texture, laser, pattern):
self._flush_texture = texture
self._flush_laser = laser
self._flush_pattern = pattern
def set_flush_stream_values(self, texture, laser, pattern):
self._flush_stream_texture = texture
self._flush_stream_laser = laser
self._flush_stream_pattern = pattern
def set_use_distortion(self, value):
self.use_distortion = value
def set_remove_background(self, value):
self._remove_background = value
def set_mode(self, mode):
if self._mode is not mode:
self._updating = True
self._mode.selected = False
self._mode = mode
self._mode.selected = True
self._mode.send_all_settings()
self._updating = False
def set_mode_texture(self):
self.set_mode(self.texture_mode)
def set_mode_laser(self):
self.set_mode(self.laser_mode)
def set_mode_pattern(self):
self.set_mode(self.pattern_mode)
def flush_texture(self):
self.set_mode_texture()
self.capture_image(flush=0)
def flush_laser(self):
self.set_mode_laser()
self.capture_image(flush=0)
def flush_pattern(self):
self.set_mode_pattern()
self.capture_image(flush=0)
def capture_texture(self):
self.set_mode(self.texture_mode)
if self.stream:
flush = self._flush_stream_texture
else:
flush = self._flush_texture
image = self.capture_image(flush=flush)
return image
def _capture_laser(self, index):
self.set_mode(self.laser_mode)
self.driver.board.lasers_off()
self.driver.board.laser_on(index)
if self.stream:
flush = self._flush_stream_laser
else:
flush = self._flush_laser
image = self.capture_image(flush=flush)
self.driver.board.laser_off(index)
return image
def capture_laser(self, index):
# Capture background
image_background = None
if self._remove_background:
self.driver.board.lasers_off()
if self.stream:
flush = self._flush_stream_laser
else:
flush = self._flush_laser
image_background = self.capture_image(flush=flush)
# Capture laser
image = self._capture_laser(index)
if image_background is not None:
if image is not None:
image = cv2.subtract(image, image_background)
return image
def capture_lasers(self):
# Capture background
image_background = None
if self._remove_background:
self.driver.board.lasers_off()
if self.stream:
flush = self._flush_stream_laser
else:
flush = self._flush_laser
image_background = self.capture_image(flush=flush)
# Capture lasers
images = [None, None]
images[0] = self._capture_laser(0)
images[1] = self._capture_laser(1)
if image_background is not None:
if images[0] is not None:
images[0] = cv2.subtract(images[0], image_background)
if images[1] is not None:
images[1] = cv2.subtract(images[1], image_background)
return images
def capture_all_lasers(self):
image_background = None
self.set_mode(self.laser_mode)
if self.stream:
flush = self._flush_stream_laser
else:
flush = self._flush_laser
if self._remove_background:
self.driver.board.lasers_off()
image_background = self.capture_image(flush=flush)
self.driver.board.lasers_on()
image = self.capture_image(flush=flush)
self.driver.board.lasers_off()
if image_background is not None:
if image is not None and image_background is not None:
image = cv2.subtract(image, image_background)
return image
def capture_pattern(self):
self.set_mode(self.pattern_mode)
if self.stream:
flush = self._flush_stream_pattern
else:
flush = self._flush_pattern
image = self.capture_image(flush=flush)
return image
def capture_image(self, flush=0):
image = self.driver.camera.capture_image(flush=flush)
if self.use_distortion:
if image is not None and \
self.calibration_data.camera_matrix is not None and \
self.calibration_data.distortion_vector is not None and \
self.calibration_data.dist_camera_matrix is not None:
image = cv2.undistort(image,##利用OPENCV内部函数校正数据。
self.calibration_data.camera_matrix,
self.calibration_data.distortion_vector,
None,
self.calibration_data.dist_camera_matrix)
return image
相关阅读
现在很多用户都会使用迅雷下载工具,不过由于迅雷软件不兼容win10系统补丁,导致用户更新一些补丁后出现迅雷老是崩溃的情况,那么遇到w
进入版权时代后,很多追剧党因为种种原因无法观看到自己喜欢的热剧。一些剧质量不佳,好剧又被迫下架,一些列问题也引发不少追剧党的吐
本章内容提要软件配置管理的作用软件配置管理的相关概念建立软件配置管理环境版本控制系统集成分支管理变更管理配置审计和配置状
移动设备已成为我们生活中最重要的工具,力量越大,责任越大。由于移动端是一个私人媒介,对营销人员而言,在营销过程中如何避开哪些&ldq
1、Adobe Photoshop优点:功能强大、好用缺点:需要授权使用,会扫描个人信息到Adobe服务器(企业会收到律师函)2、GIMP (GNU Image Manipu