互联网企业网站设计,企业网站搜索优化外,百度推广介绍,微页制作网站模板下载目录 一、实验内容
二、实验过程
2.1.1 test.py文件
2.1.2 test.py文件结果与分析
2.2.1 文件代码
2.2.2 结果与分析 一、实验内容
给定左右相机图片#xff0c;估算图片的视差/深度#xff1b;体现极线校正#xff08;例如打印前后极线对#xff09;、同名点匹配…目录 一、实验内容
二、实验过程
2.1.1 test.py文件
2.1.2 test.py文件结果与分析
2.2.1 文件代码
2.2.2 结果与分析 一、实验内容
给定左右相机图片估算图片的视差/深度体现极线校正例如打印前后极线对、同名点匹配例如打印数量、或可视化部分匹配点、估计结果部分像素的视差或深度。评估基线长短、不同场景室内、室外对算法的影响。
二、实验过程
2.1.1 test.py文件
from PIL import Image
from pylab import *
from scipy.ndimage import *
import numpy as np
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import filtersdef plane_sweep_ncc(im_l, im_r, start, steps, wid):m, n im_l.shapemean_l np.zeros((m, n))mean_r np.zeros((m, n))s np.zeros((m, n))s_l np.zeros((m, n))s_r np.zeros((m, n))dmaps np.zeros((m, n, steps))filters.uniform_filter(im_l, wid, mean_l)filters.uniform_filter(im_r, wid, mean_r)norm_l im_l - mean_lnorm_r im_r - mean_rfor displ in range(steps):filters.uniform_filter(np.roll(norm_l, -displ - start) * norm_r, wid, s)filters.uniform_filter(np.roll(norm_l, -displ - start) * np.roll(norm_l, -displ - start), wid, s_l)filters.uniform_filter(norm_r * norm_r, wid, s_r)with np.errstate(invalidignore):denominator np.sqrt(s_l * s_r)denominator[denominator 0] np.inf dmaps[:, :, displ] s / denominatorreturn np.argmax(dmaps, axis2)def epipolar_correction(im_l, im_r, F):h, w im_l.shapecorrected_r np.zeros_like(im_r)for y in range(h):for x in range(w):pt np.array([x, y, 1])line F ptline line / line[0]a, b, c lineu int(round(-c / a))v int(round(-c / b))if 0 u w and 0 v h:corrected_r[y, x] im_r[v, u]print(f\n校正前位置坐标 ({x}, {y}) - 校正后位置坐标 ({u}, {v}))return corrected_rdef find_matches(im_l, im_r):sift cv2.SIFT_create()kp1, des1 sift.detectAndCompute(im_l.astype(np.uint8), None)kp2, des2 sift.detectAndCompute(im_r.astype(np.uint8), None)bf cv2.BFMatcher()matches bf.knnMatch(des1, des2, k2)good_matches []for m, n in matches:if m.distance 0.75 * n.distance:good_matches.append(m)return kp1, kp2, good_matchesdef compute_fundamental_matrix(kp1, kp2, matches):points1 np.float32([kp1[m.queryIdx].pt for m in matches])points2 np.float32([kp2[m.trainIdx].pt for m in matches])F, mask cv2.findFundamentalMat(points1, points2, cv2.FM_RANSAC)return Fdef visualize_results(im_l, im_r, im_r_corrected, kp1, kp2, matches):fig, axs plt.subplots(1, 3, figsize(15, 5))axs[0].imshow(im_l, cmapgray)axs[0].set_title(Left Image)axs[0].axis(off)axs[1].imshow(im_r, cmapgray)axs[1].set_title(Right Image)axs[1].axis(off)axs[2].imshow(im_r_corrected, cmapgray)axs[2].set_title(Corrected Right Image)axs[2].axis(off)plt.show()img_matches cv2.drawMatches(im_l.astype(np.uint8), kp1, im_r.astype(np.uint8), kp2, matches[:10], None, flagscv2.DrawMatchesFlags_NOT_DRAW_SINGLE_POINTS)plt.figure(figsize(10, 5))plt.imshow(img_matches)plt.title(Top 10 Matches)plt.axis(off)plt.show()im_l np.array(Image.open(D:\\Computer vision\\KITTI2015_part\\left\\000000_10.png).convert(L), f)
im_r np.array(Image.open(D:\\Computer vision\\KITTI2015_part\\right\\000000_10.png).convert(L), f)
steps 50
start 4
wid 13kp1, kp2, matches find_matches(im_l, im_r)
F compute_fundamental_matrix(kp1, kp2, matches)im_r_corrected epipolar_correction(im_l, im_r, F)
visualize_results(im_l, im_r, im_r_corrected, kp1, kp2, matches)
res plane_sweep_ncc(im_l, im_r_corrected, start, steps, wid)
imsave(D:\\Computer vision\\KITTI2015_part\\12_3test.jpg, res)
2.1.2 test.py文件结果与分析
上述代码通过特征点检测、基础矩阵计算、极线校正以及视差图计算实现了立体匹配和校正的流程。
结果一
数据集如下图图1、图2所示图3展示了极线校正前后坐标信息的部分截图图4展示了部分同名点匹配结果图5展示了视差估计结果。 图 1 left picture 图 2 right picture 图 3 极线校正前后坐标 图 4 同名点匹配图 图 5 视差估计结果 结果二
数据集如下图图6、图7所示图8展示了极线校正前后坐标信息的部分截图图9展示了部分同名点匹配结果图10展示了视差估计结果。 图 6 left picture 图 7 right picture 图 8 极线校正 图 9 同名点匹配 图 10 结果图 2.2.1 文件代码
a.stereo_module.py文件
from numpy import argmax, roll, sqrt, zeros
from scipy.ndimage import filters
def plane_sweep_ncc(im_l,im_r,start,steps,wid):m,nim_l.shapemean_lzeros((m,n))mean_rzeros((m,n))szeros((m,n))s_lzeros((m,n))s_rzeros((m,n))dmapszeros((m,n,steps))filters.uniform_filter(im_l,wid,mean_l)filters.uniform_filter(im_r,wid,mean_r)norm_lim_l-mean_lnorm_rim_r-mean_rfor displ in range(steps):filters.uniform_filter(roll(norm_l,-displ-start)*norm_r,wid,s)filters.uniform_filter(roll(norm_l,-displ-start)*roll(norm_l,-displ-start),wid,s_l)filters.uniform_filter(norm_r*norm_r,wid,s_r)dmaps[:,:,displ]s/sqrt(s_l*s_r)return argmax(dmaps,axis2)def plane_sweep_gauss(im_l,im_r,start,steps,wid):m,n im_l.shape# arrays to hold the different sumsmean_l zeros((m,n))mean_r zeros((m,n))s zeros((m,n))s_l zeros((m,n))s_r zeros((m,n))dmaps zeros((m,n,steps))filters.gaussian_filter(im_l,wid,0,mean_l)filters.gaussian_filter(im_r,wid,0,mean_r)norm_l im_l - mean_lnorm_r im_r - mean_rfor displ in range(steps):filters.gaussian_filter(roll(norm_l,-displ-start)*norm_r,wid,0,s) filters.gaussian_filter(roll(norm_l,-displ-start)*roll(norm_l,-displ-start),wid,0,s_l)filters.gaussian_filter(norm_r*norm_r,wid,0,s_r) dmaps[:,:,displ] s/sqrt(s_l*s_r)return argmax(dmaps,axis2)
b. stereo_test.py文件
from matplotlib import colorbar
from matplotlib.pyplot import imshow, show, subplot
from numpy import array
from PIL import Image
import stereo_module as stereo
import cv2
import matplotlib.pyplot as plt
im_larray(Image.open(D:\\Computer vision\\KITTI2015_part\\left\\000000_10.png).convert(L),f)
im_rarray(Image.open(D:\Computer vision\\KITTI2015_part\\right\\000000_10.png).convert(L),f)
steps12
start4
wid9
res_nccstereo.plane_sweep_ncc(im_l,im_r,start,steps,wid)
cv2.imwrite(D:\\Computer vision\\KITTI2015_part\\depth_ncc.png,res_ncc)
res_gaussstereo.plane_sweep_gauss(im_l,im_r,start,steps,wid)
cv2.imwrite(D:\\Computer vision\\KITTI2015_part\\depth_gauss.png,res_gauss)subplot(121)
imshow(im_l)subplot(122)
imshow(res_ncc, cmapjet)
plt.colorbar()
show()
2.2.2 结果与分析
视差估计结果如图11、图12所示 图 11 视差估计结果一 图 12 视差估计结果二 文章转载自: http://www.morning.rbrhj.cn.gov.cn.rbrhj.cn http://www.morning.rwfj.cn.gov.cn.rwfj.cn http://www.morning.rcklc.cn.gov.cn.rcklc.cn http://www.morning.jfxdy.cn.gov.cn.jfxdy.cn http://www.morning.stfdh.cn.gov.cn.stfdh.cn http://www.morning.qwgct.cn.gov.cn.qwgct.cn http://www.morning.pbzgj.cn.gov.cn.pbzgj.cn http://www.morning.bbxbh.cn.gov.cn.bbxbh.cn http://www.morning.qyfqx.cn.gov.cn.qyfqx.cn http://www.morning.routalr.cn.gov.cn.routalr.cn http://www.morning.mqfw.cn.gov.cn.mqfw.cn http://www.morning.chehb.com.gov.cn.chehb.com http://www.morning.krzrg.cn.gov.cn.krzrg.cn http://www.morning.kfmnf.cn.gov.cn.kfmnf.cn http://www.morning.qscsy.cn.gov.cn.qscsy.cn http://www.morning.wrysm.cn.gov.cn.wrysm.cn http://www.morning.rwzmz.cn.gov.cn.rwzmz.cn http://www.morning.bhdyr.cn.gov.cn.bhdyr.cn http://www.morning.cfybl.cn.gov.cn.cfybl.cn http://www.morning.rkdw.cn.gov.cn.rkdw.cn http://www.morning.bbgr.cn.gov.cn.bbgr.cn http://www.morning.dwyyf.cn.gov.cn.dwyyf.cn http://www.morning.hxxyp.cn.gov.cn.hxxyp.cn http://www.morning.qdscb.cn.gov.cn.qdscb.cn http://www.morning.xjmpg.cn.gov.cn.xjmpg.cn http://www.morning.bfmrq.cn.gov.cn.bfmrq.cn http://www.morning.mrfbp.cn.gov.cn.mrfbp.cn http://www.morning.zqmdn.cn.gov.cn.zqmdn.cn http://www.morning.xhklb.cn.gov.cn.xhklb.cn http://www.morning.jzykq.cn.gov.cn.jzykq.cn http://www.morning.kqzrt.cn.gov.cn.kqzrt.cn http://www.morning.mqfhy.cn.gov.cn.mqfhy.cn http://www.morning.lslin.com.gov.cn.lslin.com http://www.morning.pcshb.cn.gov.cn.pcshb.cn http://www.morning.jghqc.cn.gov.cn.jghqc.cn http://www.morning.pkrb.cn.gov.cn.pkrb.cn http://www.morning.bnlch.cn.gov.cn.bnlch.cn http://www.morning.fnnkl.cn.gov.cn.fnnkl.cn http://www.morning.nbnq.cn.gov.cn.nbnq.cn http://www.morning.kzpy.cn.gov.cn.kzpy.cn http://www.morning.smzr.cn.gov.cn.smzr.cn http://www.morning.rhnn.cn.gov.cn.rhnn.cn http://www.morning.lsssx.cn.gov.cn.lsssx.cn http://www.morning.kjcfz.cn.gov.cn.kjcfz.cn http://www.morning.nfbkp.cn.gov.cn.nfbkp.cn http://www.morning.fqtdz.cn.gov.cn.fqtdz.cn http://www.morning.qnrpj.cn.gov.cn.qnrpj.cn http://www.morning.qmzhy.cn.gov.cn.qmzhy.cn http://www.morning.xysxj.com.gov.cn.xysxj.com http://www.morning.bqdgr.cn.gov.cn.bqdgr.cn http://www.morning.ldsgm.cn.gov.cn.ldsgm.cn http://www.morning.gthc.cn.gov.cn.gthc.cn http://www.morning.tfgkq.cn.gov.cn.tfgkq.cn http://www.morning.jpjpb.cn.gov.cn.jpjpb.cn http://www.morning.fndfn.cn.gov.cn.fndfn.cn http://www.morning.thzgd.cn.gov.cn.thzgd.cn http://www.morning.krtky.cn.gov.cn.krtky.cn http://www.morning.rdlong.com.gov.cn.rdlong.com http://www.morning.sbyhj.cn.gov.cn.sbyhj.cn http://www.morning.pqxjq.cn.gov.cn.pqxjq.cn http://www.morning.jbgzy.cn.gov.cn.jbgzy.cn http://www.morning.dmsxd.cn.gov.cn.dmsxd.cn http://www.morning.nxtgb.cn.gov.cn.nxtgb.cn http://www.morning.wmhlz.cn.gov.cn.wmhlz.cn http://www.morning.ljqd.cn.gov.cn.ljqd.cn http://www.morning.gqtzb.cn.gov.cn.gqtzb.cn http://www.morning.lnmby.cn.gov.cn.lnmby.cn http://www.morning.cwgn.cn.gov.cn.cwgn.cn http://www.morning.wzdjl.cn.gov.cn.wzdjl.cn http://www.morning.srbfp.cn.gov.cn.srbfp.cn http://www.morning.crkhd.cn.gov.cn.crkhd.cn http://www.morning.dqxph.cn.gov.cn.dqxph.cn http://www.morning.zqcsj.cn.gov.cn.zqcsj.cn http://www.morning.kmldm.cn.gov.cn.kmldm.cn http://www.morning.jpjpb.cn.gov.cn.jpjpb.cn http://www.morning.cpktd.cn.gov.cn.cpktd.cn http://www.morning.bxbkq.cn.gov.cn.bxbkq.cn http://www.morning.kzrg.cn.gov.cn.kzrg.cn http://www.morning.lmrcq.cn.gov.cn.lmrcq.cn http://www.morning.ydflc.cn.gov.cn.ydflc.cn