-
大小: 9KB文件类型: .zip金币: 2下载: 1 次发布日期: 2021-06-06
- 语言: Python
- 标签: Stereo_visio
资源简介
程序完全是由python3+opencv实现的,包括标定板图像采集,单目相机标定,双目相机标定,立体矫正,SGBM立体匹配,生成视差图像。测距并非采用opencv传统三维函数,通过记录实验数据,对实验数据进行多项式拟合,通过拟合函数进行测距,精度在有效范围内可达3mm,有效范围由摄像头距离决定。
代码片段和文件信息
# ▄▀▄ ▄▀▄
# ▄█░░▀▀▀▀▀░░█▄
# ▄▄ █░░░░░░░░░░░█ ▄▄
#█▄▄█ █░░▀░░┬░░▀░░█ █▄▄█
###################################
##### Authors: #####
##### Stephane Vujasinovic #####
##### Frederic Uhrweiller #####
##### #####
##### Creation: 2017 #####
###################################
#***********************
#**** Main Programm ****
#***********************
# Package importation
import numpy as np
import cv2
from openpyxl import Workbook # Used for writing data into an Excel file
from sklearn.preprocessing import normalize
# Filtering
kernel= np.ones((33)np.uint8)
def coords_mouse_disp(eventxyflagsparam):
if event == cv2.EVENT_LBUTTONDBLCLK:
#print xydisp[yx]filteredImg[yx]
average=0
for u in range (-12):
for v in range (-12):
average += disp[y+ux+v]
average=average/9
Distance= -593.97*average**(3) + 1506.8*average**(2) - 1373.1*average + 522.06
Distance= np.around(Distance*0.01decimals=2)
print(‘Distance: ‘+ str(Distance)+‘ m‘)
# This section has to be uncommented if you want to take mesurements and store them in the excel
## ws.append([counterdist average])
## print(‘Measure at ‘+str(counterdist)+‘ cm the dispasrity is ‘ + str(average))
## if (counterdist <= 85):
## counterdist += 3
## elif(counterdist <= 120):
## counterdist += 5
## else:
## counterdist += 10
## print(‘Next distance to measure: ‘+str(counterdist)+‘cm‘)
# Mouseclick callback
wb=Workbook()
ws=wb.active
#*************************************************
#***** Parameters for Distortion Calibration *****
#*************************************************
# Termination criteria
criteria =(cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER 30 0.001)
criteria_stereo= (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER 30 0.001)
# Prepare object points
objp = np.zeros((9*63) np.float32)
objp[::2] = np.mgrid[0:90:6].T.reshape(-12)
# Arrays to store object points and image points from all images
objpoints= [] # 3d points in real world space
imgpointsR= [] # 2d points in image plane
imgpointsL= []
# Start calibration from the camera
print(‘Starting calibration for the 2 cameras... ‘)
# Call all saved images
for i in range(067): # Put the amount of pictures you have taken for the calibration inbetween range(0?) wenn starting from the image number 0
t= str(i)
ChessImaR= cv2.imread(‘chessboard-R‘+t+‘.png‘0) # Right side
ChessImaL= cv2.imread(‘chessboard-L‘+t+‘.png‘0) # Left side
retR cornersR = cv2.findChessboardCorners(ChessImaR
(96)None) # Define the number of chees corners we are looking for
retL cornersL = cv2.findChessboardCorners(ChessImaL
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 10700 2018-09-07 16:05 Stereo-Vision\Main_Stereo_Vision_Prog.py
目录 0 2018-09-07 15:53 Stereo-Vision\Stereo-Vision\
文件 10724 2018-09-07 15:58 Stereo-Vision\Stereo-Vision\Main_Stereo_Vision_Prog.py
文件 2815 2018-06-18 00:07 Stereo-Vision\Stereo-Vision\Take_images_for_calibration.py
目录 0 2018-09-07 16:05 Stereo-Vision\
评论
共有 条评论