-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from raviBhadeshiya/improvement
Improvement
- Loading branch information
Showing
35 changed files
with
833 additions
and
397 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
clc; clear all; close all;warning('off'); | ||
|
||
index = 0; | ||
trainFolder = '..\Input\vehicles\myposFIles\'; | ||
negativeFolder = fullfile('..\Input\vehicles'); | ||
|
||
negativeImages = imageDatastore(negativeFolder,'IncludeSubfolders',true); | ||
|
||
negativeStruct = struct(negativeImages); | ||
|
||
for i =1:negativeStruct.NumFiles | ||
img = imread(char(negativeStruct.Files(i))); | ||
rimg=flip(img,2); | ||
imwrite(rimg,fullfile(trainFolder,sprintf('file_%d.png',i)),'png'); | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
clc;clear all; close all; warning('off'); | ||
%% | ||
negativeFolder = fullfile('..\Input\non-vehicles\Extras\'); | ||
|
||
positiveFolder = fullfile('..\Input\vehicles\'); | ||
|
||
negativeImages = imageDatastore(negativeFolder,'IncludeSubfolders',true); | ||
positiveImages = imageDatastore(positiveFolder,'IncludeSubfolders',true); | ||
|
||
value = [1 1 64 64]; | ||
|
||
positiveStruct = struct(positiveImages); | ||
positiveImg(:,1) = cell2table(positiveStruct.Files); | ||
for i =1:positiveStruct.NumFiles | ||
positiveImg(i,2) = table(value); | ||
end | ||
%% | ||
trainCascadeObjectDetector('cascadeClassifier.xml',positiveImg, ... | ||
negativeFolder,'FalseAlarmRate',0.05,'NumCascadeStages',10); |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
function [k,r,c] = DecomposeCameraMatrix(p) | ||
% Descompose the camera matrix P into K, R, C according P = K [R |-RC] | ||
% | ||
% Input: | ||
% - p is a 3x4 camera matrix. | ||
% | ||
% Output: | ||
% - k is a 3x3 calibration matrix. | ||
% - r is a 3x3 rotation matrix. | ||
% - c is a 3x1 camera coordinates. | ||
% | ||
%---------------------------------------------------------- | ||
% | ||
% From | ||
% Book: "Multiple View Geometry in Computer Vision", | ||
% Authors: Hartley and Zisserman, 2006, [HaZ2006] | ||
% Section: "Decomposition of the camera matrix", | ||
% Chapter: 6 | ||
% Page: 163 | ||
% | ||
%---------------------------------------------------------- | ||
% Author: Diego Cheda | ||
% Affiliation: CVC - UAB | ||
% Date: 03/06/2008 | ||
%---------------------------------------------------------- | ||
|
||
% Finding camera centre | ||
% PC = 0, right null vector of P. | ||
x = det([ p(:,2), p(:,3), p(:,4) ]); | ||
y = -det([ p(:,1), p(:,3), p(:,4) ]); | ||
z = det([ p(:,1), p(:,2), p(:,4) ]); | ||
t = -det([ p(:,1), p(:,2), p(:,3) ]); | ||
|
||
c = [ x/t; y/t; z/t ]; | ||
|
||
% Finding camera orientation and internal parameters | ||
% P = [M | -MC] = K[R | -RC] | ||
[k,r] = RQDecomposition(p(:,1:3)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
function d = DepthOfPoints(x3D,rot,t) | ||
% Computes the depth of points | ||
% | ||
% Input: | ||
% - x3D are the 3D points. | ||
% | ||
% - rot is a 3x3 rotation matrix | ||
% | ||
% - t is a 3x1 traslation matrix. | ||
% | ||
% Output: | ||
% - d is a 1xn vector with the depth of points. | ||
% | ||
%---------------------------------------------------------- | ||
% | ||
% From | ||
% Book: "Multiple View Geometry in Computer Vision", | ||
% Authors: Hartley and Zisserman, 2006, [HaZ2006] | ||
% Section: "Depth of points", | ||
% Chapter: 6 | ||
% Page: 162 | ||
% | ||
%---------------------------------------------------------- | ||
% Author: Diego Cheda | ||
% Affiliation: CVC - UAB | ||
% Date: 11/06/2008 | ||
%---------------------------------------------------------- | ||
|
||
[k,r,c] = DecomposeCameraMatrix([rot t]); | ||
|
||
x3D = HomogeneousCoordinates(x3D,'3D'); | ||
|
||
for i=1:size(x3D,2) | ||
w = rot(3,:) * (x3D(1:3,i) - c(1:3,:)); | ||
|
||
depth = (sign(det(rot)) * w) / x3D(4,i) * norm(rot(3,:)); | ||
|
||
d(i) = depth(1,1); | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
function [C, R, X] = DisambiguateCameraPose(Cset, Rset, Xset) | ||
|
||
for i = 1 : length(Cset) | ||
D = Rset{i}*(Xset{i}'-Cset{i}*ones(1,size(Xset{i},1))); | ||
n(i) = length(find(D(3,:)>0 & Xset{i}(:,3)'>0)); | ||
end | ||
|
||
[~, maxi] = min(n); | ||
C = Cset{maxi}; | ||
R = Rset{maxi}'; | ||
X = Xset{maxi}; | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
function e = EssentialMatrixFrom2DPoints(p1,p2,k) | ||
% | ||
% Input: | ||
% p1 and p2 are 2xN (or 3xN in homogeneous coordiantes) of | ||
% correspondings corners. | ||
% | ||
% k is the camera matrix. | ||
% | ||
% Output: | ||
% e is the essential matrix. | ||
% | ||
%---------------------------------------------------------- | ||
% | ||
% From | ||
% Book: "Multiple View Geometry in Computer Vision", | ||
% Authors: Hartley and Zisserman, 2006, [HaZ2006] | ||
% Section: "Computation of the Fundamental Matrix F", specifically "The | ||
% normalised 8-point algorithm" | ||
% Chapter: 11 | ||
% Page: 279 | ||
% | ||
%---------------------------------------------------------- | ||
% Author: Diego Cheda | ||
% Affiliation: CVC - UAB | ||
% Date: 03/06/2008 | ||
%---------------------------------------------------------- | ||
|
||
% Points in Normalized Coordinates. p = inv(k) * p | ||
p1 = NormalizedCoordinates(p1,k); | ||
p2 = NormalizedCoordinates(p2,k); | ||
|
||
% Normalization | ||
% Transform the image coordinates according to x^_i = Tx_i and x'^_i = | ||
% T'x'_i where T and T' are normalizing transformation consisting of a | ||
% translation and scaling. | ||
% [p1,t1] = Normalise2DPts(p1); | ||
% [p2,t2] = Normalise2DPts(p2); | ||
[p1,t1] = normalise2dpts(p1); | ||
[p2,t2] = normalise2dpts(p2); | ||
|
||
|
||
% (x,y) | ||
x1 = p1(1,:)'; | ||
x2 = p2(1,:)'; | ||
|
||
y1 = p1(2,:)'; | ||
y2 = p2(2,:)'; | ||
|
||
|
||
% Number of points | ||
numPts = size(p1,2); | ||
|
||
% Af = 0 | ||
% Computes A, the constraint matrix of numpts x 9 | ||
a = [x2.*x1 x2.*y1 x2 y2.*x1 y2.*y1 y2 x1 y1 ones(numPts,1)]; | ||
%a = [x1.*x2 x1.*y2 x1 y1.*x2 y1.*y2 y1 x2 y2 ones(numPts,1)]; | ||
|
||
if (rank(a)<8) | ||
disp('rank defficient'); | ||
end | ||
|
||
|
||
% Singular Value Decomposition of A. | ||
% [U,S,V] = SVD(A) produces a diagonal matrix S, of the same dimension as A | ||
% and with nonnegative diagonal elements in decreasing order, and unitary | ||
% matrices U and V so that A = U*S*V'. | ||
[u, d, v] = svd(a); | ||
|
||
% Linear solution. Obtain F from 9th column of V (the smallest singular | ||
% value of A). | ||
e = reshape(v(:,9),3,3)'; | ||
|
||
% Constraint enforcement. | ||
[u, d, v] = svd(e); | ||
d = diag([1 1 0]); | ||
e = u * d * v'; | ||
|
||
% Desnormalization | ||
e = t2' * e * t1; |
16 changes: 0 additions & 16 deletions
16
VisualOdometry/code/EssentialMatrixFromFundamentalMatrix.m
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
function [rot,t] = EssentialMatrixToCameraMatrix(e) | ||
% Extracts the cameras from the essential matrix | ||
% | ||
% Input: | ||
% - e is the 3x4 essential matrix. | ||
% | ||
% Output: | ||
% - p1 = [I | 0] is the first canonic camera matrix. | ||
% | ||
% - rot and t are the rotation and translation of the | ||
% second camera matrix from 4 possible solutions. One camera matrix | ||
% must be selected. We test with a single point to determine if it is | ||
% in front of both cameras is sufficient to decide between the four | ||
% different solutions for the camera matrix (pag. 259). | ||
% | ||
%---------------------------------------------------------- | ||
% | ||
% From | ||
% Book: "Multiple View Geometry in Computer Vision", | ||
% Authors: Hartley and Zisserman, 2006, [HaZ2006] | ||
% Section: "Extraction of cameras from the essential matrix", | ||
% Chapter: 9 | ||
% Page: 258 | ||
% | ||
%---------------------------------------------------------- | ||
% Author: Diego Cheda | ||
% Affiliation: CVC - UAB | ||
% Date: 03/06/2008 | ||
%---------------------------------------------------------- | ||
|
||
|
||
% Decompose the matrix E by svd | ||
[u, s, v] = svd(e); | ||
|
||
% | ||
w = [0 -1 0; 1 0 0; 0 0 1]; | ||
z = [0 1 0; -1 0 0; 0 0 1]; | ||
|
||
% | ||
% E = SR where S = [t]_x and R is the rotation matrix. | ||
% E can be factorized as: | ||
%s = u * z * u'; | ||
|
||
% Two possibilities: | ||
rot1 = u * w * v'; | ||
rot2 = u * w' * v'; | ||
|
||
% Two possibilities: | ||
t1 = u(:,3) ./max(abs(u(:,3))); | ||
t2 = -u(:,3) ./max(abs(u(:,3))); | ||
|
||
|
||
% 4 possible choices of the camera matrix P2 based on the 2 possible | ||
% choices of R and 2 possible signs of t. | ||
rot(:,:,1) = rot1; | ||
t(:,:,1) = t1; | ||
|
||
rot(:,:,2) = rot2; | ||
t(:,:,2) = t2; | ||
|
||
rot(:,:,3) = rot1; | ||
t(:,:,3) = t2; | ||
|
||
rot(:,:,4) = rot2; | ||
t(:,:,4) = t1; |
Oops, something went wrong.