6 結構光 雙目視覺 基於特徵點

2021-07-30 10:13:01 字數 3781 閱讀 8429

在這裡,對matlab的demo進行更改,測試了雙目視覺!具體的**如下:

%%

% 雙目立體視覺

% 對比實驗

%%% 清空工作區

clc;

clear;

close all;

%%% 匯入影象資料

i1 = imread('pattern_cam1_im1.png');

i2 = imread('pattern_cam2_im1.png');

figure

imshowpair(i1, i2, 'montage');

title('original images');

% 匯入相機引數

load cameraparams.mat

%%% 校正

i1 = undistortimage(i1, camera1params);

i2 = undistortimage(i2, camera1params);

figure

imshowpair(i1, i2, 'montage');

title('undistorted images');

%%% 特徵點提取

imagepoints1 = detectmineigenfeatures(rgb2gray(i1), 'minquality', 0.1);

%%% 視覺化

figure

imshow(i1, 'initialmagnification', 50);

title('150 strongest corners from the first image');

hold on

plot(selectstrongest(imagepoints1, 150));

%%% create the point tracker

tracker = vision.pointtracker('maxbidirectionalerror', 1, 'numpyramidlevels', 5);

imagepoints1 = imagepoints1.location;

initialize(tracker, imagepoints1, i1);

% track the points

[imagepoints2, valididx] = step(tracker, i2);

matchedpoints1 = imagepoints1(valididx, :);

matchedpoints2 = imagepoints2(valididx, :);

%%% 特徵點匹配

figure

showmatchedfeatures(i1, i2, matchedpoints1, matchedpoints2);

title('tracked features');

%%% f矩陣估計

[fmatrix, epipolarinliers] = estimatefundamentalmatrix(...

matchedpoints1, matchedpoints2, 'method', 'msac', 'numtrials', 10000);

% 極線

inlierpoints1 = matchedpoints1(epipolarinliers, :);

inlierpoints2 = matchedpoints2(epipolarinliers, :);

% 顯示內點

figure

showmatchedfeatures(i1, i2, inlierpoints1, inlierpoints2);

title('epipolar inliers');

%%% r和t(也可以用ransac演算法)

r = [0.9455,-0.0096,0.3253;

0.0120,0.9999,-0.0053;

-0.3252,0.0090,0.9456];

t = [98.4069,0.1741,18.9018];

%%% 稠密的特徵點

imagepoints1 = detectmineigenfeatures(rgb2gray(i1), 'minquality', 0.001);

%%% create the point tracker

tracker = vision.pointtracker('maxbidirectionalerror', 1, 'numpyramidlevels', 5);

% initialize the point tracker

imagepoints1 = imagepoints1.location;

initialize(tracker, imagepoints1, i1);

% track the points

[imagepoints2, valididx] = step(tracker, i2);

matchedpoints1 = imagepoints1(valididx, :);

matchedpoints2 = imagepoints2(valididx, :);

%%% cameramatrix

cammatrix1 = cameramatrix(camera1params, eye(3), [0 0 0]);

cammatrix2 = cameramatrix(camera2params, r', -t*r');

% 三維點雲的計算

points3d = triangulate(matchedpoints1, matchedpoints2, cammatrix1, cammatrix2);

% 獲取顏色資訊

numpixels = size(i1, 1) * size(i1, 2);

allcolors = reshape(i1, [numpixels, 3]);

coloridx = sub2ind([size(i1, 1), size(i1, 2)], round(matchedpoints1(:,2)), ...

round(matchedpoints1(:, 1)));

color = allcolors(coloridx, :);

% 建立點雲

ptcloud = pointcloud(points3d, 'color', color);

%%% 視覺化

camerasize = 0.3;

figure

plotcamera('size', camerasize, 'color', 'r', 'label', '1', 'opacity', 0);

hold on

grid on

plotcamera('location', t, 'orientation', r, 'size', camerasize, ...

'color', 'b', 'label', '2', 'opacity', 0);

% 點雲的視覺化

pcshow(ptcloud, 'verticalaxis', 'y', 'verticalaxisdir', 'down', ...

'markersize', 45);

% rotate and zoom the plot

camorbit(0, -30);

camzoom(1.5);

% label the axes

xlabel('x-axis');

ylabel('y-axis');

zlabel('z-axis')

title('up to scale reconstruction of the scene');

第五講5 4 1雙目視覺生成點雲

cmake minimum required version 3.15 project stereovision find package pangolin required find package opencv required include directories include direc...

基於雙目視覺的汽車前向障礙物檢測

在我的設計中 1 測試案例中的左圖 左上圖 和右圖使用自己改進的sgm演算法進行計算得到視差圖,通過gpu的加速可以實時輸出視差圖 右中圖為視差圖的偽色彩圖 可以看到,改進版的sgm演算法不但速度滿足了實時計算的要求,而且效果明顯好於原版的sgm演算法。2 通過對視差資訊的計算,獲得三維點雲圖 右下...

基於結構光的立體視覺

1介紹 對立體視覺進行介紹,分析現有的缺陷。如何引進結構光,測量的原理和標定,效能測試與評估。二維的影象無法獲取深度資訊。雙目立體視覺 特徵提取 sift,suft,orb。特徵描述 特徵匹配 犧牲特徵點的數量。特徵點數目比較少,比較稀疏。無法實現識別。結構光視覺 視覺範圍 小於5m,精度 最大0....