Skip to content

Commit

Permalink
import code frm v0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
dmaugis committed Jun 17, 2018
1 parent b8a319b commit a2d2fbc
Show file tree
Hide file tree
Showing 204 changed files with 12,547 additions and 2 deletions.
4 changes: 2 additions & 2 deletions LICENSE → COPYING
Original file line number Diff line number Diff line change
Expand Up @@ -633,8 +633,8 @@ the "copyright" line and a pointer to where the full notice is found.
Copyright (C) <year> <name of author>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
Expand Down
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# lazy makefile
PROG=detect_vps
all:
$(MAKE) -C mex_files/ all
mcc -m ${PROG}.m -a mex_files/ -a mixtures/ -a lib/ -R -nodisplay



109 changes: 109 additions & 0 deletions README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
Vanishing Points detection
==========================
version 0.6 - July 2015
by Jose Lezama <jlezama@gmail.com>


Introduction
------------

This code implements the vanishing point detection algorithm as described in the IPOL article
"Vanishing Point Detection in Urban Scenes Using Point Alignments" Jose Lezama, Gregory Randall, Jean-Michel Morel and Rafael Grompone von Gioi.

Optionally, this code uses the algorithm by Figueiredo and Jain, Unsupervised
learning of finite mixture models, to quickly obtain cluster candidates.

Files and Folders
-----------------

README.txt - This file
COPYING - GNU AFFERO GENERAL PUBLIC LICENSE Version 3
Makefile - Compilation instructions for 'make'
main.m - demo script
detect_vps.m - main algorithm script
yud_benchmark.m - script to run benchmark scores in York Urban Database
ecd_benchmark.m - script to run benchmark scores in Eurasian Citites Database
test.jpg - test image
lib/ - folder with auxiliary MATLAB scripts
mex_files/ - folder with C sources for line segment and point alignment detection, to be compiled as mex files
mixtures/ - folder with the unsupervised mixtures detection code of Figueiredo and Jain, which can optionally be used for accelerating the method


Compiling
---------

The algorithm depends on three mex scripts that need to be compiled before
execution. For compilation inside MATLAB, cd into the 'mex_files' folder and run
build.m

Optional: run make to produce compiled matlab executables

Running
-------

For a test run on the test image, run main.m
main.m calls the main function, detect_vps.m
Arguments of detect_vps.m are:
- img_in: filename of the input image
- folder_out: path to save resulting image and text files
- manhattan: boolean variable used to determine if the Manhattan-world
hypothesis is assumed
- acceleration: boolean variable used to determine if acceleration using
Figueiredo and Jain GMM algorithm should be used
- focal_ratio: ratio between the focal lenght and captor width
- input_params: optional input parameters


Benchmarks
----------

To run benchmarks on York Urban Dataset (YUD) and Eurasian Cities Dataset (ECD)
run yud_benchmark.m and ecd_benchmark.m. You should obtain results similar or
better to the ones reported in our CVPR paper.

Note that without the acceleration the scripts can be slow. In particular for
ECD the non-accelerated version can take up to 3 minutes per image (there are
103 images in that dataset).

The datasets are not provided but can be obtained from the following sites:

YUD, by P. Denis: http://www.elderlab.yorku.ca/YorkUrbanDB/
ECD, by O. Barinova: http://graphics.cs.msu.ru/en/research/projects/msr/geometry


Acceleration
------------

As an optional procedure, an accelerated version of the algorithm can be run by
setting the appropiate flag (see detect_vps.m). This version uses Figueiredo's
"Unsupervised Learning of Finite Mixture Models" algorithm to quickly obtain
cluster candidates.

The scripts files, available at the author's website (http://www.lx.it.pt/~mtf/)
are included, and have been slightly modified for speed improvement.


Copyright and License
---------------------

Copyright (c) 2013-2015 Jose Lezama <jlezama@gmail.com>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.


Thanks
------

We would be grateful to receive any comment, especially about errors,
bugs, or strange results.
Binary file added __MACOSX/._COPYING
Binary file not shown.
Binary file added __MACOSX/._Makefile
Binary file not shown.
Binary file added __MACOSX/._README.txt
Binary file not shown.
Binary file added __MACOSX/._detect_vps.m
Binary file not shown.
Binary file added __MACOSX/._ecd_benchmark.m
Binary file not shown.
Binary file added __MACOSX/._lib
Binary file not shown.
Binary file added __MACOSX/._main.m
Binary file not shown.
Binary file added __MACOSX/._mex_files
Binary file not shown.
Binary file added __MACOSX/._mixtures
Binary file not shown.
Binary file added __MACOSX/._out.txt
Binary file not shown.
Binary file added __MACOSX/._test.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added __MACOSX/._yud_benchmark.m
Binary file not shown.
Binary file added __MACOSX/lib/._.DS_Store
Binary file not shown.
Binary file added __MACOSX/lib/._PCLines_straight_all.m
Binary file not shown.
Binary file added __MACOSX/lib/._PCLines_twisted_all.m
Binary file not shown.
Binary file added __MACOSX/lib/._aggclus.m
Binary file not shown.
Binary file added __MACOSX/lib/._calc_auc.m
Binary file not shown.
Binary file added __MACOSX/lib/._compute_horizon_line_manhattan.m
Binary file not shown.
Binary file added __MACOSX/lib/._compute_horizon_line_non_manhattan.m
Binary file not shown.
Binary file added __MACOSX/lib/._convert_to_PClines.m
Binary file not shown.
Binary file added __MACOSX/lib/._denoise_lines.m
Binary file not shown.
Binary file added __MACOSX/lib/._draw_dual_spaces.m
Binary file not shown.
Binary file added __MACOSX/lib/._draw_lines.m
Binary file not shown.
Binary file added __MACOSX/lib/._draw_segments.m
Binary file not shown.
Binary file added __MACOSX/lib/._drawline.m
Binary file not shown.
Binary file added __MACOSX/lib/._find_detections.m
Binary file not shown.
Binary file added __MACOSX/lib/._find_endpoints_detections.m
Binary file not shown.
Binary file added __MACOSX/lib/._get_intersection.m
Binary file not shown.
Binary file added __MACOSX/lib/._line_to_homogeneous.m
Binary file not shown.
Binary file added __MACOSX/lib/._line_to_slope_offset.m
Binary file not shown.
Binary file added __MACOSX/lib/._my_cross.m
Binary file not shown.
Binary file added __MACOSX/lib/._my_repmat.m
Binary file not shown.
Binary file added __MACOSX/lib/._my_repmat2.m
Binary file not shown.
Binary file added __MACOSX/lib/._orthogonal_triplet.m
Binary file not shown.
Binary file added __MACOSX/lib/._read_detections_as_vps.m
Binary file not shown.
Binary file added __MACOSX/lib/._refine_detections.m
Binary file not shown.
Binary file added __MACOSX/lib/._remove_duplicates.m
Binary file not shown.
Binary file added __MACOSX/lib/._run_lsd.m
Binary file not shown.
Binary file added __MACOSX/mex_files/._.DS_Store
Binary file not shown.
Binary file added __MACOSX/mex_files/._Makefile
Binary file not shown.
Binary file added __MACOSX/mex_files/._alignments.mexmaci64
Binary file not shown.
Binary file added __MACOSX/mex_files/._alignments_fast.c
Binary file not shown.
Binary file added __MACOSX/mex_files/._alignments_fast.m
Binary file not shown.
Binary file added __MACOSX/mex_files/._alignments_fast.mexa64
Binary file not shown.
Binary file added __MACOSX/mex_files/._alignments_fast.mexmaci64
Binary file not shown.
Binary file added __MACOSX/mex_files/._alignments_slow.c
Binary file not shown.
Binary file added __MACOSX/mex_files/._alignments_slow.m
Binary file not shown.
Binary file added __MACOSX/mex_files/._alignments_slow.mexa64
Binary file not shown.
Binary file added __MACOSX/mex_files/._alignments_slow.mexmaci64
Binary file not shown.
Binary file added __MACOSX/mex_files/._build.m
Binary file not shown.
Binary file added __MACOSX/mex_files/._lib
Binary file not shown.
Binary file added __MACOSX/mex_files/._lsd.c
Binary file not shown.
Binary file added __MACOSX/mex_files/._lsd.h
Binary file not shown.
Binary file added __MACOSX/mex_files/._lsd.mexa64
Binary file not shown.
Binary file added __MACOSX/mex_files/._lsd.mexmaci64
Binary file not shown.
Binary file added __MACOSX/mex_files/._rand.o
Binary file not shown.
Binary file added __MACOSX/mex_files/lib/._.DS_Store
Binary file not shown.
Binary file added __MACOSX/mex_files/lib/._alignments.c
Binary file not shown.
Binary file added __MACOSX/mex_files/lib/._alignments.h
Binary file not shown.
Binary file added __MACOSX/mex_files/lib/._cmd_line_handler.c
Binary file not shown.
Binary file added __MACOSX/mex_files/lib/._cmd_line_handler.h
Binary file not shown.
Binary file added __MACOSX/mex_files/lib/._dimg_io.c
Binary file not shown.
Binary file added __MACOSX/mex_files/lib/._dimg_io.h
Binary file not shown.
Binary file added __MACOSX/mex_files/lib/._eps.c
Binary file not shown.
Binary file added __MACOSX/mex_files/lib/._eps.h
Binary file not shown.
Binary file added __MACOSX/mex_files/lib/._gauss.c
Binary file not shown.
Binary file added __MACOSX/mex_files/lib/._gauss.h
Binary file not shown.
Binary file added __MACOSX/mex_files/lib/._image.c
Binary file not shown.
Binary file added __MACOSX/mex_files/lib/._image.h
Binary file not shown.
Binary file added __MACOSX/mex_files/lib/._jirafa_lib.h
Binary file not shown.
Binary file added __MACOSX/mex_files/lib/._jirafa_lib.h.gch
Binary file not shown.
Binary file added __MACOSX/mex_files/lib/._misc.c
Binary file not shown.
Binary file added __MACOSX/mex_files/lib/._misc.h
Binary file not shown.
Binary file added __MACOSX/mex_files/lib/._nfa.c
Binary file not shown.
Binary file added __MACOSX/mex_files/lib/._nfa.h
Binary file not shown.
Binary file added __MACOSX/mex_files/lib/._ntuple.c
Binary file not shown.
Binary file added __MACOSX/mex_files/lib/._ntuple.h
Binary file not shown.
Binary file added __MACOSX/mex_files/lib/._ntuple_ll.c
Binary file not shown.
Binary file added __MACOSX/mex_files/lib/._ntuple_ll.h
Binary file not shown.
Binary file added __MACOSX/mex_files/lib/._ntuples_aux.c
Binary file not shown.
Binary file added __MACOSX/mex_files/lib/._ntuples_aux.h
Binary file not shown.
Binary file added __MACOSX/mex_files/lib/._pgm_io.c
Binary file not shown.
Binary file added __MACOSX/mex_files/lib/._pgm_io.h
Binary file not shown.
Binary file added __MACOSX/mex_files/lib/._rand.c
Binary file not shown.
Binary file added __MACOSX/mex_files/lib/._rand.h
Binary file not shown.
Binary file added __MACOSX/mex_files/lib/._svg.c
Binary file not shown.
Binary file added __MACOSX/mex_files/lib/._svg.h
Binary file not shown.
Binary file added __MACOSX/mex_files/lib/._x_gui.c
Binary file not shown.
Binary file added __MACOSX/mex_files/lib/._x_gui.h
Binary file not shown.
Binary file added __MACOSX/mixtures/._README.txt
Binary file not shown.
Binary file added __MACOSX/mixtures/._README.txt~
Binary file not shown.
Binary file added __MACOSX/mixtures/._elipsnorm.m
Binary file not shown.
Binary file added __MACOSX/mixtures/._genmix.m
Binary file not shown.
Binary file added __MACOSX/mixtures/._get_ellipse_endpoints.m
Binary file not shown.
Binary file added __MACOSX/mixtures/._mixtures4.m
Binary file not shown.
Binary file added __MACOSX/mixtures/._multinorm.m
Binary file not shown.
Binary file added __MACOSX/mixtures/._my_kron.m
Binary file not shown.
Binary file added __MACOSX/mixtures/._my_meshgrid.m
Binary file not shown.
Binary file added __MACOSX/mixtures/._my_multinorm.m
Binary file not shown.
Binary file added __MACOSX/mixtures/._my_repmat.m
Binary file not shown.
Binary file added __MACOSX/mixtures/._my_repmat2.m
Binary file not shown.
Binary file added __MACOSX/mixtures/._run_mixtures.m
Binary file not shown.
Binary file added __MACOSX/mixtures/._uninorm.m
Binary file not shown.
180 changes: 180 additions & 0 deletions detect_vps.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
function [horizon_line, vpimg] = detect_vps(img_in,folder_out,...
manhattan, acceleration, focal_ratio, input_params)

% DETECT_VPS
% Function for vanishing points and horizon line detection
%
% Version 0.5, February 2015
%
% arguments:
% - img_in: filename of the input image
% - folder_out: path to save resulting image and text files
% - manhattan: boolean variable used to determine if the Manhattan-world
% hypothesis is assumed
% - acceleration: boolean variable used to determine if acceleration using
% Figueiredo and Jain GMM algorithm should be used
% - focal_ratio: ratio between the focal lenght and captor width
% - input_params: optional input parameters
%
% output:
% - horizon_line: estimated horizon line in image coordinates
% - vpimg: esitmated vanishing points in image coordinates
%
% Copyright (C) 2015 Jose Lezama <jlezama@gmail.com>
%
% This program is free software: you can use, modify and/or
% redistribute it under the terms of the GNU General Public
% License as published by the Free Software Foundation, either
% version 3 of the License, or (at your option) any later
% version. You should have received a copy of this license along
% this program. If not, see <http://www.gnu.org/licenses/>.
%
% This program is free software: you can use, modify and/or
% redistribute it under the terms of the simplified BSD
% License. You should have received a copy of this license along
% this program. If not, see
% <http://www.opensource.org/licenses/bsd-license.html>.
%
% To the extent possible under law, the authors have dedicated all
% copyright and related and neighboring rights to this software to
% the public domain worldwide. This software is distributed without
% any warranty. You should have received a copy of the CC0 Public
% Domain Dedication along with this software. If not, see
% <http://creativecommons.org/publicdomain/zero/1.0/>.
%
% This program is provided for research and education only: you can
% use and/or modify it for these purposes, but you are not allowed
% to redistribute this work or derivative works in source or
% executable form. A license must be obtained from the patent right
% holders for any other use.

if ~isdeployed
addpath lib
end

% input parameters
if isdeployed
manhattan = str2num(manhattan);
acceleration = str2num(acceleration);
focal_ratio = str2num(focal_ratio);
end


if nargin < 6
input_params = struct();
end

params.MANHATTAN = manhattan;
params.ACCELERATION = acceleration;
params.img_in = img_in;
params.folder_out = folder_out;

if isdeployed
params.PLOT = 1;
params.PRINT = 1;
else
params.PLOT = 0;
params.PRINT = 0;
end

% method parameters
params.REFINE_THRESHOLD = 2; % (theta)
params.VARIATION_THRESHOLD = .3; % (zeta)
params.DUPLICATES_THRESHOLD = .05;%.3; % (delta)
params.VERTICAL_ANGLE_THRESHOLD = 50; % (omega)
params.INFINITY_THRESHOLD = 30; % (lambda)
params.FOCAL_RATIO = focal_ratio; % (f)
params.LENGTH_THRESHOLD = 1.71;; % (tau) final threshold will be sqrt(W+H)/tau
params.DIST_THRESHOLD =.165;% (kappa)

if params.MANHATTAN
% inclusive threshold
params.ORTHOGONALITY_THRESHOLD = cos(87.5*pi/180); % .058;
else
% exclusive threshold
params.ORTHOGONALITY_THRESHOLD = cos(77.5*pi/180);%cos(75*pi/180);
end


% acceleration parameters
params.MAX_POINTS_ACCELERATION = 200; % use acceleration if number of points is larger than this
params.GMM_Ks = [30 30 30];

% overwrite with optional input parameters
names = fieldnames(input_params);
for i=1:length(names)
v = getfield(input_params, names{i});
params = setfield(params, names{i}, v);
end

%% START SCRIPT

% read image
img = imread(img_in);
[params.H, params.W, ~] = size(img);


% length threshold based on image size
params.LENGTH_THRESHOLD = sqrt((params.H+params.W))/params.LENGTH_THRESHOLD;


% get line segments
lines = run_lsd(img_in);
lines_lsd = lines;

% denoise lines
[lines, line_endpoints] = denoise_lines(lines, params);

if params.PRINT
draw_lines(lines, line_endpoints, params);


end

% convert to PClines
[points_straight, points_twisted] = convert_to_PClines(lines, params);

% run alignment detector in straight and twisted spaces
[detections_straight, m1, b1] = find_detections(points_straight, params);
[detections_twisted, m2, b2] = find_detections(points_twisted, params);


% gather intial vanishing point detections
[mvp_all, NFAs] = read_detections_as_vps(detections_straight, m1, b1, ...
detections_twisted, m2, b2, params);

% refine detections
mvp_all = refine_detections(mvp_all, lines_lsd, params);

[mvp_all, NFAs] = remove_duplicates(mvp_all, NFAs,params);

% draw preliminary detections
if params.PRINT

img2 = draw_segments(img,mvp_all, lines_lsd, params);

imwrite(img2,sprintf('%s/vps_raw.png',params.folder_out));
end

% compute horizon line
if ~isempty(mvp_all);
if params.MANHATTAN
[horizon_line, vpimg] = compute_horizon_line_manhattan(mvp_all, NFAs, lines_lsd, params);
else
[horizon_line, vpimg] = compute_horizon_line_non_manhattan(mvp_all, NFAs, lines_lsd, params);
end
else
horizon_line = [];
vpimg = [];
imwrite(img,sprintf('%s/horizon_line.png',params.folder_out));
fileID = fopen(sprintf('%s/out.txt',params.folder_out),'w');
fprintf(fileID,'No Vanishing Points found.\n');
fclose(fileID);
end

if params.PRINT
draw_dual_spaces(points_straight, detections_straight, 'straight', vpimg, params)
draw_dual_spaces(points_twisted, detections_twisted, 'twisted', vpimg, params)
end

disp('FINISHED.')
86 changes: 86 additions & 0 deletions ecd_benchmark.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
% Benchmark VP detection on Eurasian Cities Dataset
%
% This program is written by Jose Lezama <jlezama@gmail.com> and
% distributed under the terms of the GPLv3 license.
%
% Eurasian Cities Dataset (ECD) by Olga Barinova
% http://graphics.cs.msu.ru/en/research/projects/msr/geometry
%
% Reported performance should be close to 89.8% for the training set
% (first 25 images) and 89.6% for the test set

clear
close all

tic

% point the following path to your local copy of ECD
DATASET_PATH = '/Users/jose/Documents/cmla/datasets/20130829_EurasianCitiesBase';

dirlist = dir(sprintf('%s/*.jpg',DATASET_PATH));

params.REFINE_THRESHOLD = .62;% 0.375;
params.VARIATION_THRESHOLD = .3;%.305;
params.DUPLICATES_THRESHOLD = .0001;%.0039;
params.DIST_THRESHOLD = .165;
params.INFINITY_THRESHOLD = 3.58; % (lambda)

focal_ratio = 1.08;% 1.05;


all_errors = zeros(size(dirlist));

PLOT = 0;

for f = 26:103%1:length(dirlist)
% load image and ground truth
img_filename = sprintf('%s/%s',DATASET_PATH, dirlist(f).name);
mat_filename = sprintf('%s/%shor.mat',DATASET_PATH, dirlist(f).name(1:end-4));

img = imread(img_filename);
[H, W, ~] = size(img);

if PLOT
img = imread(img_filename);
[H, W, ~] = size(img);
figure, imagesc(img)
end

manhattan = 0;
acceleration = 1;

% compute horizon line detection
horizon_line_ours = detect_vps(img_filename, '.', manhattan, acceleration, focal_ratio, params);


% load ground truth
load(mat_filename)

% compute horizon line estimation error
X = [1 W];
P_gt = [-horizon(1)/horizon(2) -horizon(3)/horizon(2)];
Y_gt = polyval(P_gt,X);
Y_ours = [horizon_line_ours(1) horizon_line_ours(W)];
err = max(abs(Y_gt-Y_ours))/H;

if PLOT
hold on
plot(X, Y_gt);
end

fprintf('----------------------------------------\n')
fprintf('File %i, error: %f\n', f, err);
fprintf('----------------------------------------\n')

all_errors(f) = err;
end

% compute AUC score for training and testing set
auc_train = calc_auc(all_errors(1:25));
auc_test = calc_auc(all_errors(26:end));

fprintf('AUCtrain: %2.4f. AUCtest:%2.4f\n', auc_train, auc_test);

% should output something close to AUCtrain: 0.8940. AUCtest:0.8970

toc
Binary file added lib/.DS_Store
Binary file not shown.
Loading

0 comments on commit a2d2fbc

Please sign in to comment.