可见光相机与红外相机标定
目录
1.打开相机
2.可见光相机畸变矫正
安装相关库
查看相机参数
修改launch文件
启动标定程序
启动矫正图像节点
3.查看相机图像
4.计算H举矩阵
手动标注获取每一组的H矩阵(h.py)
计算出平均H矩阵并查看标定效果(MeanH_Test.py)
5.接受、处理、发送图像(biaoding.py)
6.标定效果
1.打开相机
cd camera_ws
source devel/setup.bash
roslaunch usb_cam usb_cam-dual_model_rectified.launch
2.可见光相机畸变矫正
安装相关库
catkin_make -DCATKIN_WHITELIST_PACKAGES="aruco;aruco_ros;aruco_msgs"
catkin_make -DCATKIN_WHITELIST_PACKAGES="aruco_mapping;lidar_camera_calibration"
catkin_make -DCATKIN_WHITELIST_PACKAGES=""
查看相机参数
ls /dev/video* #查看video个数和名称
v4l2-ctl -d 0 --all #查看video0的参数
修改launch文件
<param name="video_device" value="/dev/video1" />
<param name="image_width" value="640" />
<param name="image_height" value="480" />
<param name="pixel_format" value="mjpeg" />
启动标定程序
rosrun camera_calibration cameracalibrator.py --size 8x6 --square 0.06 image:=/usb_cam/image_raw camera:=/usb_cam
- 移动标定板时,标定窗口中的各指标增加。
- 当CALIBRATE按钮亮起时,单击计算相机内参矩阵及矫正参数,并输出至终端,此过程可能需要1-2分钟。
- 当SAVE按钮亮起时,单击将采集的样本图片和计算结果保存
- 当COMMIT按钮亮起时,单击将标定结果写入
~/.ros/camera_info/head_camera.yaml
。注:此标定文件将被原始图像节点usb_cam读取,标定参数会被发布至话题/usb_cam/camera_info
以供矫正图像节点image_proc使用。
启动矫正图像节点
ROS_NAMESPACE=/cam_rgb/usb_cam rosrun image_proc image_proc
3.查看相机图像
rqt_image_view
4.计算H举矩阵
手动标注获取每一组的H矩阵(h.py)
#!/usr/bin/python
# -*- coding: UTF-8 -*-
from PIL import Image
import cv2
import numpy as np
import pylab as pl
import matplotlib.pyplot as plt
import scipy.io as sio
from PIL import Imagedef re_img(path):img = cv2.imread(path)a=int(20) #x startb=int(700) #x endc=int(0) #y startd=int(510) #y endcropimg=img[c:d,a:b]imgresize=cv2.resize(cropimg,(640,480))return imgresizeif __name__ == '__main__' :num = 9h=np.zeros((3,3))# 读取红外图.inf_Fig = "./rgb1/" + str(num) +"_dual.png"img_dst = re_img(inf_Fig)pl.figure(), pl.imshow(img_dst[:, :, ::-1]), pl.title('dual')# 红外图中的4个点dst_point = plt.ginput(4) dst_point = np.float32(dst_point)# 读取RGB图像.RGB_Fig_1 = "./rgb1/"+ str(num) +".png"im_src_1 = cv2.imread(RGB_Fig_1)pl.figure(), pl.imshow(im_src_1[:, :, ::-1]), pl.title('rgb1')# RGB图中的4个点src_point_1 = plt.ginput(4) src_point_1 = np.float32(src_point_1)# Calculate Homographyh, status = cv2.findHomography(src_point_1, dst_point)# Warp source image to destination based on homographyim_out_1 = cv2.warpPerspective(im_src_1,h,(640,480),borderValue=(255,255,255))pl.imshow(im_out_1[:, :, ::-1]), pl.title('out')pl.show() #show dst#保存H矩阵H1_name = 'h'+str(num)+'.mat'print('H1:',h)sio.savemat(H1_name, {'Homography_Mat_1':h})
计算出平均H矩阵并查看标定效果(MeanH_Test.py)
#!/usr/bin/python
# -*- coding: UTF-8 -*-from PIL import Image
import cv2
import numpy as np
#import pylab as pl
#import matplotlib.pyplot as plt
import scipy.io as sio
import timeclass bd():def get_time_stamp(self):ct = time.time()local_time = time.localtime(ct)data_head = time.strftime("%Y-%m-%d %H:%M:%S", local_time)data_secs = (ct - int(ct)) * 1000time_stamp = "%s.%03d" % (data_head, data_secs)#print(time_stamp)stamp = ("".join(time_stamp.split()[0].split("-"))+"".join(time_stamp.split()[1].split(":"))).replace('.', '')#print(stamp)return stampdef re_img(self,img):#img = cv2.imread(path)a=int(20) #x startb=int(700) #x endc=int(0) #y startd=int(510) #y endcropimg=img[c:d,a:b]imgresize=cv2.resize(cropimg,(640,480))return imgresizedef H_use(self,fig1):name_1 = 'H11.mat'data = sio.loadmat(name_1)h1 = data['Homography_Mat_1']h1[0][2]=h1[0][2]+30 #根据实际效果的修正h1[1][2]=h1[1][2]+10#print(h1[0][2])#print(h1)im_out_1 = cv2.warpPerspective(fig1,h1,(640,480))return im_out_1def Htest(self,path1,path2):im_src_1 = cv2.imread(path1)img_dst = self.re_img(path2)im_out_1= self.H_use(im_src_1)#pl.figure(),pl.imshow(img_dst[:, :, ::-1]), pl.title('dst'),#pl.figure(),pl.imshow(im_out_1[:, :, ::-1]), pl.title('out1'),#pl.show()return im_out_1, img_dstdef Htest_t(self,img_t):img_dst = self.re_img(img_t)return img_dstdef Htest_rgb(self,img_rgb):im_out_1= self.H_use(img_rgb)return im_out_1def cal_H(self):num=0H=np.zeros((3,3))while int(num) < 10:print(num)name = 'h' + str(num) +'.mat'data=sio.loadmat(name)h = data['Homography_Mat_1']print("h:",h)num = num + 1H=H+hH=H/10H1_name = 'H.mat'print('H1:',H)sio.savemat(H1_name, {'Homography_Mat_1':H})if __name__ == '__main__' :B=bd()num=0#B.cal_H()while int(num)<10:rgb_path="./rgb1/"+str(num)+".png" t_path="./rgb1/"+str(num)+"_t.png"img_rgb,img_t = B.Htest(rgb_path,t_path)cv2.imwrite('./out/'+str(num)+'.png',img_rgb)cv2.imwrite('./out/'+str(num)+'_t.png',img_t)num=num+1time=B.get_time_stamp()print(time)
5.接受、处理、发送图像(biaoding.py)
#! /usr/bin/env python2from __future__ import print_function#python2
import os
import roslib
import rospy
from std_msgs.msg import Header
from std_msgs.msg import String
from sensor_msgs.msg import Image
# from ros_numpy import msgify
from cv_bridge import CvBridge
import sys
sys.path.remove('/opt/ros/melodic/lib/python2.7/dist-packages')
import threading
import time
import numpy as np
import MeanH_Test as biao
import cv2
import threading
#python3class SubscribeAndPublish:def __init__(self):self.all_obstacle_str=''self.sub1_name="/cam_rgb/usb_cam/image_rect_color"#self.sub1_name="/cam_rgb/usb_cam/image_raw"self.sub1= rospy.Subscriber(self.sub1_name, Image,self.callback_rgb)self.sub2_name="/cam_t/usb_cam/image_raw"self.sub2= rospy.Subscriber(self.sub2_name, Image,self.callback_t)self.rate = 10self.timer = rospy.Timer(rospy.Duration(1.0 / self.rate), self.callback_timer)self.lock_rgb = threading.Lock()self.lock_t = threading.Lock()self.img_rgb_global = []self.img_t_global = []self.pub1_name="pub_rgb"self.pub1= rospy.Publisher(self.pub1_name, Image,queue_size=1)self.pub2_name="pub_t"self.pub2= rospy.Publisher(self.pub2_name, Image,queue_size=1)self.mode=0self.path_rgb='./img/img_rgb'self.path_t='./img/img_t'# self.bridge = CvBridge()def callback_rgb(self,data):print('callback1')self.lock_rgb.acquire()img = np.frombuffer(data.data, dtype=np.uint8).reshape(data.height, data.width, -1)if len(self.img_rgb_global) > 0:self.img_rgb_global.pop(0)self.img_rgb_global.append(img)else:self.img_rgb_global.append(img)self.lock_rgb.release()#print('rgb')#img = CvBridge().imgmsg_to_cv2(data, "bgr8")#img = np.frombuffer(data.data, dtype=np.uint8).reshape(data.height, data.width, -1)#print(img.shape)#B=biao.bd()#time=B.get_time_stamp()#name='rgb_'+str(time)+'.jpg'#img_rgb=B.Htest_rgb(img)#cv2.imwrite('./img/img_rgb/'+str(name),img_rgb)#self.pub1.publish(CvBridge().cv2_to_imgmsg(img_rgb,"bgr8"))def callback_t(self,data):print('callback2')self.lock_t.acquire()img = np.frombuffer(data.data, dtype=np.uint8).reshape(data.height, data.width, -1)if len(self.img_t_global) > 0:self.img_t_global.pop(0)self.img_t_global.append(img)else:self.img_t_global.append(img)self.lock_t.release()#print('t')#img = CvBridge().imgmsg_to_cv2(data, "bgr8")#img = np.frombuffer(data.data, dtype=np.uint8).reshape(data.height, data.width, -1)#print(img.shape)#B=biao.bd()#time=B.get_time_stamp()#name='t_'+str(time)+'.jpg'#img_t=B.Htest_t(img)#cv2.imwrite('./img/img_t/'+str(name),img_t)# self.pub2.publish(CvBridge().cv2_to_imgmsg(img_t,"bgr8"))def callback_timer(self, event):print('callback')self.lock_rgb.acquire()if len(self.img_rgb_global) > 0:img_rgb = self.img_rgb_global[0].copy()else:returnself.lock_rgb.release()self.lock_t.acquire()if len(self.img_t_global) > 0:img_t = self.img_t_global[0].copy()else:returnself.lock_t.release()B=biao.bd()time=B.get_time_stamp()img_rgb=B.Htest_rgb(img_rgb)img_t=B.Htest_t(img_t)img_rgb=img_rgb[:,:,::-1]img_t=img_t[:,:,::-1]self.mode=modeif self.mode==0:self.path_rgb=path_rgbself.path_t=path_tcv2.imwrite(self.path_rgb+'/rgb_'+str(time)+'.jpg',img_rgb)cv2.imwrite(self.path_t+'/t_'+str(time)+'.jpg',img_t)print('save image successful!')self.pub1.publish(CvBridge().cv2_to_imgmsg(img_rgb,"rgb8"))self.pub2.publish(CvBridge().cv2_to_imgmsg(img_t,"rgb8"))def main(mode,path_rgb,path_t):rospy.init_node('biaoding_ws', anonymous=True)#####################t=SubscribeAndPublish()#####################rospy.spin()
if __name__ == "__main__":mode=0if len(sys.argv)>1:mode=int(sys.argv[1])if mode>1:mode=1else:mode=0print(mode)if mode==0:print("save image")else:print("no save image")#create dirsb=biao.bd()ti=b.get_time_stamp()path='./img'+str(ti)folder=os.path.exists(path)if not folder:os.makedirs(path)path_rgb=path+'/img_rgb'os.makedirs(path_rgb)path_t=path+'/img_t'os.makedirs(path_t)main(mode,path_rgb,path_t)
6.标定效果
可见光相机与红外相机标定相关推荐
- 乐视体感三合一奥比中光Astra Pro相机彩色和深度(红外)相机标定
具体标定过程参考 乐视体感三合一奥比中光Astra Pro相机彩色和深度(红外)相机标定 由于在标定过程中IR图像过暗无法进行标定,故对其数据进行放大处理,相关代码如下: #!/usr/bin/env ...
- matlab鱼眼镜头,普通镜头,单目双目相机标定校正(四)
写这篇文章的目的,是记录相机标定过程和问题,经过试验,记录问题 1.单目相机与双目相机的标定.区别.目的 2.相机拍照时,距离标定板的距离 3.填写参数时.黑白格的大小有影响? 4.参数的设置 5.拍 ...
- Ubuntu 18.04 Intel RealSense D435i 相机标定教程
1.D435i相机简介 RealSenseD435i 是一款立体视觉深度相机,如下图所示,其集成了两个红外传感器(IR Stereo Camera).一个红外激光发射器(IR Projector)和一 ...
- 视觉SLAM——针孔相机模型 相机标定原理 双目相机模型 深度相机对比
前言 本博客为主要学习<视觉SLAM十四讲>第5讲.<机器人学的状态估计>第6章6.4.1透视相机.<多视图几何>第5章摄像头模型等SLAM内容的总结与整理. 主要 ...
- Camera Calibration 相机标定
Camera Calibration 相机标定 一.相机标定方法 在opencv中提供了一组函数用于实现相机的标定,标定返回的值包括:相机内参矩阵(fx fy xc yc).相机外参矩阵(R t)以及 ...
- 标题 相机标定(Camera calibration)原理和步骤
标题 相机标定(Camera calibration)原理和步骤 为什么要相机标定? 在图像测量过程和机器视觉应用中,为确定空间物体表面某点的三维几何位置与其在图像中对应点之间的相互关系,必须建立相机 ...
- Matlab相机标定并进行图像校正
Matlab相机标定工具 APP->展开: 图像处理与计算机视觉栏: 相机标定过程 打印一张黑白棋盘,拍摄足够多张照片,以确保之后的合格照片的筛选. 2. 打开Matlab相机标定工具,从文件中 ...
- 相机标定 matlab opencv ROS三种方法标定步骤(2)
二 ubuntu下Opencv的相机标定 一般直接用Opencv的源码就可以进行相机的标定,但是可能只是会实现结果,却不懂实现的过程,我也是模模糊糊的看了<计算机视觉中的多视图几何>以及 ...
- 相机标定 matlab opencv ROS三种方法标定步骤(3)
三 , ROS 环境下 如何进行相机标定 刚开始做到的时候遇到一些问题没有记录下来,现在回头写的时候都是没有错误的结果了,首先使用ROS标定相机, 要知道如何查看节点之间的流程图 rosrun r ...
最新文章
- 【Python学习教程】:装饰器的详细教程,通俗易懂
- equals方法中变量在前和在后的区别
- LeetCode 1216. 验证回文字符串 III(DP)
- LeetCode 1408. 数组中的字符串匹配(暴力查找)
- 攻略:三大秘籍让你笑傲IT职场!
- oracle导出报错04063,Oracle EXP导出报错的解决方法
- git报错 ssh: Could not resolve hostname gitee.com:xxxxxx: Name or service not known fatal
- java 创建bean_java – 使用spring按需创建bean
- Redis 和Memcache的区别
- Pycharm汉化使用教程
- 汇编语言程序设计(一)
- 分布式与微服务☞web组件kafka
- 2022吴恩达机器学习课程学习笔记(第二课第一周)
- 接口测试之用例设计技巧
- 全景图(三):在Unity3D上实现360°球面投影
- 前端之TS类型注解、接口(vscode自编译ts→js)
- 老宇哥带你玩转ESP32,12篇基础教程已经更新完毕,接下来是进阶教程
- ERROR: Cannot uninstall ‘wrapt‘. It is a distutils installed project and thus we cannot accurately d
- php session传数组,php session存储数组
- Android超强大的粒子动画库,流星雨,爆炸,满屏飞花,等粒子特效快速实现
热门文章
- 数字图书馆是计算机技术多媒体技术网络技术,计算机技术在数字图书馆上的应用...
- 我家一只1岁大黑白相间的中华田园猫丢了,你能帮我写一则寻猫启事吗?我家住在一楼,小猫的尾巴尖缺失了一节...
- 用python写一个大鱼吃小鱼的游戏
- 用vim还是用vs呢
- 内蒙古大学孙涛计算机学院,孙涛(博士)
- python桌面爬虫_Python3爬虫爬取英雄联盟高清桌面壁纸功能示例【基于Scrapy框架】...
- SQL 通过sum() over(order by ,rownum)实现财务现金日记账实例
- XenServer常用命令
- joomlaGOOGLE被屏蔽解决方案
- LayaAir2.13.0