commit
9c606686af
210 changed files with 800579 additions and 121 deletions
@ -0,0 +1,3 @@ |
||||
set(the_description "datasets tools") |
||||
ocv_define_module(datasetstools opencv_core) |
||||
|
@ -0,0 +1,331 @@ |
||||
********************************************************* |
||||
datasetstools. Tools for working with different datasets. |
||||
********************************************************* |
||||
|
||||
.. highlight:: cpp |
||||
|
||||
The datasetstools module includes classes for working with different datasets. |
||||
|
||||
First version of this module was implemented for **Fall2014 OpenCV Challenge**. |
||||
|
||||
Action Recognition |
||||
------------------ |
||||
|
||||
AR_hmdb |
||||
======= |
||||
.. ocv:class:: AR_hmdb |
||||
|
||||
Implements loading dataset: |
||||
|
||||
_`"HMDB: A Large Human Motion Database"`: http://serre-lab.clps.brown.edu/resource/hmdb-a-large-human-motion-database/ |
||||
|
||||
.. note:: Usage |
||||
|
||||
1. From link above download dataset files: hmdb51_org.rar & test_train_splits.rar. |
||||
|
||||
2. Unpack them. |
||||
|
||||
3. To load data run: ./opencv/build/bin/example_datasetstools_ar_hmdb -p=/home/user/path_to_unpacked_folders/ |
||||
|
||||
AR_sports |
||||
========= |
||||
.. ocv:class:: AR_sports |
||||
|
||||
Implements loading dataset: |
||||
|
||||
_`"Sports-1M Dataset"`: http://cs.stanford.edu/people/karpathy/deepvideo/ |
||||
|
||||
.. note:: Usage |
||||
|
||||
1. From link above download dataset files (git clone https://code.google.com/p/sports-1m-dataset/). |
||||
|
||||
2. To load data run: ./opencv/build/bin/example_datasetstools_ar_sports -p=/home/user/path_to_downloaded_folders/ |
||||
|
||||
Face Recognition |
||||
---------------- |
||||
|
||||
FR_lfw |
||||
====== |
||||
.. ocv:class:: FR_lfw |
||||
|
||||
Implements loading dataset: |
||||
|
||||
_`"Labeled Faces in the Wild-a"`: http://www.openu.ac.il/home/hassner/data/lfwa/ |
||||
|
||||
.. note:: Usage |
||||
|
||||
1. From link above download dataset file: lfwa.tar.gz. |
||||
|
||||
2. Unpack it. |
||||
|
||||
3. To load data run: ./opencv/build/bin/example_datasetstools_fr_lfw -p=/home/user/path_to_unpacked_folder/lfw2/ |
||||
|
||||
Gesture Recognition |
||||
------------------- |
||||
|
||||
GR_chalearn |
||||
=========== |
||||
.. ocv:class:: GR_chalearn |
||||
|
||||
Implements loading dataset: |
||||
|
||||
_`"ChaLearn Looking at People"`: http://gesture.chalearn.org/ |
||||
|
||||
.. note:: Usage |
||||
|
||||
1. Follow instruction from site above, download files for dataset "Track 3: Gesture Recognition": Train1.zip-Train5.zip, Validation1.zip-Validation3.zip (Register on site: www.codalab.org and accept the terms and conditions of competition: https://www.codalab.org/competitions/991#learn_the_details There are three mirrors for downloading dataset files. When I downloaded data only mirror: "Universitat Oberta de Catalunya" works). |
||||
|
||||
2. Unpack train archives Train1.zip-Train5.zip to one folder (currently loading validation files wasn't implemented) |
||||
|
||||
3. To load data run: ./opencv/build/bin/example_datasetstools_gr_chalearn -p=/home/user/path_to_unpacked_folder/ |
||||
|
||||
GR_skig |
||||
======= |
||||
.. ocv:class:: GR_skig |
||||
|
||||
Implements loading dataset: |
||||
|
||||
_`"Sheffield Kinect Gesture Dataset"`: http://lshao.staff.shef.ac.uk/data/SheffieldKinectGesture.htm |
||||
|
||||
.. note:: Usage |
||||
|
||||
1. From link above download dataset files: subject1_dep.7z-subject6_dep.7z, subject1_rgb.7z-subject6_rgb.7z. |
||||
|
||||
2. Unpack them. |
||||
|
||||
3. To load data run: ./opencv/build/bin/example_datasetstools_gr_skig -p=/home/user/path_to_unpacked_folders/ |
||||
|
||||
Human Pose Estimation |
||||
--------------------- |
||||
|
||||
HPE_parse |
||||
========= |
||||
.. ocv:class:: HPE_parse |
||||
|
||||
Implements loading dataset: |
||||
|
||||
_`"PARSE Dataset"`: http://www.ics.uci.edu/~dramanan/papers/parse/ |
||||
|
||||
.. note:: Usage |
||||
|
||||
1. From link above download dataset file: people.zip. |
||||
|
||||
2. Unpack it. |
||||
|
||||
3. To load data run: ./opencv/build/bin/example_datasetstools_hpe_parse -p=/home/user/path_to_unpacked_folder/people_all/ |
||||
|
||||
Image Registration |
||||
------------------ |
||||
|
||||
IR_affine |
||||
========= |
||||
.. ocv:class:: IR_affine |
||||
|
||||
Implements loading dataset: |
||||
|
||||
_`"Affine Covariant Regions Datasets"`: http://www.robots.ox.ac.uk/~vgg/data/data-aff.html |
||||
|
||||
.. note:: Usage |
||||
|
||||
1. From link above download dataset files: bark\\bikes\\boat\\graf\\leuven\\trees\\ubc\\wall.tar.gz. |
||||
|
||||
2. Unpack them. |
||||
|
||||
3. To load data, for example, for "bark", run: ./opencv/build/bin/example_datasetstools_ir_affine -p=/home/user/path_to_unpacked_folder/bark/ |
||||
|
||||
IR_robot |
||||
======== |
||||
.. ocv:class:: IR_robot |
||||
|
||||
Implements loading dataset: |
||||
|
||||
_`"Robot Data Set"`: http://roboimagedata.compute.dtu.dk/?page_id=24 |
||||
|
||||
.. note:: Usage |
||||
|
||||
1. From link above download files for dataset "Point Feature Data Set – 2010": SET001_6.tar.gz-SET055_60.tar.gz (there are two data sets: - Full resolution images (1200×1600), ~500 Gb and - Half size image (600×800), ~115 Gb.) |
||||
2. Unpack them to one folder. |
||||
|
||||
3. To load data run: ./opencv/build/bin/example_datasetstools_ir_robot -p=/home/user/path_to_unpacked_folder/ |
||||
|
||||
Image Segmentation |
||||
------------------ |
||||
|
||||
IS_bsds |
||||
======= |
||||
.. ocv:class:: IS_bsds |
||||
|
||||
Implements loading dataset: |
||||
|
||||
_`"The Berkeley Segmentation Dataset and Benchmark"`: https://www.eecs.berkeley.edu/Research/Projects/CS/vision/bsds/ |
||||
|
||||
.. note:: Usage |
||||
|
||||
1. From link above download dataset files: BSDS300-human.tgz & BSDS300-images.tgz. |
||||
|
||||
2. Unpack them. |
||||
|
||||
3. To load data run: ./opencv/build/bin/example_datasetstools_is_bsds -p=/home/user/path_to_unpacked_folder/BSDS300/ |
||||
|
||||
IS_weizmann |
||||
=========== |
||||
.. ocv:class:: IS_weizmann |
||||
|
||||
Implements loading dataset: |
||||
|
||||
_`"Weizmann Segmentation Evaluation Database"`: http://www.wisdom.weizmann.ac.il/~vision/Seg_Evaluation_DB/ |
||||
|
||||
.. note:: Usage |
||||
|
||||
1. From link above download dataset files: Weizmann_Seg_DB_1obj.ZIP & Weizmann_Seg_DB_2obj.ZIP. |
||||
|
||||
2. Unpack them. |
||||
|
||||
3. To load data, for example, for 1 object dataset, run: ./opencv/build/bin/example_datasetstools_is_weizmann -p=/home/user/path_to_unpacked_folder/1obj/ |
||||
|
||||
Multiview Stereo Matching |
||||
------------------------- |
||||
|
||||
MSM_epfl |
||||
======== |
||||
.. ocv:class:: MSM_epfl |
||||
|
||||
Implements loading dataset: |
||||
|
||||
_`"EPFL Multi-View Stereo"`: http://cvlabwww.epfl.ch/~strecha/multiview/denseMVS.html |
||||
|
||||
.. note:: Usage |
||||
|
||||
1. From link above download dataset files: castle_dense\\castle_dense_large\\castle_entry\\fountain\\herzjesu_dense\\herzjesu_dense_large_bounding\\cameras\\images\\p.tar.gz. |
||||
|
||||
2. Unpack them in separate folder for each object. For example, for "fountain", in folder fountain/ : fountain_dense_bounding.tar.gz -> bounding/, fountain_dense_cameras.tar.gz -> camera/, fountain_dense_images.tar.gz -> png/, fountain_dense_p.tar.gz -> P/ |
||||
|
||||
3. To load data, for example, for "fountain", run: ./opencv/build/bin/example_datasetstools_msm_epfl -p=/home/user/path_to_unpacked_folder/fountain/ |
||||
|
||||
MSM_middlebury |
||||
============== |
||||
.. ocv:class:: MSM_middlebury |
||||
|
||||
Implements loading dataset: |
||||
|
||||
_`"Stereo – Middlebury Computer Vision"`: http://vision.middlebury.edu/mview/ |
||||
|
||||
.. note:: Usage |
||||
|
||||
1. From link above download dataset files: dino\\dinoRing\\dinoSparseRing\\temple\\templeRing\\templeSparseRing.zip |
||||
|
||||
2. Unpack them. |
||||
|
||||
3. To load data, for example "temple" dataset, run: ./opencv/build/bin/example_datasetstools_msm_middlebury -p=/home/user/path_to_unpacked_folder/temple/ |
||||
|
||||
Object Recognition |
||||
------------------ |
||||
|
||||
OR_imagenet |
||||
=========== |
||||
.. ocv:class:: OR_imagenet |
||||
|
||||
Implements loading dataset: |
||||
|
||||
_`"ImageNet"`: http://www.image-net.org/ |
||||
|
||||
Currently implemented loading full list with urls. Planned to implement dataset from ILSVRC challenge. |
||||
|
||||
.. note:: Usage |
||||
|
||||
1. From link above download dataset file: imagenet_fall11_urls.tgz |
||||
|
||||
2. Unpack it. |
||||
|
||||
3. To load data run: ./opencv/build/bin/example_datasetstools_or_imagenet -p=/home/user/path_to_unpacked_file/ |
||||
|
||||
OR_sun |
||||
====== |
||||
.. ocv:class:: OR_sun |
||||
|
||||
Implements loading dataset: |
||||
|
||||
_`"SUN Database"`: http://sun.cs.princeton.edu/ |
||||
|
||||
Currently implemented loading "Scene Recognition Benchmark. SUN397". Planned to implement also "Object Detection Benchmark. SUN2012". |
||||
|
||||
.. note:: Usage |
||||
|
||||
1. From link above download dataset file: SUN397.tar |
||||
|
||||
2. Unpack it. |
||||
|
||||
3. To load data run: ./opencv/build/bin/example_datasetstools_or_sun -p=/home/user/path_to_unpacked_folder/SUN397/ |
||||
|
||||
SLAM |
||||
---- |
||||
|
||||
SLAM_kitti |
||||
========== |
||||
.. ocv:class:: SLAM_kitti |
||||
|
||||
Implements loading dataset: |
||||
|
||||
_`"KITTI Vision Benchmark"`: http://www.cvlibs.net/datasets/kitti/eval_odometry.php |
||||
|
||||
.. note:: Usage |
||||
|
||||
1. From link above download "Odometry" dataset files: data_odometry_gray\\data_odometry_color\\data_odometry_velodyne\\data_odometry_poses\\data_odometry_calib.zip. |
||||
|
||||
2. Unpack data_odometry_poses.zip, it creates folder dataset/poses/. After that unpack data_odometry_gray.zip, data_odometry_color.zip, data_odometry_velodyne.zip. Folder dataset/sequences/ will be created with folders 00/..21/. Each of these folders will contain: image_0/, image_1/, image_2/, image_3/, velodyne/ and files calib.txt & times.txt. These two last files will be replaced after unpacking data_odometry_calib.zip at the end. |
||||
|
||||
3. To load data run: ./opencv/build/bin/example_datasetstools_slam_kitti -p=/home/user/path_to_unpacked_folder/dataset/ |
||||
|
||||
SLAM_tumindoor |
||||
============== |
||||
.. ocv:class:: SLAM_tumindoor |
||||
|
||||
Implements loading dataset: |
||||
|
||||
_`"TUMindoor Dataset"`: http://www.navvis.lmt.ei.tum.de/dataset/ |
||||
|
||||
.. note:: Usage |
||||
|
||||
1. From link above download dataset files: dslr\\info\\ladybug\\pointcloud.tar.bz2 for each dataset: 11-11-28 (1st floor)\\11-12-13 (1st floor N1)\\11-12-17a (4th floor)\\11-12-17b (3rd floor)\\11-12-17c (Ground I)\\11-12-18a (Ground II)\\11-12-18b (2nd floor) |
||||
|
||||
2. Unpack them in separate folder for each dataset. dslr.tar.bz2 -> dslr/, info.tar.bz2 -> info/, ladybug.tar.bz2 -> ladybug/, pointcloud.tar.bz2 -> pointcloud/. |
||||
|
||||
3. To load each dataset run: ./opencv/build/bin/example_datasetstools_slam_tumindoor -p=/home/user/path_to_unpacked_folders/ |
||||
|
||||
Text Recognition |
||||
---------------- |
||||
|
||||
TR_chars |
||||
======== |
||||
.. ocv:class:: TR_chars |
||||
|
||||
Implements loading dataset: |
||||
|
||||
_`"The Chars74K Dataset"`: http://www.ee.surrey.ac.uk/CVSSP/demos/chars74k/ |
||||
|
||||
.. note:: Usage |
||||
|
||||
1. From link above download dataset files: EnglishFnt\\EnglishHnd\\EnglishImg\\KannadaHnd\\KannadaImg.tgz, ListsTXT.tgz. |
||||
|
||||
2. Unpack them. |
||||
|
||||
3. Move .m files from folder ListsTXT/ to appropriate folder. For example, English/list_English_Img.m for EnglishImg.tgz. |
||||
|
||||
4. To load data, for example "EnglishImg", run: ./opencv/build/bin/example_datasetstools_tr_chars -p=/home/user/path_to_unpacked_folder/English/ |
||||
|
||||
TR_svt |
||||
====== |
||||
.. ocv:class:: TR_svt |
||||
|
||||
Implements loading dataset: |
||||
|
||||
_`"The Street View Text Dataset"`: http://vision.ucsd.edu/~kai/svt/ |
||||
|
||||
.. note:: Usage |
||||
|
||||
1. From link above download dataset file: svt.zip. |
||||
|
||||
2. Unpack it. |
||||
|
||||
3. To load data run: ./opencv/build/bin/example_datasetstools_tr_svt -p=/home/user/path_to_unpacked_folder/svt/svt1/ |
||||
|
@ -0,0 +1,81 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Itseez Inc or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef OPENCV_DATASETSTOOLS_AR_HMDB_HPP |
||||
#define OPENCV_DATASETSTOOLS_AR_HMDB_HPP |
||||
|
||||
#include <string> |
||||
#include <vector> |
||||
|
||||
#include "opencv2/datasetstools/dataset.hpp" |
||||
|
||||
#include <opencv2/core.hpp> |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace datasetstools |
||||
{ |
||||
|
||||
struct AR_hmdbObj : public Object |
||||
{ |
||||
std::string name; |
||||
std::vector<std::string> videoNames; |
||||
}; |
||||
|
||||
class CV_EXPORTS AR_hmdb : public Dataset |
||||
{ |
||||
public: |
||||
AR_hmdb() {} |
||||
AR_hmdb(const std::string &path, int number = 0); |
||||
virtual ~AR_hmdb() {} |
||||
|
||||
virtual void load(const std::string &path, int number = 0); |
||||
|
||||
private: |
||||
void loadDataset(const std::string &path, int number = 0); |
||||
|
||||
void loadAction(const std::string &fileName, std::vector<std::string> &train_, std::vector<std::string> &test_); |
||||
}; |
||||
|
||||
} |
||||
} |
||||
|
||||
#endif |
@ -0,0 +1,81 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Itseez Inc or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef OPENCV_DATASETSTOOLS_AR_SPORTS_HPP |
||||
#define OPENCV_DATASETSTOOLS_AR_SPORTS_HPP |
||||
|
||||
#include <string> |
||||
#include <vector> |
||||
|
||||
#include "opencv2/datasetstools/dataset.hpp" |
||||
|
||||
#include <opencv2/core.hpp> |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace datasetstools |
||||
{ |
||||
|
||||
struct AR_sportsObj : public Object |
||||
{ |
||||
std::string videoUrl; |
||||
std::vector<int> labels; |
||||
}; |
||||
|
||||
class CV_EXPORTS AR_sports : public Dataset |
||||
{ |
||||
public: |
||||
AR_sports() {} |
||||
AR_sports(const std::string &path); |
||||
virtual ~AR_sports() {} |
||||
|
||||
virtual void load(const std::string &path, int number = 0); |
||||
|
||||
private: |
||||
void loadDataset(const std::string &path); |
||||
|
||||
void loadDatasetPart(const std::string &fileName, std::vector< Ptr<Object> > &dataset_); |
||||
}; |
||||
|
||||
} |
||||
} |
||||
|
||||
#endif |
@ -0,0 +1,74 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Itseez Inc or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef OPENCV_DATASETSTOOLS_DATASET_HPP |
||||
#define OPENCV_DATASETSTOOLS_DATASET_HPP |
||||
|
||||
#include <string> |
||||
#include <vector> |
||||
|
||||
#include <opencv2/core.hpp> |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace datasetstools |
||||
{ |
||||
|
||||
struct Object |
||||
{ |
||||
}; |
||||
|
||||
class CV_EXPORTS Dataset |
||||
{ |
||||
public: |
||||
Dataset() {} |
||||
virtual ~Dataset() {} |
||||
|
||||
virtual void load(const std::string &path, int number = 0) = 0; |
||||
|
||||
std::vector< Ptr<Object> > train; |
||||
std::vector< Ptr<Object> > test; |
||||
}; |
||||
|
||||
} |
||||
} |
||||
|
||||
#endif |
@ -0,0 +1,79 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Itseez Inc or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef OPENCV_DATASETSTOOLS_FR_LFW_HPP |
||||
#define OPENCV_DATASETSTOOLS_FR_LFW_HPP |
||||
|
||||
#include <string> |
||||
#include <vector> |
||||
|
||||
#include "opencv2/datasetstools/dataset.hpp" |
||||
|
||||
#include <opencv2/core.hpp> |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace datasetstools |
||||
{ |
||||
|
||||
struct FR_lfwObj : public Object |
||||
{ |
||||
std::string name; |
||||
std::vector<std::string> images; |
||||
}; |
||||
|
||||
class CV_EXPORTS FR_lfw : public Dataset |
||||
{ |
||||
public: |
||||
FR_lfw() {} |
||||
FR_lfw(const std::string &path); |
||||
virtual ~FR_lfw() {} |
||||
|
||||
virtual void load(const std::string &path, int number = 0); |
||||
|
||||
private: |
||||
void loadDataset(const std::string &path); |
||||
}; |
||||
|
||||
} |
||||
} |
||||
|
||||
#endif |
@ -0,0 +1,96 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Itseez Inc or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef OPENCV_DATASETSTOOLS_GR_CHALEARN_HPP |
||||
#define OPENCV_DATASETSTOOLS_GR_CHALEARN_HPP |
||||
|
||||
#include <string> |
||||
#include <vector> |
||||
|
||||
#include "opencv2/datasetstools/dataset.hpp" |
||||
|
||||
#include <opencv2/core.hpp> |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace datasetstools |
||||
{ |
||||
|
||||
struct groundTruth |
||||
{ |
||||
int gestureID, initialFrame, lastFrame; |
||||
}; |
||||
|
||||
struct join |
||||
{ |
||||
double Wx, Wy, Wz, Rx, Ry, Rz, Rw, Px, Py; |
||||
}; |
||||
|
||||
struct skeleton |
||||
{ |
||||
join s[20]; |
||||
}; |
||||
|
||||
struct GR_chalearnObj : public Object |
||||
{ |
||||
std::string name, nameColor, nameDepth, nameUser; |
||||
int numFrames, fps, depth; |
||||
std::vector<groundTruth> groundTruths; |
||||
std::vector<skeleton> skeletons; |
||||
}; |
||||
|
||||
class CV_EXPORTS GR_chalearn : public Dataset |
||||
{ |
||||
public: |
||||
GR_chalearn() {} |
||||
GR_chalearn(const std::string &path); |
||||
virtual ~GR_chalearn() {} |
||||
|
||||
virtual void load(const std::string &path, int number = 0); |
||||
|
||||
private: |
||||
void loadDataset(const std::string &path); |
||||
}; |
||||
|
||||
} |
||||
} |
||||
|
||||
#endif |
@ -0,0 +1,118 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Itseez Inc or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef OPENCV_DATASETSTOOLS_GR_SKIG_HPP |
||||
#define OPENCV_DATASETSTOOLS_GR_SKIG_HPP |
||||
|
||||
#include <string> |
||||
#include <vector> |
||||
|
||||
#include "opencv2/datasetstools/dataset.hpp" |
||||
|
||||
#include <opencv2/core.hpp> |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace datasetstools |
||||
{ |
||||
|
||||
enum actionType |
||||
{ |
||||
circle = 1, |
||||
triangle, |
||||
updown, |
||||
rightleft, |
||||
wave, |
||||
z, |
||||
cross, |
||||
comehere, |
||||
turnaround, |
||||
pat |
||||
}; |
||||
|
||||
enum poseType |
||||
{ |
||||
fist = 1, |
||||
index, |
||||
flat |
||||
}; |
||||
|
||||
enum illuminationType |
||||
{ |
||||
light = 1, |
||||
dark |
||||
}; |
||||
|
||||
enum backgroundType |
||||
{ |
||||
woodenBoard = 1, |
||||
whitePaper, |
||||
paperWithCharacters |
||||
}; |
||||
|
||||
struct GR_skigObj : public Object |
||||
{ |
||||
std::string rgb; |
||||
std::string dep; |
||||
char person; // 1..6
|
||||
backgroundType background; |
||||
illuminationType illumination; |
||||
poseType pose; |
||||
actionType type; |
||||
}; |
||||
|
||||
class CV_EXPORTS GR_skig : public Dataset |
||||
{ |
||||
public: |
||||
GR_skig() {} |
||||
GR_skig(const std::string &path); |
||||
virtual ~GR_skig() {} |
||||
|
||||
virtual void load(const std::string &path, int number = 0); |
||||
|
||||
private: |
||||
void loadDataset(const std::string &path); |
||||
}; |
||||
|
||||
} |
||||
} |
||||
|
||||
#endif |
@ -0,0 +1,78 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Itseez Inc or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef OPENCV_DATASETSTOOLS_HPE_PARSE_HPP |
||||
#define OPENCV_DATASETSTOOLS_HPE_PARSE_HPP |
||||
|
||||
#include <string> |
||||
#include <vector> |
||||
|
||||
#include "opencv2/datasetstools/dataset.hpp" |
||||
|
||||
#include <opencv2/core.hpp> |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace datasetstools |
||||
{ |
||||
|
||||
struct HPE_parseObj : public Object |
||||
{ |
||||
std::string name; |
||||
}; |
||||
|
||||
class CV_EXPORTS HPE_parse : public Dataset |
||||
{ |
||||
public: |
||||
HPE_parse() {} |
||||
HPE_parse(const std::string &path); |
||||
virtual ~HPE_parse() {} |
||||
|
||||
virtual void load(const std::string &path, int number = 0); |
||||
|
||||
private: |
||||
void loadDataset(const std::string &path); |
||||
}; |
||||
|
||||
} |
||||
} |
||||
|
||||
#endif |
@ -0,0 +1,80 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Itseez Inc or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef OPENCV_DATASETSTOOLS_IR_AFFINE_HPP |
||||
#define OPENCV_DATASETSTOOLS_IR_AFFINE_HPP |
||||
|
||||
#include <string> |
||||
#include <vector> |
||||
|
||||
#include "opencv2/datasetstools/dataset.hpp" |
||||
|
||||
#include <opencv2/core.hpp> |
||||
#include <opencv2/core/matx.hpp> |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace datasetstools |
||||
{ |
||||
|
||||
struct IR_affineObj : public Object |
||||
{ |
||||
std::string imageName; |
||||
Matx33d mat; |
||||
}; |
||||
|
||||
class CV_EXPORTS IR_affine : public Dataset |
||||
{ |
||||
public: |
||||
IR_affine() {} |
||||
IR_affine(const std::string &path); |
||||
virtual ~IR_affine() {} |
||||
|
||||
virtual void load(const std::string &path, int number = 0); |
||||
|
||||
private: |
||||
void loadDataset(const std::string &path); |
||||
}; |
||||
|
||||
} |
||||
} |
||||
|
||||
#endif |
@ -0,0 +1,84 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Itseez Inc or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef OPENCV_DATASETSTOOLS_IR_ROBOT_HPP |
||||
#define OPENCV_DATASETSTOOLS_IR_ROBOT_HPP |
||||
|
||||
#include <string> |
||||
#include <vector> |
||||
|
||||
#include "opencv2/datasetstools/dataset.hpp" |
||||
|
||||
#include <opencv2/core.hpp> |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace datasetstools |
||||
{ |
||||
|
||||
// calibration matrix from calibrationFile.mat
|
||||
// 2.8290e+03 0.0000e+00 8.0279e+02
|
||||
// 0.0000e+00 2.8285e+03 6.1618e+02
|
||||
// 0.0000e+00 0.0000e+00 1.0000e+00
|
||||
|
||||
struct IR_robotObj : public Object |
||||
{ |
||||
std::string name; |
||||
std::vector<std::string> images; // TODO: implement more complex structure
|
||||
}; |
||||
|
||||
class CV_EXPORTS IR_robot : public Dataset |
||||
{ |
||||
public: |
||||
IR_robot() {} |
||||
IR_robot(const std::string &path); |
||||
virtual ~IR_robot() {} |
||||
|
||||
virtual void load(const std::string &path, int number = 0); |
||||
|
||||
private: |
||||
void loadDataset(const std::string &path); |
||||
}; |
||||
|
||||
} |
||||
} |
||||
|
||||
#endif |
@ -0,0 +1,80 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Itseez Inc or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef OPENCV_DATASETSTOOLS_IS_BSDS_HPP |
||||
#define OPENCV_DATASETSTOOLS_IS_BSDS_HPP |
||||
|
||||
#include <string> |
||||
#include <vector> |
||||
|
||||
#include "opencv2/datasetstools/dataset.hpp" |
||||
|
||||
#include <opencv2/core.hpp> |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace datasetstools |
||||
{ |
||||
|
||||
struct IS_bsdsObj : public Object |
||||
{ |
||||
std::string name; |
||||
}; |
||||
|
||||
class CV_EXPORTS IS_bsds : public Dataset |
||||
{ |
||||
public: |
||||
IS_bsds() {} |
||||
IS_bsds(const std::string &path); |
||||
virtual ~IS_bsds() {} |
||||
|
||||
virtual void load(const std::string &path, int number = 0); |
||||
|
||||
private: |
||||
void loadDataset(const std::string &path); |
||||
|
||||
void loadDatasetPart(const std::string &fileName, std::vector< Ptr<Object> > &dataset_); |
||||
}; |
||||
|
||||
} |
||||
} |
||||
|
||||
#endif |
@ -0,0 +1,81 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Itseez Inc or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef OPENCV_DATASETSTOOLS_IS_WEIZMANN_HPP |
||||
#define OPENCV_DATASETSTOOLS_IS_WEIZMANN_HPP |
||||
|
||||
#include <string> |
||||
#include <vector> |
||||
|
||||
#include "opencv2/datasetstools/dataset.hpp" |
||||
|
||||
#include <opencv2/core.hpp> |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace datasetstools |
||||
{ |
||||
|
||||
struct IS_weizmannObj : public Object |
||||
{ |
||||
std::string imageName; |
||||
std::string srcBw; |
||||
std::string srcColor; |
||||
std::string humanSeg; // TODO: read human segmented
|
||||
}; |
||||
|
||||
class CV_EXPORTS IS_weizmann : public Dataset |
||||
{ |
||||
public: |
||||
IS_weizmann() {} |
||||
IS_weizmann(const std::string &path); |
||||
virtual ~IS_weizmann() {} |
||||
|
||||
virtual void load(const std::string &path, int number = 0); |
||||
|
||||
private: |
||||
void loadDataset(const std::string &path); |
||||
}; |
||||
|
||||
} |
||||
} |
||||
|
||||
#endif |
@ -0,0 +1,81 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Itseez Inc or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef OPENCV_DATASETSTOOLS_MSM_EPFL_HPP |
||||
#define OPENCV_DATASETSTOOLS_MSM_EPFL_HPP |
||||
|
||||
#include <string> |
||||
#include <vector> |
||||
|
||||
#include "opencv2/datasetstools/dataset.hpp" |
||||
|
||||
#include <opencv2/core.hpp> |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace datasetstools |
||||
{ |
||||
|
||||
struct MSM_epflObj : public Object |
||||
{ |
||||
std::string imageName; |
||||
std::vector<double> bounding, camera, p; // TODO: implement better structures
|
||||
}; |
||||
|
||||
class CV_EXPORTS MSM_epfl : public Dataset |
||||
{ |
||||
public: |
||||
MSM_epfl() {} |
||||
MSM_epfl(const std::string &path); |
||||
virtual ~MSM_epfl() {} |
||||
|
||||
virtual void load(const std::string &path, int number = 0); |
||||
|
||||
private: |
||||
void loadDataset(const std::string &path); |
||||
|
||||
void readFileDouble(const std::string &fileName, std::vector<double> &out); |
||||
}; |
||||
|
||||
} |
||||
} |
||||
|
||||
#endif |
@ -0,0 +1,81 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Itseez Inc or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef OPENCV_DATASETSTOOLS_MSM_MIDDLEBURY_HPP |
||||
#define OPENCV_DATASETSTOOLS_MSM_MIDDLEBURY_HPP |
||||
|
||||
#include <string> |
||||
#include <vector> |
||||
|
||||
#include "opencv2/datasetstools/dataset.hpp" |
||||
|
||||
#include <opencv2/core.hpp> |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace datasetstools |
||||
{ |
||||
|
||||
struct MSM_middleburyObj : public Object |
||||
{ |
||||
std::string imageName; |
||||
double k[3][3]; |
||||
double r[3][3]; |
||||
double t[3]; |
||||
}; |
||||
|
||||
class CV_EXPORTS MSM_middlebury : public Dataset |
||||
{ |
||||
public: |
||||
MSM_middlebury() {} |
||||
MSM_middlebury(const std::string &path); |
||||
virtual ~MSM_middlebury() {} |
||||
|
||||
virtual void load(const std::string &path, int number = 0); |
||||
|
||||
private: |
||||
void loadDataset(const std::string &path); |
||||
}; |
||||
|
||||
} |
||||
} |
||||
|
||||
#endif |
@ -0,0 +1,83 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Itseez Inc or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef OPENCV_DATASETSTOOLS_OR_IMAGENET_HPP |
||||
#define OPENCV_DATASETSTOOLS_OR_IMAGENET_HPP |
||||
|
||||
#include <string> |
||||
#include <vector> |
||||
#include <set> |
||||
|
||||
#include "opencv2/datasetstools/dataset.hpp" |
||||
|
||||
#include <opencv2/core.hpp> |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace datasetstools |
||||
{ |
||||
|
||||
struct OR_imagenetObj : public Object |
||||
{ |
||||
std::string wnid; |
||||
int id2; |
||||
std::string imageUrl; |
||||
}; |
||||
|
||||
class CV_EXPORTS OR_imagenet : public Dataset |
||||
{ |
||||
public: |
||||
OR_imagenet() {} |
||||
OR_imagenet(const std::string &path); |
||||
virtual ~OR_imagenet() {} |
||||
|
||||
virtual void load(const std::string &path, int number = 0); |
||||
|
||||
std::set<std::string> wnids; |
||||
|
||||
private: |
||||
void loadDataset(const std::string &path); |
||||
}; |
||||
|
||||
} |
||||
} |
||||
|
||||
#endif |
@ -0,0 +1,79 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Itseez Inc or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef OPENCV_DATASETSTOOLS_OR_SUN_HPP |
||||
#define OPENCV_DATASETSTOOLS_OR_SUN_HPP |
||||
|
||||
#include <string> |
||||
#include <vector> |
||||
|
||||
#include "opencv2/datasetstools/dataset.hpp" |
||||
|
||||
#include <opencv2/core.hpp> |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace datasetstools |
||||
{ |
||||
|
||||
struct OR_sunObj : public Object |
||||
{ |
||||
std::string name; |
||||
std::vector<std::string> imageNames; |
||||
}; |
||||
|
||||
class CV_EXPORTS OR_sun : public Dataset |
||||
{ |
||||
public: |
||||
OR_sun() {} |
||||
OR_sun(const std::string &path); |
||||
virtual ~OR_sun() {} |
||||
|
||||
virtual void load(const std::string &path, int number = 0); |
||||
|
||||
private: |
||||
void loadDataset(const std::string &path); |
||||
}; |
||||
|
||||
} |
||||
} |
||||
|
||||
#endif |
@ -0,0 +1,87 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Itseez Inc or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef OPENCV_DATASETSTOOLS_SLAM_KITTI_HPP |
||||
#define OPENCV_DATASETSTOOLS_SLAM_KITTI_HPP |
||||
|
||||
#include <string> |
||||
#include <vector> |
||||
|
||||
#include "opencv2/datasetstools/dataset.hpp" |
||||
|
||||
#include <opencv2/core.hpp> |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace datasetstools |
||||
{ |
||||
|
||||
struct pose |
||||
{ |
||||
double elem[12]; |
||||
}; |
||||
|
||||
struct SLAM_kittiObj : public Object |
||||
{ |
||||
std::string name; |
||||
std::vector<std::string> images[4]; |
||||
std::vector<std::string> velodyne; |
||||
std::vector<double> times, p[4]; |
||||
std::vector<pose> posesArray; |
||||
}; |
||||
|
||||
class CV_EXPORTS SLAM_kitti : public Dataset |
||||
{ |
||||
public: |
||||
SLAM_kitti() {} |
||||
SLAM_kitti(const std::string &path); |
||||
virtual ~SLAM_kitti() {} |
||||
|
||||
virtual void load(const std::string &path, int number = 0); |
||||
|
||||
private: |
||||
void loadDataset(const std::string &path); |
||||
}; |
||||
|
||||
} |
||||
} |
||||
|
||||
#endif |
@ -0,0 +1,87 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Itseez Inc or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef OPENCV_DATASETSTOOLS_SLAM_TUMINDOOR_HPP |
||||
#define OPENCV_DATASETSTOOLS_SLAM_TUMINDOOR_HPP |
||||
|
||||
#include <string> |
||||
#include <vector> |
||||
|
||||
#include "opencv2/datasetstools/dataset.hpp" |
||||
|
||||
#include <opencv2/core.hpp> |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace datasetstools |
||||
{ |
||||
|
||||
enum imageType |
||||
{ |
||||
LEFT = 0, |
||||
RIGHT, |
||||
LADYBUG |
||||
}; |
||||
|
||||
struct SLAM_tumindoorObj : public Object |
||||
{ |
||||
std::string name; |
||||
double transformMat[4][4]; |
||||
imageType type; |
||||
}; |
||||
|
||||
class CV_EXPORTS SLAM_tumindoor : public Dataset |
||||
{ |
||||
public: |
||||
SLAM_tumindoor() {} |
||||
SLAM_tumindoor(const std::string &path); |
||||
virtual ~SLAM_tumindoor() {} |
||||
|
||||
virtual void load(const std::string &path, int number = 0); |
||||
|
||||
private: |
||||
void loadDataset(const std::string &path); |
||||
}; |
||||
|
||||
} |
||||
} |
||||
|
||||
#endif |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,81 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Itseez Inc or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef OPENCV_DATASETSTOOLS_TR_CHARS_HPP |
||||
#define OPENCV_DATASETSTOOLS_TR_CHARS_HPP |
||||
|
||||
#include <string> |
||||
#include <vector> |
||||
|
||||
#include "opencv2/datasetstools/dataset.hpp" |
||||
|
||||
#include <opencv2/core.hpp> |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace datasetstools |
||||
{ |
||||
|
||||
struct TR_charsObj : public Object |
||||
{ |
||||
std::string imgName; |
||||
int label; |
||||
}; |
||||
|
||||
class CV_EXPORTS TR_chars : public Dataset |
||||
{ |
||||
public: |
||||
TR_chars() {} |
||||
TR_chars(const std::string &path, int number = 0); |
||||
virtual ~TR_chars() {} |
||||
|
||||
virtual void load(const std::string &path, int number = 0); |
||||
|
||||
private: |
||||
void loadDataset(const std::string &path, int number = 0); |
||||
|
||||
void parseLine(const std::string &line, std::vector<int> &currSet, int number); |
||||
}; |
||||
|
||||
} |
||||
} |
||||
|
||||
#endif |
@ -0,0 +1,88 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Itseez Inc or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef OPENCV_DATASETSTOOLS_TR_SVT_HPP |
||||
#define OPENCV_DATASETSTOOLS_TR_SVT_HPP |
||||
|
||||
#include <string> |
||||
#include <vector> |
||||
|
||||
#include "opencv2/datasetstools/dataset.hpp" |
||||
|
||||
#include <opencv2/core.hpp> |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace datasetstools |
||||
{ |
||||
|
||||
struct tag |
||||
{ |
||||
std::string value; |
||||
int height, width, x, y; |
||||
}; |
||||
|
||||
struct TR_svtObj : public Object |
||||
{ |
||||
std::string fileName; |
||||
std::vector<std::string> lex; |
||||
std::vector<tag> tags; |
||||
}; |
||||
|
||||
class CV_EXPORTS TR_svt : public Dataset |
||||
{ |
||||
public: |
||||
TR_svt() {} |
||||
TR_svt(const std::string &path); |
||||
virtual ~TR_svt() {} |
||||
|
||||
virtual void load(const std::string &path, int number = 0); |
||||
|
||||
private: |
||||
void loadDataset(const std::string &path); |
||||
|
||||
void xmlParse(const std::string &set, std::vector< Ptr<Object> > &out); |
||||
}; |
||||
|
||||
} |
||||
} |
||||
|
||||
#endif |
@ -0,0 +1,62 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Itseez Inc or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef OPENCV_DATASETSTOOLS_UTIL_HPP |
||||
#define OPENCV_DATASETSTOOLS_UTIL_HPP |
||||
|
||||
#include <string> |
||||
#include <vector> |
||||
|
||||
#include <opencv2/core.hpp> |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace datasetstools |
||||
{ |
||||
|
||||
void split(const std::string &s, std::vector<std::string> &elems, char delim); |
||||
|
||||
void getDirList(const std::string &dirName, std::vector<std::string> &fileNames); |
||||
|
||||
} |
||||
} |
||||
|
||||
#endif |
@ -0,0 +1,88 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Itseez Inc or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/datasetstools/ar_hmdb.hpp" |
||||
|
||||
#include <opencv2/core.hpp> |
||||
|
||||
#include <cstdio> |
||||
|
||||
#include <string> |
||||
#include <vector> |
||||
|
||||
using namespace std; |
||||
using namespace cv; |
||||
using namespace cv::datasetstools; |
||||
|
||||
int main(int argc, char *argv[]) |
||||
{ |
||||
const char *keys = |
||||
"{ help h usage ? | | show this message }" |
||||
"{ path p |true| path to dataset }"; |
||||
CommandLineParser parser(argc, argv, keys); |
||||
string path(parser.get<string>("path")); |
||||
if (parser.has("help") || path=="true") |
||||
{ |
||||
parser.printMessage(); |
||||
return -1; |
||||
} |
||||
|
||||
AR_hmdb dataset[3]; |
||||
for (int i=0; i<3; ++i) |
||||
{ |
||||
dataset[i].load(path, i); |
||||
} |
||||
|
||||
// ***************
|
||||
// dataset contains for each split: a set of video file names for each action.
|
||||
// For example, let output all training video file names for second split and first action.
|
||||
// And its size.
|
||||
AR_hmdbObj *example = static_cast<AR_hmdbObj *>(dataset[1].train[0].get()); |
||||
printf("name: %s\n", example->name.c_str()); |
||||
vector<string> &videoNames = example->videoNames; |
||||
printf("size: %u\n", (unsigned int)videoNames.size()); |
||||
for (vector<string>::iterator it=videoNames.begin(); it!=videoNames.end(); ++it) |
||||
{ |
||||
printf("%s\n", (*it).c_str()); |
||||
} |
||||
|
||||
return 0; |
||||
} |
@ -0,0 +1,89 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Itseez Inc or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/datasetstools/ar_sports.hpp" |
||||
|
||||
#include <opencv2/core.hpp> |
||||
|
||||
#include <cstdio> |
||||
#include <cstdlib> // atoi |
||||
|
||||
#include <string> |
||||
#include <vector> |
||||
|
||||
using namespace std; |
||||
using namespace cv; |
||||
using namespace cv::datasetstools; |
||||
|
||||
int main(int argc, char *argv[]) |
||||
{ |
||||
const char *keys = |
||||
"{ help h usage ? | | show this message }" |
||||
"{ path p |true| path to dataset description }"; |
||||
CommandLineParser parser(argc, argv, keys); |
||||
string path(parser.get<string>("path")); |
||||
if (parser.has("help") || path=="true") |
||||
{ |
||||
parser.printMessage(); |
||||
return -1; |
||||
} |
||||
|
||||
AR_sports dataset(path); |
||||
|
||||
// ***************
|
||||
// dataset. train & test contains for each video url in dataset all it's labels.
|
||||
// For example, let output the first element in test dataset and it's labels.
|
||||
// And sizes of both datasets.
|
||||
printf("train size: %u\n", (unsigned int)dataset.train.size()); |
||||
printf("test size: %u\n", (unsigned int)dataset.test.size()); |
||||
|
||||
AR_sportsObj *example = static_cast<AR_sportsObj *>(dataset.test[0].get()); |
||||
printf("url: %s\n", example->videoUrl.c_str()); |
||||
printf("labels: "); |
||||
vector<int> &labels = example->labels; |
||||
for (vector<int>::iterator it=labels.begin(); it!=labels.end(); ++it) |
||||
{ |
||||
printf("%u ", *it); |
||||
} |
||||
printf("\n"); |
||||
|
||||
return 0; |
||||
} |
@ -0,0 +1,83 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Itseez Inc or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/datasetstools/fr_lfw.hpp" |
||||
|
||||
#include <opencv2/core.hpp> |
||||
|
||||
#include <cstdio> |
||||
|
||||
#include <string> |
||||
#include <vector> |
||||
|
||||
using namespace std; |
||||
using namespace cv; |
||||
using namespace cv::datasetstools; |
||||
|
||||
int main(int argc, char *argv[]) |
||||
{ |
||||
const char *keys = |
||||
"{ help h usage ? | | show this message }" |
||||
"{ path p |true| path to dataset (lfw2 folder) }"; |
||||
CommandLineParser parser(argc, argv, keys); |
||||
string path(parser.get<string>("path")); |
||||
if (parser.has("help") || path=="true") |
||||
{ |
||||
parser.printMessage(); |
||||
return -1; |
||||
} |
||||
|
||||
FR_lfw dataset(path); |
||||
|
||||
// ***************
|
||||
// dataset contains object with name and its images.
|
||||
// For example, let output dataset size and sixth element.
|
||||
printf("dataset size: %u\n", (unsigned int)dataset.train.size()); |
||||
FR_lfwObj *example = static_cast<FR_lfwObj *>(dataset.train[5].get()); |
||||
printf("sixth dataset object:\n%s\n", example->name.c_str()); |
||||
string currPath(path + example->name + "/"); |
||||
for (vector<string>::iterator it=example->images.begin(); it!=example->images.end(); ++it) |
||||
{ |
||||
printf("%s\n", (currPath+(*it)).c_str()); |
||||
} |
||||
|
||||
return 0; |
||||
} |
@ -0,0 +1,95 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Itseez Inc or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/datasetstools/gr_chalearn.hpp" |
||||
|
||||
#include <opencv2/core.hpp> |
||||
|
||||
#include <cstdio> |
||||
|
||||
#include <string> |
||||
#include <vector> |
||||
|
||||
using namespace std; |
||||
using namespace cv; |
||||
using namespace cv::datasetstools; |
||||
|
||||
int main(int argc, char *argv[]) |
||||
{ |
||||
const char *keys = |
||||
"{ help h usage ? | | show this message }" |
||||
"{ path p |true| path to dataset folder }"; |
||||
CommandLineParser parser(argc, argv, keys); |
||||
string path(parser.get<string>("path")); |
||||
if (parser.has("help") || path=="true") |
||||
{ |
||||
parser.printMessage(); |
||||
return -1; |
||||
} |
||||
|
||||
GR_chalearn dataset(path); |
||||
|
||||
// ***************
|
||||
// dataset contains information for each sample.
|
||||
// For example, let output dataset size and first element.
|
||||
printf("dataset size: %u\n", (unsigned int)dataset.train.size()); |
||||
GR_chalearnObj *example = static_cast<GR_chalearnObj *>(dataset.train[0].get()); |
||||
printf("first dataset sample:\n%s\n", example->name.c_str()); |
||||
printf("color video:\n%s\n", example->nameColor .c_str()); |
||||
printf("depth video:\n%s\n", example->nameDepth.c_str()); |
||||
printf("user video:\n%s\n", example->nameUser.c_str()); |
||||
printf("video:\nnumber of frames: %u\nfps: %u\nmaximum depth: %u\n", example->numFrames, example->fps, example->depth); |
||||
for (vector<groundTruth>::iterator it=example->groundTruths.begin(); it!=example->groundTruths.end(); ++it) |
||||
{ |
||||
printf("gestureID: %u, initial frame: %u, last frame: %u\n", (*it).gestureID, (*it).initialFrame, (*it).lastFrame); |
||||
} |
||||
printf("skeletons number: %u\n", (unsigned int)example->skeletons.size()); |
||||
skeleton &last = example->skeletons.back(); |
||||
printf("last skeleton:\n"); |
||||
for (unsigned int i=0; i<20; ++i) |
||||
{ |
||||
printf("Wx: %f, Wy: %f, Wz: %f, Rx: %f, Ry: %f, Rz: %f, Rw: %f, Px: %f, Py: %f\n", |
||||
last.s[i].Wx, last.s[i].Wy, last.s[i].Wz, last.s[i].Rx, |
||||
last.s[i].Ry, last.s[i].Rz, last.s[i].Rw, last.s[i].Px, last.s[i].Py); |
||||
} |
||||
|
||||
return 0; |
||||
} |
@ -0,0 +1,81 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Itseez Inc or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/datasetstools/gr_skig.hpp" |
||||
|
||||
#include <opencv2/core.hpp> |
||||
|
||||
#include <cstdio> |
||||
#include <cstdlib> // atoi |
||||
|
||||
#include <string> |
||||
#include <vector> |
||||
|
||||
using namespace std; |
||||
using namespace cv; |
||||
using namespace cv::datasetstools; |
||||
|
||||
int main(int argc, char *argv[]) |
||||
{ |
||||
const char *keys = |
||||
"{ help h usage ? | | show this message }" |
||||
"{ path p |true| path to dataset (subject* folders) }"; |
||||
CommandLineParser parser(argc, argv, keys); |
||||
string path(parser.get<string>("path")); |
||||
if (parser.has("help") || path=="true") |
||||
{ |
||||
parser.printMessage(); |
||||
return -1; |
||||
} |
||||
|
||||
GR_skig dataset(path); |
||||
|
||||
// ***************
|
||||
// dataset contains pair of rgb\dep images
|
||||
// For example, let output train size and second element.
|
||||
GR_skigObj *example = static_cast<GR_skigObj *>(dataset.train[1].get()); |
||||
printf("train size: %u\n", (unsigned int)dataset.train.size()); |
||||
printf("second train image:\nrgb: %s\ndep: %s\n", example->rgb.c_str(), example->dep.c_str()); |
||||
printf("person: %u, backgroud: %u, illumination: %u, pose: %u, actionType: %u\n", |
||||
example->person, example->background, example->illumination, example->pose, example->type); |
||||
|
||||
return 0; |
||||
} |
@ -0,0 +1,81 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Itseez Inc or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/datasetstools/hpe_parse.hpp" |
||||
|
||||
#include <opencv2/core.hpp> |
||||
|
||||
#include <cstdio> |
||||
|
||||
#include <string> |
||||
#include <vector> |
||||
|
||||
using namespace std; |
||||
using namespace cv; |
||||
using namespace cv::datasetstools; |
||||
|
||||
int main(int argc, char *argv[]) |
||||
{ |
||||
const char *keys = |
||||
"{ help h usage ? | | show this message }" |
||||
"{ path p |true| path to dataset (people_all folder) }"; |
||||
CommandLineParser parser(argc, argv, keys); |
||||
string path(parser.get<string>("path")); |
||||
if (parser.has("help") || path=="true") |
||||
{ |
||||
parser.printMessage(); |
||||
return -1; |
||||
} |
||||
|
||||
HPE_parse dataset(path); |
||||
|
||||
// ***************
|
||||
// dataset. train & test contain appropriate images
|
||||
// For example, let output their sizes and first elements.
|
||||
printf("train size: %u\n", (unsigned int)dataset.train.size()); |
||||
printf("test size: %u\n", (unsigned int)dataset.test.size()); |
||||
HPE_parseObj *example1 = static_cast<HPE_parseObj *>(dataset.train[0].get()); |
||||
HPE_parseObj *example2 = static_cast<HPE_parseObj *>(dataset.test[0].get()); |
||||
printf("first train image: %s\n", example1->name.c_str()); |
||||
printf("first test image: %s\n", example2->name.c_str()); |
||||
|
||||
return 0; |
||||
} |
@ -0,0 +1,91 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Itseez Inc or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/datasetstools/ir_affine.hpp" |
||||
|
||||
#include <opencv2/core.hpp> |
||||
|
||||
#include <cstdio> |
||||
#include <cstdlib> // atoi |
||||
|
||||
#include <string> |
||||
#include <vector> |
||||
|
||||
using namespace std; |
||||
using namespace cv; |
||||
using namespace cv::datasetstools; |
||||
|
||||
int main(int argc, char *argv[]) |
||||
{ |
||||
const char *keys = |
||||
"{ help h usage ? | | show this message }" |
||||
"{ path p |true| path to dataset folder }"; |
||||
CommandLineParser parser(argc, argv, keys); |
||||
string path(parser.get<string>("path")); |
||||
if (parser.has("help") || path=="true") |
||||
{ |
||||
parser.printMessage(); |
||||
return -1; |
||||
} |
||||
|
||||
// loading dataset
|
||||
IR_affine dataset(path); |
||||
|
||||
// ***************
|
||||
// dataset contains for each image in dataset it's matrix.
|
||||
// For example, let output the last element in dataset and it's matrix.
|
||||
// And dataset size.
|
||||
printf("size: %u\n", (unsigned int)dataset.train.size()); |
||||
|
||||
IR_affineObj *example = static_cast<IR_affineObj *>(dataset.train.back().get()); |
||||
printf("image name: %s\n", example->imageName.c_str()); |
||||
printf("matrix:\n"); |
||||
for (int i=0; i<3; ++i) |
||||
{ |
||||
for (int j=0; j<3; ++j) |
||||
{ |
||||
printf("%f ", example->mat(i, j)); |
||||
} |
||||
printf("\n"); |
||||
} |
||||
|
||||
return 0; |
||||
} |
@ -0,0 +1,83 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Itseez Inc or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/datasetstools/ir_robot.hpp" |
||||
|
||||
#include <opencv2/core.hpp> |
||||
|
||||
#include <cstdio> |
||||
|
||||
#include <string> |
||||
#include <vector> |
||||
|
||||
using namespace std; |
||||
using namespace cv; |
||||
using namespace cv::datasetstools; |
||||
|
||||
int main(int argc, char *argv[]) |
||||
{ |
||||
const char *keys = |
||||
"{ help h usage ? | | show this message }" |
||||
"{ path p |true| path to dataset folders }"; |
||||
CommandLineParser parser(argc, argv, keys); |
||||
string path(parser.get<string>("path")); |
||||
if (parser.has("help") || path=="true") |
||||
{ |
||||
parser.printMessage(); |
||||
return -1; |
||||
} |
||||
|
||||
IR_robot dataset(path); |
||||
|
||||
// ***************
|
||||
// dataset contains object with name and its images.
|
||||
// For example, let output last element and dataset size.
|
||||
IR_robotObj *example = static_cast<IR_robotObj *>(dataset.train.back().get()); |
||||
printf("last dataset object:\n%s\n", example->name.c_str()); |
||||
string currPath(path + example->name + "/"); |
||||
for (vector<string>::iterator it=example->images.begin(); it!=example->images.end(); ++it) |
||||
{ |
||||
printf("%s\n", (currPath+(*it)).c_str()); |
||||
} |
||||
printf("dataset size: %u\n", (unsigned int)dataset.train.size()); |
||||
|
||||
return 0; |
||||
} |
@ -0,0 +1,87 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Itseez Inc or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/datasetstools/is_bsds.hpp" |
||||
|
||||
#include <opencv2/core.hpp> |
||||
|
||||
#include <cstdio> |
||||
|
||||
#include <string> |
||||
#include <vector> |
||||
|
||||
using namespace std; |
||||
using namespace cv; |
||||
using namespace cv::datasetstools; |
||||
|
||||
int main(int argc, char *argv[]) |
||||
{ |
||||
const char *keys = |
||||
"{ help h usage ? | | show this message }" |
||||
"{ path p |true| path to dataset (images, iids_train.txt, iids_test.txt) }"; |
||||
CommandLineParser parser(argc, argv, keys); |
||||
string path(parser.get<string>("path")); |
||||
if (parser.has("help") || path=="true") |
||||
{ |
||||
parser.printMessage(); |
||||
return -1; |
||||
} |
||||
|
||||
IS_bsds dataset(path); |
||||
|
||||
// TODO: read human/ folder for evaluation
|
||||
|
||||
// ***************
|
||||
// dataset. train & test contain names of appropriate images.
|
||||
// For example, let output full path & name for first train and test images.
|
||||
// And sets size.
|
||||
printf("train size: %u\n", (unsigned int)dataset.train.size()); |
||||
printf("test size: %u\n", (unsigned int)dataset.test.size()); |
||||
|
||||
IS_bsdsObj *example1 = static_cast<IS_bsdsObj *>(dataset.train[0].get()); |
||||
string fullPath(path + "images/train/" + example1->name + ".jpg"); |
||||
printf("first train image: %s\n", fullPath.c_str()); |
||||
IS_bsdsObj *example2 = static_cast<IS_bsdsObj *>(dataset.test[0].get()); |
||||
fullPath = path + "images/test/" + example2->name + ".jpg"; |
||||
printf("first test image: %s\n", fullPath.c_str()); |
||||
|
||||
return 0; |
||||
} |
@ -0,0 +1,79 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Itseez Inc or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/datasetstools/is_weizmann.hpp" |
||||
|
||||
#include <opencv2/core.hpp> |
||||
|
||||
#include <cstdio> |
||||
|
||||
#include <string> |
||||
#include <vector> |
||||
|
||||
using namespace std; |
||||
using namespace cv; |
||||
using namespace cv::datasetstools; |
||||
|
||||
int main(int argc, char *argv[]) |
||||
{ |
||||
const char *keys = |
||||
"{ help h usage ? | | show this message }" |
||||
"{ path p |true| path to dataset (1obj/2obj folders) }"; |
||||
CommandLineParser parser(argc, argv, keys); |
||||
string path(parser.get<string>("path")); |
||||
if (parser.has("help") || path=="true") |
||||
{ |
||||
parser.printMessage(); |
||||
return -1; |
||||
} |
||||
|
||||
IS_weizmann dataset(path); |
||||
|
||||
// ***************
|
||||
// dataset contains all information for each image.
|
||||
// For example, let output dataset size and first object.
|
||||
printf("dataset size: %u\n", (unsigned int)dataset.train.size()); |
||||
IS_weizmannObj *example = static_cast<IS_weizmannObj *>(dataset.train[0].get()); |
||||
printf("first image:\nname: %s\n", example->imageName.c_str()); |
||||
printf("src bw: %s\nsrc color: %s\n", example->srcBw.c_str(), example->srcColor.c_str()); |
||||
|
||||
return 0; |
||||
} |
@ -0,0 +1,99 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Itseez Inc or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/datasetstools/msm_epfl.hpp" |
||||
|
||||
#include <opencv2/core.hpp> |
||||
|
||||
#include <cstdio> |
||||
|
||||
#include <string> |
||||
#include <vector> |
||||
|
||||
using namespace std; |
||||
using namespace cv; |
||||
using namespace cv::datasetstools; |
||||
|
||||
int main(int argc, char *argv[]) |
||||
{ |
||||
const char *keys = |
||||
"{ help h usage ? | | show this message }" |
||||
"{ path p |true| path to dataset (bounding/, camera/, P/, png/ folders) }"; |
||||
CommandLineParser parser(argc, argv, keys); |
||||
string path(parser.get<string>("path")); |
||||
if (parser.has("help") || path=="true") |
||||
{ |
||||
parser.printMessage(); |
||||
return -1; |
||||
} |
||||
|
||||
MSM_epfl dataset(path); |
||||
|
||||
// ***************
|
||||
// dataset contains all information for each image.
|
||||
// For example, let output dataset size and first object.
|
||||
printf("dataset size: %u\n", (unsigned int)dataset.train.size()); |
||||
MSM_epflObj *example = static_cast<MSM_epflObj *>(dataset.train[0].get()); |
||||
printf("first image:\nname: %s\n", example->imageName.c_str()); |
||||
|
||||
printf("bounding:\n"); |
||||
for (vector<double>::iterator it=example->bounding.begin(); it!=example->bounding.end(); ++it) |
||||
{ |
||||
printf("%f ", *it); |
||||
} |
||||
printf("\n"); |
||||
|
||||
printf("camera:\n"); |
||||
for (vector<double>::iterator it=example->camera.begin(); it!=example->camera.end(); ++it) |
||||
{ |
||||
printf("%f ", *it); |
||||
} |
||||
printf("\n"); |
||||
|
||||
printf("P:\n"); |
||||
for (vector<double>::iterator it=example->p.begin(); it!=example->p.end(); ++it) |
||||
{ |
||||
printf("%f ", *it); |
||||
} |
||||
printf("\n"); |
||||
|
||||
return 0; |
||||
} |
@ -0,0 +1,102 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Itseez Inc or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/datasetstools/msm_middlebury.hpp" |
||||
|
||||
#include <opencv2/core.hpp> |
||||
|
||||
#include <cstdio> |
||||
|
||||
#include <string> |
||||
#include <vector> |
||||
|
||||
using namespace std; |
||||
using namespace cv; |
||||
using namespace cv::datasetstools; |
||||
|
||||
int main(int argc, char *argv[]) |
||||
{ |
||||
const char *keys = |
||||
"{ help h usage ? | | show this message }" |
||||
"{ path p |true| path to dataset description }"; |
||||
CommandLineParser parser(argc, argv, keys); |
||||
string path(parser.get<string>("path")); |
||||
if (parser.has("help") || path=="true") |
||||
{ |
||||
parser.printMessage(); |
||||
return -1; |
||||
} |
||||
|
||||
MSM_middlebury dataset(path); |
||||
|
||||
// ***************
|
||||
// dataset contains camera parameters for each image.
|
||||
// For example, let output number of elements and last element.
|
||||
printf("images number: %u\n", (unsigned int)dataset.train.size()); |
||||
MSM_middleburyObj *example = static_cast<MSM_middleburyObj *>(dataset.train.back().get()); |
||||
printf("last image name: %s\n", (path + example->imageName).c_str()); |
||||
printf("K:\n"); |
||||
for (int i=0; i<3; ++i) |
||||
{ |
||||
for (int j=0; j<3; ++j) |
||||
{ |
||||
printf("%f ", example->k[i][j]); |
||||
} |
||||
printf("\n"); |
||||
} |
||||
printf("R:\n"); |
||||
for (int i=0; i<3; ++i) |
||||
{ |
||||
for (int j=0; j<3; ++j) |
||||
{ |
||||
printf("%f ", example->r[i][j]); |
||||
} |
||||
printf("\n"); |
||||
} |
||||
printf("t:\n"); |
||||
for (int i=0; i<3; ++i) |
||||
{ |
||||
printf("%f ", example->t[i]); |
||||
} |
||||
printf("\n"); |
||||
|
||||
return 0; |
||||
} |
@ -0,0 +1,83 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Itseez Inc or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/datasetstools/or_imagenet.hpp" |
||||
|
||||
#include <opencv2/core.hpp> |
||||
|
||||
#include <cstdio> |
||||
#include <cstdlib> // atoi |
||||
|
||||
#include <string> |
||||
#include <vector> |
||||
#include <set> |
||||
|
||||
using namespace std; |
||||
using namespace cv; |
||||
using namespace cv::datasetstools; |
||||
|
||||
int main(int argc, char *argv[]) |
||||
{ |
||||
const char *keys = |
||||
"{ help h usage ? | | show this message }" |
||||
"{ path p |true| path to file with urls: fall11_urls.txt }"; |
||||
CommandLineParser parser(argc, argv, keys); |
||||
string path(parser.get<string>("path")); |
||||
if (parser.has("help") || path=="true") |
||||
{ |
||||
parser.printMessage(); |
||||
return -1; |
||||
} |
||||
|
||||
OR_imagenet dataset(path); |
||||
|
||||
// ***************
|
||||
// dataset contains for each object its id & image url.
|
||||
// For example, let output dataset size and first object.
|
||||
printf("dataset size: %u\n", (unsigned int)dataset.train.size()); |
||||
printf("wnids number: %u\n", (unsigned int)dataset.wnids.size()); |
||||
OR_imagenetObj *example = static_cast<OR_imagenetObj *>(dataset.train[0].get()); |
||||
printf("first object url: %s\n", example->imageUrl.c_str()); |
||||
printf("first object wnid: %s\n", example->wnid.c_str()); |
||||
printf("first object id2: %u\n", example->id2); |
||||
|
||||
return 0; |
||||
} |
@ -0,0 +1,84 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Itseez Inc or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/datasetstools/or_sun.hpp" |
||||
|
||||
#include <opencv2/core.hpp> |
||||
|
||||
#include <cstdio> |
||||
|
||||
#include <string> |
||||
#include <vector> |
||||
|
||||
using namespace std; |
||||
using namespace cv; |
||||
using namespace cv::datasetstools; |
||||
|
||||
int main(int argc, char *argv[]) |
||||
{ |
||||
const char *keys = |
||||
"{ help h usage ? | | show this message }" |
||||
"{ path p |true| path to dataset (SUN397 folder) }"; |
||||
CommandLineParser parser(argc, argv, keys); |
||||
string path(parser.get<string>("path")); |
||||
if (parser.has("help") || path=="true") |
||||
{ |
||||
parser.printMessage(); |
||||
return -1; |
||||
} |
||||
|
||||
OR_sun dataset(path); |
||||
|
||||
// ***************
|
||||
// dataset contains for each object its images.
|
||||
// For example, let output dataset size and last object.
|
||||
printf("dataset size: %u\n", (unsigned int)dataset.train.size()); |
||||
OR_sunObj *example = static_cast<OR_sunObj *>(dataset.train.back().get()); |
||||
printf("last object name: %s\n", example->name.c_str()); |
||||
printf("last object images number: %u\n", (unsigned int)example->imageNames.size()); |
||||
vector<string> &imageNames = example->imageNames; |
||||
for (vector<string>::iterator it=imageNames.begin(); it!=imageNames.end(); ++it) |
||||
{ |
||||
printf("%s\n", (*it).c_str()); |
||||
} |
||||
|
||||
return 0; |
||||
} |
@ -0,0 +1,128 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Itseez Inc or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/datasetstools/slam_kitti.hpp" |
||||
|
||||
#include <opencv2/core.hpp> |
||||
|
||||
#include <cstdio> |
||||
|
||||
#include <string> |
||||
#include <vector> |
||||
|
||||
using namespace std; |
||||
using namespace cv; |
||||
using namespace cv::datasetstools; |
||||
|
||||
int main(int argc, char *argv[]) |
||||
{ |
||||
const char *keys = |
||||
"{ help h usage ? | | show this message }" |
||||
"{ path p |true| path to dataset folders }"; |
||||
CommandLineParser parser(argc, argv, keys); |
||||
string path(parser.get<string>("path")); |
||||
if (parser.has("help") || path=="true") |
||||
{ |
||||
parser.printMessage(); |
||||
return -1; |
||||
} |
||||
|
||||
SLAM_kitti dataset(path); |
||||
|
||||
// ***************
|
||||
// dataset contains sequence with name and its data.
|
||||
// For example, let output first sequence and dataset size.
|
||||
printf("dataset size: %u\n", (unsigned int)dataset.train.size()); |
||||
|
||||
SLAM_kittiObj *example = static_cast<SLAM_kittiObj *>(dataset.train[0].get()); |
||||
printf("first dataset sequence:\n%s\n", example->name.c_str()); |
||||
|
||||
/*string pathVelodyne(path + "sequences/" + example->name + "/velodyne/");
|
||||
for (vector<string>::iterator it=example->velodyne.begin(); it!=example->velodyne.end(); ++it) |
||||
{ |
||||
printf("%s\n", (pathVelodyne + (*it)).c_str()); |
||||
}*/ |
||||
printf("number of velodyne images: %u\n", (unsigned int)example->velodyne.size()); |
||||
|
||||
for (unsigned int i=0; i<=3; ++i) |
||||
{ |
||||
/*char tmp[2];
|
||||
sprintf(tmp, "%u", i); |
||||
// 0,1 - gray, 2,3 - color
|
||||
string currPath(path + "sequences/" + example->name + "/image_" + tmp + "/"); |
||||
for (vector<string>::iterator it=example->images[i].begin(); it!=example->images[i].end(); ++it) |
||||
{ |
||||
printf("%s\n", (currPath + (*it)).c_str()); |
||||
}*/ |
||||
printf("number of images %u: %u\n", i, (unsigned int)example->images[i].size()); |
||||
} |
||||
|
||||
/*printf("times:\n");
|
||||
for (vector<double>::iterator it=example->times.begin(); it!=example->times.end(); ++it) |
||||
{ |
||||
printf("%f ", *it); |
||||
} |
||||
printf("\n");*/ |
||||
printf("number of times: %u\n", (unsigned int)example->times.size()); |
||||
|
||||
/*printf("poses:\n");
|
||||
for (vector<pose>::iterator it=example->posesArray.begin(); it!=example->posesArray.end(); ++it) |
||||
{ |
||||
for (unsigned int i=0; i<12; ++i) |
||||
{ |
||||
printf("%f ", (*it).elem[i]); |
||||
} |
||||
printf("\n"); |
||||
}*/ |
||||
printf("number of poses: %u\n", (unsigned int)example->posesArray.size()); |
||||
|
||||
for (unsigned int i=0; i<4; ++i) |
||||
{ |
||||
printf("calibration %u:\n", i); |
||||
for (vector<double>::iterator it=example->p[i].begin(); it!=example->p[i].end(); ++it) |
||||
{ |
||||
printf("%f ", *it); |
||||
} |
||||
printf("\n"); |
||||
} |
||||
|
||||
return 0; |
||||
} |
@ -0,0 +1,99 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Itseez Inc or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/datasetstools/slam_tumindoor.hpp" |
||||
|
||||
#include <opencv2/core.hpp> |
||||
|
||||
#include <cstdio> |
||||
|
||||
#include <string> |
||||
#include <vector> |
||||
|
||||
using namespace std; |
||||
using namespace cv; |
||||
using namespace cv::datasetstools; |
||||
|
||||
int main(int argc, char *argv[]) |
||||
{ |
||||
const char *keys = |
||||
"{ help h usage ? | | show this message }" |
||||
"{ path p |true| path to dataset folders }"; |
||||
CommandLineParser parser(argc, argv, keys); |
||||
string path(parser.get<string>("path")); |
||||
if (parser.has("help") || path=="true") |
||||
{ |
||||
parser.printMessage(); |
||||
return -1; |
||||
} |
||||
|
||||
SLAM_tumindoor dataset(path); |
||||
|
||||
// ***************
|
||||
// dataset contains image and its information.
|
||||
// For example, let output first image information and dataset size.
|
||||
printf("dataset size: %u\n", (unsigned int)dataset.train.size()); |
||||
|
||||
SLAM_tumindoorObj *example = static_cast<SLAM_tumindoorObj *>(dataset.train[0].get()); |
||||
printf("first image:\ntype: %u\n", example->type); |
||||
|
||||
string imagePath(path); |
||||
if (LADYBUG == example->type) |
||||
{ |
||||
imagePath += "ladybug/"; |
||||
} else |
||||
{ |
||||
imagePath += "dslr/"; |
||||
} |
||||
printf("file name: %s\n", (imagePath + example->name).c_str()); |
||||
|
||||
printf("transformation matrix:\n"); |
||||
for (unsigned int i=0; i<4; ++i) |
||||
{ |
||||
for (unsigned int j=0; j<4; ++j) |
||||
{ |
||||
printf("%f ", example->transformMat[i][j]); |
||||
} |
||||
printf("\n"); |
||||
} |
||||
|
||||
return 0; |
||||
} |
@ -0,0 +1,99 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Itseez Inc or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/datasetstools/tr_chars.hpp" |
||||
|
||||
#include <opencv2/core.hpp> |
||||
|
||||
#include <cstdio> |
||||
#include <cstdlib> // atoi |
||||
|
||||
#include <string> |
||||
#include <vector> |
||||
|
||||
using namespace std; |
||||
using namespace cv; |
||||
using namespace cv::datasetstools; |
||||
|
||||
int main(int argc, char *argv[]) |
||||
{ |
||||
const char *keys = |
||||
"{ help h usage ? | | show this message }" |
||||
"{ path p |true| path to dataset description file: list_English_Img.m }"; |
||||
CommandLineParser parser(argc, argv, keys); |
||||
string path(parser.get<string>("path")); |
||||
if (parser.has("help") || path=="true") |
||||
{ |
||||
parser.printMessage(); |
||||
return -1; |
||||
} |
||||
|
||||
vector<TR_chars> dataset; |
||||
do |
||||
{ |
||||
TR_chars curr; |
||||
dataset.push_back(curr); |
||||
|
||||
int number = (int)dataset.size()-1; |
||||
dataset.back().load(path, number); |
||||
} while (dataset.back().train.size()>0); |
||||
dataset.pop_back(); // remove last empty split
|
||||
|
||||
// ***************
|
||||
// dataset. train, test contain information about each element of appropriate sets and splits.
|
||||
// For example, let output first elements of these vectors and their sizes for last split.
|
||||
// And number of splits.
|
||||
printf("splits number: %u\n", (unsigned int)dataset.size()); |
||||
|
||||
vector< Ptr<Object> > &currTrain = dataset.back().train; |
||||
vector< Ptr<Object> > &currTest = dataset.back().test; |
||||
printf("train size: %u\n", (unsigned int)currTrain.size()); |
||||
printf("test size: %u\n", (unsigned int)currTest.size()); |
||||
|
||||
TR_charsObj *example1 = static_cast<TR_charsObj *>(currTrain[0].get()); |
||||
TR_charsObj *example2 = static_cast<TR_charsObj *>(currTest[0].get()); |
||||
printf("first train element:\nname: %s\n", example1->imgName.c_str()); |
||||
printf("label: %u\n", example1->label); |
||||
printf("first test element:\nname: %s\n", example2->imgName.c_str()); |
||||
printf("label: %u\n", example2->label); |
||||
|
||||
return 0; |
||||
} |
@ -0,0 +1,95 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Itseez Inc or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/datasetstools/tr_svt.hpp" |
||||
|
||||
#include <opencv2/core.hpp> |
||||
|
||||
#include <cstdio> |
||||
#include <cstdlib> // atoi |
||||
|
||||
#include <string> |
||||
#include <vector> |
||||
|
||||
using namespace std; |
||||
using namespace cv; |
||||
using namespace cv::datasetstools; |
||||
|
||||
int main(int argc, char *argv[]) |
||||
{ |
||||
const char *keys = |
||||
"{ help h usage ? | | show this message }" |
||||
"{ path p |true| path to dataset xml files }"; |
||||
CommandLineParser parser(argc, argv, keys); |
||||
string path(parser.get<string>("path")); |
||||
if (parser.has("help") || path=="true") |
||||
{ |
||||
parser.printMessage(); |
||||
return -1; |
||||
} |
||||
|
||||
// loading train & test images description
|
||||
TR_svt dataset(path); |
||||
|
||||
// ***************
|
||||
// dataset. train & test contains images description.
|
||||
// For example, let output the last element in train set and it's description.
|
||||
// And their sizes.
|
||||
printf("train size: %u\n", (unsigned int)dataset.train.size()); |
||||
printf("test size: %u\n", (unsigned int)dataset.test.size()); |
||||
|
||||
TR_svtObj *example = static_cast<TR_svtObj *>(dataset.train.back().get()); |
||||
printf("last element:\nfile name: %s", example->fileName.c_str()); |
||||
printf("\nlex: "); |
||||
for (vector<string>::iterator it=example->lex.begin(); it!=example->lex.end(); ++it) |
||||
{ |
||||
printf("%s,", (*it).c_str()); |
||||
} |
||||
printf("\ntags:\n"); |
||||
for (vector<tag>::iterator it=example->tags.begin(); it!=example->tags.end(); ++it) |
||||
{ |
||||
tag &t = (*it); |
||||
printf("%s\nheight: %u, width: %u, x: %u, y: %u\n", |
||||
t.value.c_str(), t.height, t.width, t.x, t.y); |
||||
} |
||||
|
||||
return 0; |
||||
} |
@ -0,0 +1,110 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Itseez Inc or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/datasetstools/ar_hmdb.hpp" |
||||
#include "precomp.hpp" |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace datasetstools |
||||
{ |
||||
|
||||
using namespace std; |
||||
|
||||
void AR_hmdb::loadAction(const string &fileName, vector<string> &train_, vector<string> &test_) |
||||
{ |
||||
ifstream infile(fileName.c_str()); |
||||
string video, label; |
||||
while (infile >> video >> label) |
||||
{ |
||||
if ("1"==label) |
||||
{ |
||||
train_.push_back(video); |
||||
} else |
||||
if ("2"==label) |
||||
{ |
||||
test_.push_back(video); |
||||
} |
||||
} |
||||
} |
||||
|
||||
AR_hmdb::AR_hmdb(const string &path, int number) |
||||
{ |
||||
loadDataset(path, number); |
||||
} |
||||
|
||||
void AR_hmdb::load(const string &path, int number) |
||||
{ |
||||
loadDataset(path, number); |
||||
} |
||||
|
||||
void AR_hmdb::loadDataset(const string &path, int number) |
||||
{ |
||||
// valid number [0,1,2]
|
||||
if (number<0 || number>2) |
||||
{ |
||||
return; |
||||
} |
||||
|
||||
string pathDataset(path + "hmdb51_org/"); |
||||
string pathSplit(path + "testTrainMulti_7030_splits/"); |
||||
|
||||
vector<string> fileNames; |
||||
getDirList(pathDataset, fileNames); |
||||
for (vector<string>::iterator it=fileNames.begin(); it!=fileNames.end(); ++it) |
||||
{ |
||||
Ptr<AR_hmdbObj> currTrain(new AR_hmdbObj); |
||||
Ptr<AR_hmdbObj> currTest(new AR_hmdbObj); |
||||
currTrain->name = *it; |
||||
currTest->name = *it; |
||||
|
||||
train.push_back(currTrain); |
||||
test.push_back(currTest); |
||||
|
||||
char tmp[2]; |
||||
sprintf(tmp, "%u", number+1); |
||||
string fileName(pathSplit + currTrain->name + "_test_split" + tmp + ".txt"); |
||||
loadAction(fileName, currTrain->videoNames, currTest->videoNames); |
||||
} |
||||
} |
||||
|
||||
} |
||||
} |
@ -0,0 +1,100 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Itseez Inc or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/datasetstools/ar_sports.hpp" |
||||
#include "precomp.hpp" |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace datasetstools |
||||
{ |
||||
|
||||
using namespace std; |
||||
|
||||
void AR_sports::loadDatasetPart(const string &fileName, vector< Ptr<Object> > &dataset_) |
||||
{ |
||||
ifstream infile(fileName.c_str()); |
||||
string videoUrl, labels; |
||||
while (infile >> videoUrl >> labels) |
||||
{ |
||||
Ptr<AR_sportsObj> curr(new AR_sportsObj); |
||||
curr->videoUrl = videoUrl; |
||||
|
||||
vector<string> elems; |
||||
split(labels, elems, ','); |
||||
for (vector<string>::iterator it=elems.begin(); it!=elems.end(); ++it) |
||||
{ |
||||
curr->labels.push_back(atoi((*it).c_str())); |
||||
} |
||||
|
||||
dataset_.push_back(curr); |
||||
} |
||||
} |
||||
|
||||
AR_sports::AR_sports(const string &path) |
||||
{ |
||||
loadDataset(path); |
||||
} |
||||
|
||||
void AR_sports::load(const string &path, int number) |
||||
{ |
||||
if (number!=0) |
||||
{ |
||||
return; |
||||
} |
||||
|
||||
loadDataset(path); |
||||
} |
||||
|
||||
void AR_sports::loadDataset(const string &path) |
||||
{ |
||||
string trainPath(path + "original/train_partition.txt"); |
||||
string testPath(path + "original/test_partition.txt"); |
||||
|
||||
// loading train video urls & labels
|
||||
loadDatasetPart(trainPath, train); |
||||
|
||||
// loading test video urls & labels
|
||||
loadDatasetPart(testPath, test); |
||||
} |
||||
|
||||
} |
||||
} |
@ -0,0 +1,89 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Itseez Inc or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/datasetstools/fr_lfw.hpp" |
||||
#include "precomp.hpp" |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace datasetstools |
||||
{ |
||||
|
||||
using namespace std; |
||||
|
||||
FR_lfw::FR_lfw(const string &path) |
||||
{ |
||||
loadDataset(path); |
||||
} |
||||
|
||||
void FR_lfw::load(const string &path, int number) |
||||
{ |
||||
if (number!=0) |
||||
{ |
||||
return; |
||||
} |
||||
|
||||
loadDataset(path); |
||||
} |
||||
|
||||
void FR_lfw::loadDataset(const string &path) |
||||
{ |
||||
vector<string> fileNames; |
||||
getDirList(path, fileNames); |
||||
for (vector<string>::iterator it=fileNames.begin(); it!=fileNames.end(); ++it) |
||||
{ |
||||
Ptr<FR_lfwObj> curr(new FR_lfwObj); |
||||
curr->name = *it; |
||||
|
||||
string pathFace(path + curr->name + "/"); |
||||
vector<string> faceNames; |
||||
getDirList(pathFace, faceNames); |
||||
for (vector<string>::iterator itFace=faceNames.begin(); itFace!=faceNames.end(); ++itFace) |
||||
{ |
||||
curr->images.push_back(*itFace); |
||||
} |
||||
|
||||
train.push_back(curr); |
||||
} |
||||
} |
||||
|
||||
} |
||||
} |
@ -0,0 +1,137 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Itseez Inc or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/datasetstools/gr_chalearn.hpp" |
||||
#include "precomp.hpp" |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace datasetstools |
||||
{ |
||||
|
||||
using namespace std; |
||||
|
||||
GR_chalearn::GR_chalearn(const string &path) |
||||
{ |
||||
loadDataset(path); |
||||
} |
||||
|
||||
void GR_chalearn::load(const string &path, int number) |
||||
{ |
||||
if (number!=0) |
||||
{ |
||||
return; |
||||
} |
||||
|
||||
loadDataset(path); |
||||
} |
||||
|
||||
void GR_chalearn::loadDataset(const string &path) |
||||
{ |
||||
vector<string> fileNames; |
||||
getDirList(path, fileNames); |
||||
for (vector<string>::iterator it=fileNames.begin(); it!=fileNames.end(); ++it) |
||||
{ |
||||
Ptr<GR_chalearnObj> curr(new GR_chalearnObj); |
||||
curr->name = *it; |
||||
curr->nameColor = curr->name + "/" + curr->name + "_color.mp4"; |
||||
curr->nameDepth = curr->name + "/" + curr->name + "_depth.mp4"; |
||||
curr->nameUser = curr->name + "/" + curr->name + "_user.mp4"; |
||||
|
||||
// loading video info
|
||||
string fileVideoInfo(path + curr->name + "/" + curr->name + "_data.csv"); |
||||
ifstream infile(fileVideoInfo.c_str()); |
||||
string line; |
||||
getline(infile, line); |
||||
vector<string> elems; |
||||
split(line, elems, ','); |
||||
curr->numFrames = atoi(elems[0].c_str()); |
||||
curr->fps = atoi(elems[1].c_str()); |
||||
curr->depth = atoi(elems[2].c_str()); |
||||
|
||||
// loading ground truth
|
||||
string fileGroundTruth(path + curr->name + "/" + curr->name + "_labels.csv"); |
||||
ifstream infileGroundTruth(fileGroundTruth.c_str()); |
||||
while (getline(infileGroundTruth, line)) |
||||
{ |
||||
vector<string> elems2; |
||||
split(line, elems2, ','); |
||||
|
||||
groundTruth currGroundTruth; |
||||
currGroundTruth.gestureID = atoi(elems2[0].c_str()); |
||||
currGroundTruth.initialFrame = atoi(elems2[1].c_str()); |
||||
currGroundTruth.lastFrame = atoi(elems2[2].c_str()); |
||||
|
||||
curr->groundTruths.push_back(currGroundTruth); |
||||
} |
||||
|
||||
// loading skeleton
|
||||
string fileSkeleton(path + curr->name + "/" + curr->name + "_skeleton.csv"); |
||||
ifstream infileSkeleton(fileSkeleton.c_str()); |
||||
while (getline(infileSkeleton, line)) |
||||
{ |
||||
skeleton currSkeleton; |
||||
|
||||
vector<string> elems2; |
||||
split(line, elems2, ','); |
||||
|
||||
for (unsigned int i=0, numJoin=0; i<elems2.size(); i+=9, ++numJoin) |
||||
{ |
||||
currSkeleton.s[numJoin].Wx = atof(elems2[i+0].c_str()); |
||||
currSkeleton.s[numJoin].Wy = atof(elems2[i+1].c_str()); |
||||
currSkeleton.s[numJoin].Wz = atof(elems2[i+2].c_str()); |
||||
currSkeleton.s[numJoin].Rx = atof(elems2[i+3].c_str()); |
||||
currSkeleton.s[numJoin].Ry = atof(elems2[i+4].c_str()); |
||||
currSkeleton.s[numJoin].Rz = atof(elems2[i+5].c_str()); |
||||
currSkeleton.s[numJoin].Rw = atof(elems2[i+6].c_str()); |
||||
currSkeleton.s[numJoin].Px = atof(elems2[i+7].c_str()); |
||||
currSkeleton.s[numJoin].Py = atof(elems2[i+8].c_str()); |
||||
} |
||||
|
||||
curr->skeletons.push_back(currSkeleton); |
||||
} |
||||
|
||||
train.push_back(curr); |
||||
} |
||||
} |
||||
|
||||
} |
||||
} |
@ -0,0 +1,107 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Itseez Inc or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/datasetstools/gr_skig.hpp" |
||||
#include "precomp.hpp" |
||||
|
||||
#include <cstring> |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace datasetstools |
||||
{ |
||||
|
||||
using namespace std; |
||||
|
||||
GR_skig::GR_skig(const string &path) |
||||
{ |
||||
loadDataset(path); |
||||
} |
||||
|
||||
void GR_skig::load(const string &path, int number) |
||||
{ |
||||
if (number!=0) |
||||
{ |
||||
return; |
||||
} |
||||
|
||||
loadDataset(path); |
||||
} |
||||
|
||||
void GR_skig::loadDataset(const string &path) |
||||
{ |
||||
for (unsigned int i=1; i<=6; ++i) |
||||
{ |
||||
char number[2]; |
||||
sprintf(number, "%u", i); |
||||
string pathDatasetRgb(path + "subject" + number + "_rgb/"); |
||||
string pathDatasetDep(path + "subject" + number + "_dep/"); |
||||
|
||||
vector<string> fileNames; |
||||
getDirList(pathDatasetRgb, fileNames); |
||||
for (vector<string>::iterator it=fileNames.begin(); it!=fileNames.end(); ++it) |
||||
{ |
||||
string &file = *it; |
||||
|
||||
Ptr<GR_skigObj> curr(new GR_skigObj); |
||||
curr->rgb = pathDatasetRgb + file; |
||||
curr->dep = file; |
||||
curr->dep[0] = 'K'; |
||||
curr->dep = pathDatasetDep + curr->dep; |
||||
|
||||
size_t pos = file.find("person_"); // TODO: check ::npos
|
||||
curr->person = (unsigned char)atoi( file.substr(pos+strlen("person_"), 1).c_str() ); |
||||
pos = file.find("backgroud_"); |
||||
curr->background = (backgroundType)atoi( file.substr(pos+strlen("backgroud_"), 1).c_str() ); |
||||
pos = file.find("illumination_"); |
||||
curr->illumination = (illuminationType)atoi( file.substr(pos+strlen("illumination_"), 1).c_str() ); |
||||
pos = file.find("pose_"); |
||||
curr->pose = (poseType)atoi( file.substr(pos+strlen("pose_"), 1).c_str() ); |
||||
pos = file.find("actionType_"); |
||||
curr->type = (actionType)atoi( file.substr(pos+strlen("actionType_"), 2).c_str() ); |
||||
|
||||
train.push_back(curr); |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
||||
} |
@ -0,0 +1,98 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Itseez Inc or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/datasetstools/hpe_parse.hpp" |
||||
#include "precomp.hpp" |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace datasetstools |
||||
{ |
||||
|
||||
using namespace std; |
||||
|
||||
HPE_parse::HPE_parse(const string &path) |
||||
{ |
||||
loadDataset(path); |
||||
} |
||||
|
||||
void HPE_parse::load(const string &path, int number) |
||||
{ |
||||
if (number!=0) |
||||
{ |
||||
return; |
||||
} |
||||
|
||||
loadDataset(path); |
||||
} |
||||
|
||||
void HPE_parse::loadDataset(const string &path) |
||||
{ |
||||
unsigned int i=0; |
||||
vector<string> fileNames; |
||||
getDirList(path, fileNames); |
||||
for (vector<string>::iterator it=fileNames.begin(); it!=fileNames.end(); ++it) |
||||
{ |
||||
string &file = *it, ext; |
||||
size_t len = file.length(); |
||||
if (len>4) |
||||
{ |
||||
ext = file.substr(len-4, 4); |
||||
} |
||||
if (ext==".jpg") |
||||
{ |
||||
Ptr<HPE_parseObj> curr(new HPE_parseObj); |
||||
curr->name = file; |
||||
|
||||
if (i<100) |
||||
{ |
||||
train.push_back(curr); |
||||
} else |
||||
{ |
||||
test.push_back(curr); |
||||
} |
||||
++i; |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
||||
} |
@ -0,0 +1,95 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Itseez Inc or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/datasetstools/ir_affine.hpp" |
||||
#include "precomp.hpp" |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace datasetstools |
||||
{ |
||||
|
||||
using namespace std; |
||||
|
||||
IR_affine::IR_affine(const string &path) |
||||
{ |
||||
loadDataset(path); |
||||
} |
||||
|
||||
void IR_affine::load(const string &path, int number) |
||||
{ |
||||
if (number!=0) |
||||
{ |
||||
return; |
||||
} |
||||
|
||||
loadDataset(path); |
||||
} |
||||
|
||||
void IR_affine::loadDataset(const string &path) |
||||
{ |
||||
for (unsigned int i=1; i<=6; ++i) |
||||
{ |
||||
Ptr<IR_affineObj> curr(new IR_affineObj); |
||||
|
||||
char tmp[2]; |
||||
sprintf(tmp, "%u", i); |
||||
curr->imageName = path + "img" + tmp + ".ppm"; |
||||
|
||||
if (i>1) |
||||
{ |
||||
string matName(path + "H1to" + tmp + "p"); |
||||
ifstream infile(matName.c_str()); |
||||
for (int k=0; k<3; ++k) |
||||
{ |
||||
for (int j=0; j<3; ++j) |
||||
{ |
||||
infile >> curr->mat(k, j); |
||||
} |
||||
} |
||||
} |
||||
|
||||
train.push_back(curr); |
||||
} |
||||
} |
||||
|
||||
} |
||||
} |
@ -0,0 +1,89 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Itseez Inc or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/datasetstools/ir_robot.hpp" |
||||
#include "precomp.hpp" |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace datasetstools |
||||
{ |
||||
|
||||
using namespace std; |
||||
|
||||
IR_robot::IR_robot(const string &path) |
||||
{ |
||||
loadDataset(path); |
||||
} |
||||
|
||||
void IR_robot::load(const string &path, int number) |
||||
{ |
||||
if (number!=0) |
||||
{ |
||||
return; |
||||
} |
||||
|
||||
loadDataset(path); |
||||
} |
||||
|
||||
void IR_robot::loadDataset(const string &path) |
||||
{ |
||||
vector<string> fileNames; |
||||
getDirList(path, fileNames); |
||||
for (vector<string>::iterator it=fileNames.begin(); it!=fileNames.end(); ++it) |
||||
{ |
||||
Ptr<IR_robotObj> curr(new IR_robotObj); |
||||
curr->name = *it; |
||||
|
||||
string pathScene(path + curr->name + "/"); |
||||
vector<string> sceneNames; |
||||
getDirList(pathScene, sceneNames); |
||||
for (vector<string>::iterator itScene=sceneNames.begin(); itScene!=sceneNames.end(); ++itScene) |
||||
{ |
||||
curr->images.push_back(*itScene); |
||||
} |
||||
|
||||
train.push_back(curr); |
||||
} |
||||
} |
||||
|
||||
} |
||||
} |
@ -0,0 +1,92 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Itseez Inc or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/datasetstools/is_bsds.hpp" |
||||
#include "precomp.hpp" |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace datasetstools |
||||
{ |
||||
|
||||
using namespace std; |
||||
|
||||
void IS_bsds::loadDatasetPart(const string &fileName, vector< Ptr<Object> > &dataset_) |
||||
{ |
||||
ifstream infile(fileName.c_str()); |
||||
string imageName; |
||||
while (infile >> imageName) |
||||
{ |
||||
Ptr<IS_bsdsObj> curr(new IS_bsdsObj); |
||||
curr->name = imageName; |
||||
dataset_.push_back(curr); |
||||
} |
||||
} |
||||
|
||||
IS_bsds::IS_bsds(const string &path) |
||||
{ |
||||
loadDataset(path); |
||||
} |
||||
|
||||
void IS_bsds::load(const string &path, int number) |
||||
{ |
||||
if (number!=0) |
||||
{ |
||||
return; |
||||
} |
||||
|
||||
loadDataset(path); |
||||
} |
||||
|
||||
void IS_bsds::loadDataset(const string &path) |
||||
{ |
||||
string trainName(path + "iids_train.txt"); |
||||
string testName(path + "iids_test.txt"); |
||||
|
||||
// loading train
|
||||
loadDatasetPart(trainName, train); |
||||
|
||||
// loading test
|
||||
loadDatasetPart(testName, test); |
||||
} |
||||
|
||||
} |
||||
} |
@ -0,0 +1,89 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Itseez Inc or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/datasetstools/is_weizmann.hpp" |
||||
#include "precomp.hpp" |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace datasetstools |
||||
{ |
||||
|
||||
using namespace std; |
||||
|
||||
IS_weizmann::IS_weizmann(const string &path) |
||||
{ |
||||
loadDataset(path); |
||||
} |
||||
|
||||
void IS_weizmann::load(const string &path, int number) |
||||
{ |
||||
if (number!=0) |
||||
{ |
||||
return; |
||||
} |
||||
|
||||
loadDataset(path); |
||||
} |
||||
|
||||
void IS_weizmann::loadDataset(const string &path) |
||||
{ |
||||
vector<string> fileNames; |
||||
getDirList(path, fileNames); |
||||
for (vector<string>::iterator it=fileNames.begin(); it!=fileNames.end(); ++it) |
||||
{ |
||||
string &imageName = *it; |
||||
if (imageName.find('.') == string::npos) // only folders, discard .mat
|
||||
{ |
||||
Ptr<IS_weizmannObj> curr(new IS_weizmannObj); |
||||
curr->imageName = imageName; |
||||
curr->srcBw = imageName + "/src_bw/" + imageName + ".png"; |
||||
curr->srcColor = imageName + "/src_color/" + imageName + ".png"; |
||||
|
||||
curr->humanSeg = imageName + "human_seg/"; |
||||
|
||||
train.push_back(curr); |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
||||
} |
@ -0,0 +1,100 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Itseez Inc or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/datasetstools/msm_epfl.hpp" |
||||
#include "precomp.hpp" |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace datasetstools |
||||
{ |
||||
|
||||
using namespace std; |
||||
|
||||
void MSM_epfl::readFileDouble(const string &fileName, vector<double> &out) |
||||
{ |
||||
ifstream infile(fileName.c_str()); |
||||
double val; |
||||
while (infile >> val) |
||||
{ |
||||
out.push_back(val); |
||||
} |
||||
} |
||||
|
||||
MSM_epfl::MSM_epfl(const string &path) |
||||
{ |
||||
loadDataset(path); |
||||
} |
||||
|
||||
void MSM_epfl::load(const string &path, int number) |
||||
{ |
||||
if (number!=0) |
||||
{ |
||||
return; |
||||
} |
||||
|
||||
loadDataset(path); |
||||
} |
||||
|
||||
void MSM_epfl::loadDataset(const string &path) |
||||
{ |
||||
string pathBounding(path + "bounding/"); |
||||
string pathCamera(path + "camera/"); |
||||
string pathP(path + "P/"); |
||||
string pathPng(path + "png/"); |
||||
|
||||
vector<string> fileNames; |
||||
getDirList(pathPng, fileNames); |
||||
for (vector<string>::iterator it=fileNames.begin(); it!=fileNames.end(); ++it) |
||||
{ |
||||
Ptr<MSM_epflObj> curr(new MSM_epflObj); |
||||
curr->imageName = *it; |
||||
|
||||
readFileDouble(string(pathBounding + curr->imageName + ".bounding"), curr->bounding); |
||||
readFileDouble(string(pathCamera + curr->imageName + ".camera"), curr->camera); |
||||
readFileDouble(string(pathP + curr->imageName + ".P"), curr->p); |
||||
|
||||
train.push_back(curr); |
||||
} |
||||
} |
||||
|
||||
} |
||||
} |
@ -0,0 +1,108 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Itseez Inc or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/datasetstools/msm_middlebury.hpp" |
||||
#include "precomp.hpp" |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace datasetstools |
||||
{ |
||||
|
||||
using namespace std; |
||||
|
||||
MSM_middlebury::MSM_middlebury(const string &path) |
||||
{ |
||||
loadDataset(path); |
||||
} |
||||
|
||||
void MSM_middlebury::load(const string &path, int number) |
||||
{ |
||||
if (number!=0) |
||||
{ |
||||
return; |
||||
} |
||||
|
||||
loadDataset(path); |
||||
} |
||||
|
||||
void MSM_middlebury::loadDataset(const string &path) |
||||
{ |
||||
string name(path.substr(0, path.length()-1)); |
||||
size_t start = name.rfind('/'); |
||||
name = name.substr(start+1, name.length()-start); |
||||
|
||||
string angName(path + name + "_ang.txt"); |
||||
string parName(path + name + "_par.txt"); |
||||
|
||||
ifstream infile(parName.c_str()); |
||||
string imageName; |
||||
infile >> imageName; // skip header
|
||||
while (infile >> imageName) |
||||
{ |
||||
Ptr<MSM_middleburyObj> curr(new MSM_middleburyObj); |
||||
curr->imageName = imageName; |
||||
|
||||
for (int i=0; i<3; ++i) |
||||
{ |
||||
for (int j=0; j<3; ++j) |
||||
{ |
||||
infile >> curr->k[i][j]; |
||||
} |
||||
} |
||||
for (int i=0; i<3; ++i) |
||||
{ |
||||
for (int j=0; j<3; ++j) |
||||
{ |
||||
infile >> curr->r[i][j]; |
||||
} |
||||
} |
||||
for (int i=0; i<3; ++i) |
||||
{ |
||||
infile >> curr->t[i]; |
||||
} |
||||
|
||||
train.push_back(curr); |
||||
} |
||||
} |
||||
|
||||
} |
||||
} |
@ -0,0 +1,93 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Itseez Inc or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/datasetstools/or_imagenet.hpp" |
||||
#include "precomp.hpp" |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace datasetstools |
||||
{ |
||||
|
||||
using namespace std; |
||||
|
||||
OR_imagenet::OR_imagenet(const string &path) |
||||
{ |
||||
loadDataset(path); |
||||
} |
||||
|
||||
void OR_imagenet::load(const string &path, int number) |
||||
{ |
||||
if (number!=0) |
||||
{ |
||||
return; |
||||
} |
||||
|
||||
loadDataset(path); |
||||
} |
||||
|
||||
void OR_imagenet::loadDataset(const string &path) |
||||
{ |
||||
ifstream infile((path + "fall11_urls.txt").c_str()); |
||||
string line; |
||||
while (getline(infile, line)) |
||||
{ |
||||
vector<string> elems; |
||||
split(line, elems, '\t'); |
||||
|
||||
Ptr<OR_imagenetObj> curr(new OR_imagenetObj); |
||||
curr->imageUrl = elems[1]; |
||||
|
||||
string id(elems[0]); |
||||
elems.clear(); |
||||
split(id, elems, '_'); |
||||
|
||||
curr->wnid = elems[0]; |
||||
curr->id2 = atoi(elems[1].c_str()); |
||||
|
||||
wnids.insert(curr->wnid); |
||||
|
||||
train.push_back(curr); |
||||
} |
||||
} |
||||
|
||||
} |
||||
} |
@ -0,0 +1,90 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Itseez Inc or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/datasetstools/or_sun.hpp" |
||||
#include "precomp.hpp" |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace datasetstools |
||||
{ |
||||
|
||||
using namespace std; |
||||
|
||||
OR_sun::OR_sun(const string &path) |
||||
{ |
||||
loadDataset(path); |
||||
} |
||||
|
||||
void OR_sun::load(const string &path, int number) |
||||
{ |
||||
if (number!=0) |
||||
{ |
||||
return; |
||||
} |
||||
|
||||
loadDataset(path); |
||||
} |
||||
|
||||
void OR_sun::loadDataset(const string &path) |
||||
{ |
||||
string classNameFile(path + "ClassName.txt"); |
||||
ifstream infile(classNameFile.c_str()); |
||||
string line; |
||||
while (getline(infile, line)) |
||||
{ |
||||
Ptr<OR_sunObj> curr(new OR_sunObj); |
||||
curr->name = line; |
||||
|
||||
string currPath(path + curr->name); |
||||
vector<string> fileNames; |
||||
getDirList(currPath, fileNames); |
||||
for (vector<string>::iterator it=fileNames.begin(); it!=fileNames.end(); ++it) |
||||
{ |
||||
curr->imageNames.push_back(*it); |
||||
} |
||||
|
||||
train.push_back(curr); |
||||
} |
||||
} |
||||
|
||||
} |
||||
} |
@ -0,0 +1,52 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Itseez Inc or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __OPENCV_PRECOMP_H__ |
||||
#define __OPENCV_PRECOMP_H__ |
||||
|
||||
#include <cstdio> |
||||
#include <cstdlib> // atoi, atof |
||||
|
||||
#include <fstream> |
||||
|
||||
#include "opencv2/datasetstools/util.hpp" |
||||
|
||||
#endif |
@ -0,0 +1,150 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Itseez Inc or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/datasetstools/slam_kitti.hpp" |
||||
#include "precomp.hpp" |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace datasetstools |
||||
{ |
||||
|
||||
using namespace std; |
||||
|
||||
SLAM_kitti::SLAM_kitti(const string &path) |
||||
{ |
||||
loadDataset(path); |
||||
} |
||||
|
||||
void SLAM_kitti::load(const string &path, int number) |
||||
{ |
||||
if (number!=0) |
||||
{ |
||||
return; |
||||
} |
||||
|
||||
loadDataset(path); |
||||
} |
||||
|
||||
void SLAM_kitti::loadDataset(const string &path) |
||||
{ |
||||
string pathSequence(path + "sequences/"); |
||||
vector<string> fileNames; |
||||
getDirList(pathSequence, fileNames); |
||||
for (vector<string>::iterator it=fileNames.begin(); it!=fileNames.end(); ++it) |
||||
{ |
||||
Ptr<SLAM_kittiObj> curr(new SLAM_kittiObj); |
||||
curr->name = *it; |
||||
|
||||
string currPath(pathSequence + curr->name); |
||||
|
||||
// loading velodyne
|
||||
string pathVelodyne(currPath + "/velodyne/"); |
||||
vector<string> velodyneNames; |
||||
getDirList(pathVelodyne, velodyneNames); |
||||
for (vector<string>::iterator itV=velodyneNames.begin(); itV!=velodyneNames.end(); ++itV) |
||||
{ |
||||
curr->velodyne.push_back(*itV); |
||||
} |
||||
|
||||
// loading gray & color images
|
||||
for (unsigned int i=0; i<=3; ++i) |
||||
{ |
||||
char tmp[2]; |
||||
sprintf(tmp, "%u", i); |
||||
string pathImage(currPath + "/image_" + tmp + "/"); |
||||
vector<string> imageNames; |
||||
getDirList(pathImage, imageNames); |
||||
for (vector<string>::iterator itImage=imageNames.begin(); itImage!=imageNames.end(); ++itImage) |
||||
{ |
||||
curr->images[i].push_back(*itImage); |
||||
} |
||||
} |
||||
|
||||
// loading times
|
||||
ifstream infile((currPath + "/times.txt").c_str()); |
||||
string line; |
||||
while (getline(infile, line)) |
||||
{ |
||||
curr->times.push_back(atof(line.c_str())); |
||||
} |
||||
|
||||
// loading calibration
|
||||
ifstream infile2((currPath + "/calib.txt").c_str()); |
||||
for (unsigned int i=0; i<4; ++i) |
||||
{ |
||||
getline(infile2, line); |
||||
vector<string> elems; |
||||
split(line, elems, ' '); |
||||
vector<string>::iterator itE=elems.begin(); |
||||
for (++itE; itE!=elems.end(); ++itE) |
||||
{ |
||||
curr->p[i].push_back(atof((*itE).c_str())); |
||||
} |
||||
} |
||||
|
||||
// loading poses
|
||||
ifstream infile3((path + "poses/" + curr->name + ".txt").c_str()); |
||||
while (getline(infile3, line)) |
||||
{ |
||||
pose p; |
||||
|
||||
unsigned int i=0; |
||||
vector<string> elems; |
||||
split(line, elems, ' '); |
||||
for (vector<string>::iterator itE=elems.begin(); itE!=elems.end(); ++itE, ++i) |
||||
{ |
||||
if (i>11) |
||||
{ |
||||
break; |
||||
} |
||||
p.elem[i] = atof((*itE).c_str()); |
||||
} |
||||
|
||||
curr->posesArray.push_back(p); |
||||
} |
||||
|
||||
train.push_back(curr); |
||||
} |
||||
} |
||||
|
||||
} |
||||
} |
@ -0,0 +1,107 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Itseez Inc or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/datasetstools/slam_tumindoor.hpp" |
||||
#include "precomp.hpp" |
||||
|
||||
#include <cstring> |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace datasetstools |
||||
{ |
||||
|
||||
using namespace std; |
||||
|
||||
SLAM_tumindoor::SLAM_tumindoor(const string &path) |
||||
{ |
||||
loadDataset(path); |
||||
} |
||||
|
||||
void SLAM_tumindoor::load(const string &path, int number) |
||||
{ |
||||
if (number!=0) |
||||
{ |
||||
return; |
||||
} |
||||
|
||||
loadDataset(path); |
||||
} |
||||
|
||||
void SLAM_tumindoor::loadDataset(const string &path) |
||||
{ |
||||
string infoPath(path + "info/2011-12-17_15.02.56-info.csv"); // TODO
|
||||
ifstream infile(infoPath.c_str()); |
||||
string line; |
||||
while (getline(infile, line)) |
||||
{ |
||||
vector<string> elems; |
||||
split(line, elems, ';'); |
||||
|
||||
Ptr<SLAM_tumindoorObj> curr(new SLAM_tumindoorObj); |
||||
|
||||
curr->name = elems[0]; |
||||
if (curr->name.substr(0, strlen("dslr_left")) == "dslr_left") |
||||
{ |
||||
curr->type = LEFT; |
||||
} else |
||||
if (curr->name.substr(0, strlen("dslr_right")) == "dslr_right") |
||||
{ |
||||
curr->type = RIGHT; |
||||
} else |
||||
{ |
||||
curr->type = LADYBUG; |
||||
} |
||||
|
||||
for (unsigned int i=0; i<4; ++i) |
||||
{ |
||||
for (unsigned int j=0; j<4; ++j) |
||||
{ |
||||
curr->transformMat[i][j] = atof(elems[1 + j + i*4].c_str()); |
||||
} |
||||
} |
||||
|
||||
train.push_back(curr); |
||||
} |
||||
} |
||||
|
||||
} |
||||
} |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,188 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Itseez Inc or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/datasetstools/tr_chars.hpp" |
||||
#include "precomp.hpp" |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace datasetstools |
||||
{ |
||||
|
||||
using namespace std; |
||||
|
||||
void TR_chars::parseLine(const string &line, vector<int> &currSet, int number) |
||||
{ |
||||
vector<string> elems; |
||||
split(line, elems, ' '); |
||||
if (number >= (int)elems.size()) |
||||
{ |
||||
return; |
||||
} |
||||
|
||||
unsigned int ind = atoi(elems[number].c_str()); |
||||
if (ind > 0) |
||||
{ |
||||
currSet.push_back(ind-1); |
||||
} |
||||
} |
||||
|
||||
TR_chars::TR_chars(const string &path, int number) |
||||
{ |
||||
loadDataset(path, number); |
||||
} |
||||
|
||||
void TR_chars::load(const string &path, int number) |
||||
{ |
||||
loadDataset(path, number); |
||||
} |
||||
|
||||
void TR_chars::loadDataset(const string &path, int number) |
||||
{ |
||||
vector<int> allLabels, trainSet, testSet; |
||||
vector<string> allNames; |
||||
|
||||
ifstream infile((path + "list_English_Img.m").c_str()); |
||||
string line; |
||||
bool labels = false, names = false, isTrain = false, isTest = false; |
||||
while (getline(infile, line)) |
||||
{ |
||||
size_t pos = line.find("];"); |
||||
if (string::npos!=pos) |
||||
{ |
||||
labels = false; |
||||
names = false; |
||||
isTrain = false; |
||||
isTest = false; |
||||
} |
||||
|
||||
string slabels("list.ALLlabels = ["); |
||||
pos = line.find(slabels); |
||||
if (string::npos != pos) |
||||
{ |
||||
labels = true; |
||||
string s(line.substr(pos+slabels.length())); |
||||
allLabels.push_back(atoi(s.c_str())); |
||||
} else |
||||
if (labels) |
||||
{ |
||||
allLabels.push_back(atoi(line.c_str())); |
||||
} |
||||
|
||||
string snames("list.ALLnames = ["); |
||||
pos = line.find(snames); |
||||
if (string::npos!=pos) |
||||
{ |
||||
names = true; |
||||
size_t start = pos+snames.length(); |
||||
string s(line.substr(start+1, line.length()-start-2)); |
||||
allNames.push_back(s); |
||||
} else |
||||
if (names) |
||||
{ |
||||
string s(line.substr(1, line.length()-2)); |
||||
allNames.push_back(s); |
||||
} |
||||
|
||||
string strain("list.TRNind = ["); |
||||
pos = line.find(strain); |
||||
if (string::npos!=pos) |
||||
{ |
||||
isTrain = true; |
||||
string s(line.substr(pos+strain.length())); |
||||
parseLine(s, trainSet, number); |
||||
} else |
||||
if (isTrain) |
||||
{ |
||||
parseLine(line, trainSet, number); |
||||
} |
||||
|
||||
string stest("list.TSTind = ["); |
||||
pos = line.find(stest); |
||||
if (string::npos!=pos) |
||||
{ |
||||
isTest = true; |
||||
string s(line.substr(pos+stest.length())); |
||||
parseLine(s, testSet, number); |
||||
} else |
||||
if (isTest) |
||||
{ |
||||
parseLine(line, testSet, number); |
||||
} |
||||
|
||||
/*"list.classlabels = ["
|
||||
"list.classnames = [" |
||||
"list.NUMclasses = 62;" |
||||
"list.VALind = [" // TODO: load validation
|
||||
"list.TXNind = ["*/ |
||||
} |
||||
|
||||
for (vector<int>::iterator it=trainSet.begin(); it!=trainSet.end(); ++it) |
||||
{ |
||||
if (*it>=(int)allNames.size() || *it>=(int)allLabels.size()) |
||||
{ |
||||
printf("incorrect train index: %u\n", *it); |
||||
continue; |
||||
} |
||||
|
||||
Ptr<TR_charsObj> curr(new TR_charsObj); |
||||
curr->imgName = allNames[*it]; |
||||
curr->label = allLabels[*it]; |
||||
train.push_back(curr); |
||||
} |
||||
|
||||
for (vector<int>::iterator it=testSet.begin(); it!=testSet.end(); ++it) |
||||
{ |
||||
if (*it>=(int)allNames.size() || *it>=(int)allLabels.size()) |
||||
{ |
||||
printf("incorrect test index: %u\n", *it); |
||||
continue; |
||||
} |
||||
|
||||
Ptr<TR_charsObj> curr(new TR_charsObj); |
||||
curr->imgName = allNames[*it]; |
||||
curr->label = allLabels[*it]; |
||||
test.push_back(curr); |
||||
} |
||||
} |
||||
|
||||
} |
||||
} |
@ -0,0 +1,128 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Itseez Inc or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/datasetstools/tr_svt.hpp" |
||||
#include "precomp.hpp" |
||||
|
||||
#include <opencv2/datasetstools/tinyxml2/tinyxml2.h> |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace datasetstools |
||||
{ |
||||
|
||||
using namespace std; |
||||
using namespace tinyxml2; |
||||
|
||||
void TR_svt::xmlParse(const string &set, vector< Ptr<Object> > &out) |
||||
{ |
||||
XMLDocument doc; |
||||
doc.LoadFile(set.c_str()); |
||||
XMLElement *root_ = doc.RootElement(); |
||||
string rootElem(root_->Name()); |
||||
if (rootElem == "tagset") |
||||
{ |
||||
string strImage("image"); |
||||
XMLElement *child = root_->FirstChildElement(strImage.c_str()); |
||||
while (child) |
||||
{ |
||||
string imageName = child->FirstChildElement("imageName")->GetText(); |
||||
string lex = child->FirstChildElement("lex")->GetText(); |
||||
|
||||
Ptr<TR_svtObj> curr(new TR_svtObj); |
||||
curr->fileName = imageName; |
||||
split(lex, curr->lex, ','); |
||||
|
||||
XMLElement *childTaggeds = child->FirstChildElement("taggedRectangles"); |
||||
if (childTaggeds) |
||||
{ |
||||
string strTagged("taggedRectangle"); |
||||
XMLElement *childTagged = childTaggeds->FirstChildElement(strTagged.c_str()); |
||||
while (childTagged) |
||||
{ |
||||
tag t; |
||||
t.value = childTagged->FirstChildElement("tag")->GetText(); |
||||
t.height = atoi(childTagged->Attribute("height")); |
||||
t.width = atoi(childTagged->Attribute("width")); |
||||
t.x = atoi(childTagged->Attribute("x")); |
||||
t.y = atoi(childTagged->Attribute("y")); |
||||
curr->tags.push_back(t); |
||||
|
||||
childTagged = childTagged->NextSiblingElement(strTagged.c_str()); |
||||
} |
||||
} |
||||
|
||||
out.push_back(curr); |
||||
|
||||
child = child->NextSiblingElement(strImage.c_str()); |
||||
} |
||||
} |
||||
} |
||||
|
||||
TR_svt::TR_svt(const string &path) |
||||
{ |
||||
loadDataset(path); |
||||
} |
||||
|
||||
void TR_svt::load(const string &path, int number) |
||||
{ |
||||
if (number!=0) |
||||
{ |
||||
return; |
||||
} |
||||
|
||||
loadDataset(path); |
||||
} |
||||
|
||||
void TR_svt::loadDataset(const string &path) |
||||
{ |
||||
string trainXml(path + "train.xml"); |
||||
string testXml(path + "test.xml"); |
||||
|
||||
// loading train images description
|
||||
xmlParse(trainXml, train); |
||||
|
||||
// loading test images description
|
||||
xmlParse(testXml, test); |
||||
} |
||||
|
||||
} |
||||
} |
@ -0,0 +1,110 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Itseez Inc or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/datasetstools/util.hpp" |
||||
|
||||
#include <cstdlib> |
||||
|
||||
#include <sstream> |
||||
|
||||
#ifdef __GNUC__ |
||||
#include <unistd.h> |
||||
#include <dirent.h> |
||||
#else |
||||
#include <io.h> |
||||
#include <direct.h> |
||||
#endif |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace datasetstools |
||||
{ |
||||
|
||||
using namespace std; |
||||
|
||||
void split(const string &s, vector<string> &elems, char delim) |
||||
{ |
||||
stringstream ss(s); |
||||
string item; |
||||
while (getline(ss, item, delim)) |
||||
{ |
||||
elems.push_back(item); |
||||
} |
||||
} |
||||
|
||||
void getDirList(const string &dirName, vector<string> &fileNames) |
||||
{ |
||||
#ifdef __GNUC__ |
||||
struct dirent **namelist; |
||||
int n = scandir(dirName.c_str(), &namelist, NULL, alphasort); |
||||
for (int i=0; i<n; ++i) |
||||
{ |
||||
string fileName(namelist[i]->d_name); |
||||
if ('.' != fileName[0]) |
||||
{ |
||||
fileNames.push_back(fileName); |
||||
} |
||||
free(namelist[i]); |
||||
} |
||||
free(namelist); |
||||
#else // for WIN32
|
||||
struct _finddata_t file; |
||||
string filter(dirName); |
||||
filter += "\\*.*"; |
||||
intptr_t hFile = _findfirst(filter.c_str(), &file); |
||||
if (hFile==-1) |
||||
{ |
||||
return; |
||||
} |
||||
do |
||||
{ |
||||
string fileName(file.name); |
||||
if ('.' != fileName[0]) |
||||
{ |
||||
fileNames.push_back(fileName); |
||||
} |
||||
} while (_findnext(hFile, &file)==0); |
||||
_findclose(hFile); |
||||
#endif |
||||
} |
||||
|
||||
} |
||||
} |
@ -0,0 +1,4 @@ |
||||
set(the_description "Line descriptor") |
||||
ocv_define_module(line_descriptor opencv_features2d opencv_imgproc opencv_highgui) |
||||
|
||||
|
@ -0,0 +1,52 @@ |
||||
.. _LSDDetector: |
||||
|
||||
Line Segments Detector |
||||
====================== |
||||
|
||||
|
||||
Lines extraction methodology |
||||
---------------------------- |
||||
|
||||
The lines extraction methodology described in the following is mainly based on [EDLN]_. |
||||
The extraction starts with a Gaussian pyramid generated from an original image, downsampled N-1 times, blurred N times, to obtain N layers (one for each octave), with layer 0 corresponding to input image. Then, from each layer (octave) in the pyramid, lines are extracted using LSD algorithm. |
||||
|
||||
Differently from EDLine lines extractor used in original article, LSD furnishes information only about lines extremes; thus, additional information regarding slope and equation of line are computed via analytic methods. The number of pixels is obtained using *LineIterator*. Extracted lines are returned in the form of KeyLine objects, but since extraction is based on a method different from the one used in *BinaryDescriptor* class, data associated to a line's extremes in original image and in octave it was extracted from, coincide. KeyLine's field *class_id* is used as an index to indicate the order of extraction of a line inside a single octave. |
||||
|
||||
|
||||
LSDDetector::createLSDDetector |
||||
------------------------------ |
||||
|
||||
Creates ad LSDDetector object, using smart pointers. |
||||
|
||||
.. ocv:function:: Ptr<LSDDetector> LSDDetector::createLSDDetector() |
||||
|
||||
|
||||
LSDDetector::detect |
||||
------------------- |
||||
|
||||
Detect lines inside an image. |
||||
|
||||
.. ocv:function:: void LSDDetector::detect( const Mat& image, std::vector<KeyLine>& keylines, int scale, int numOctaves, const Mat& mask=Mat()) |
||||
|
||||
.. ocv:function:: void LSDDetector::detect( const std::vector<Mat>& images, std::vector<std::vector<KeyLine> >& keylines, int scale, int numOctaves, const std::vector<Mat>& masks=std::vector<Mat>() ) const |
||||
|
||||
:param image: input image |
||||
|
||||
:param images: input images |
||||
|
||||
:param keylines: vector or set of vectors that will store extracted lines for one or more images |
||||
|
||||
:param mask: mask matrix to detect only KeyLines of interest |
||||
|
||||
:param masks: vector of mask matrices to detect only KeyLines of interest from each input image |
||||
|
||||
:param scale: scale factor used in pyramids generation |
||||
|
||||
:param numOctaves: number of octaves inside pyramid |
||||
|
||||
|
||||
References |
||||
---------- |
||||
|
||||
.. [EDLN] Von Gioi, R. Grompone, et al. *LSD: A fast line segment detector with a false detection control*, IEEE Transactions on Pattern Analysis and Machine Intelligence 32.4 (2010): 722-732. |
||||
|
@ -0,0 +1,223 @@ |
||||
.. _binary_descriptor: |
||||
|
||||
BinaryDescriptor Class |
||||
====================== |
||||
|
||||
.. highlight:: cpp |
||||
|
||||
BinaryDescriptor Class implements both functionalities for detection of lines and computation of their binary descriptor. Class' interface is mainly based on the ones of classical detectors and extractors, such as Feature2d's `FeatureDetector <http://docs.opencv.org/modules/features2d/doc/common_interfaces_of_feature_detectors.html?highlight=featuredetector#featuredetector>`_ and `DescriptorExtractor <http://docs.opencv.org/modules/features2d/doc/common_interfaces_of_descriptor_extractors.html?highlight=extractor#DescriptorExtractor : public Algorithm>`_. |
||||
Retrieved information about lines is stored in *KeyLine* objects. |
||||
|
||||
|
||||
BinaryDescriptor::Params |
||||
----------------------------------------------------------------------- |
||||
|
||||
.. ocv:struct:: BinaryDescriptor::Params |
||||
|
||||
List of BinaryDescriptor parameters:: |
||||
|
||||
struct CV_EXPORTS_W_SIMPLE Params{ |
||||
CV_WRAP Params(); |
||||
|
||||
/* the number of image octaves (default = 1) */ |
||||
CV_PROP_RW int numOfOctave_; |
||||
|
||||
/* the width of band; (default = 7) */ |
||||
CV_PROP_RW int widthOfBand_; |
||||
|
||||
/* image's reduction ratio in construction of Gaussian pyramids (default = 2) */ |
||||
CV_PROP_RW int reductionRatio; |
||||
|
||||
/* read parameters from a FileNode object and store them (struct function) */ |
||||
void read( const FileNode& fn ); |
||||
|
||||
/* store parameters to a FileStorage object (struct function) */ |
||||
void write( FileStorage& fs ) const; |
||||
|
||||
}; |
||||
|
||||
|
||||
BinaryDescriptor::BinaryDescriptor |
||||
---------------------------------- |
||||
|
||||
Constructor |
||||
|
||||
.. ocv:function:: bool BinaryDescriptor::BinaryDescriptor( const BinaryDescriptor::Params ¶meters = BinaryDescriptor::Params() ) |
||||
|
||||
:param parameters: configuration parameters :ocv:struct:`BinaryDescriptor::Params` |
||||
|
||||
If no argument is provided, constructor sets default values (see comments in the code snippet in previous section). Default values are strongly reccomended. |
||||
|
||||
|
||||
BinaryDescriptor::getNumOfOctaves |
||||
--------------------------------- |
||||
|
||||
Get current number of octaves |
||||
|
||||
.. ocv:function:: int BinaryDescriptor::getNumOfOctaves() |
||||
|
||||
|
||||
BinaryDescriptor::setNumOfOctaves |
||||
--------------------------------- |
||||
|
||||
Set number of octaves |
||||
|
||||
.. ocv:function:: void BinaryDescriptor::setNumOfOctaves( int octaves ) |
||||
|
||||
:param octaves: number of octaves |
||||
|
||||
|
||||
BinaryDescriptor::getWidthOfBand |
||||
-------------------------------- |
||||
|
||||
Get current width of bands |
||||
|
||||
.. ocv:function:: int BinaryDescriptor::getWidthOfBand() |
||||
|
||||
|
||||
BinaryDescriptor::setWidthOfBand |
||||
-------------------------------- |
||||
|
||||
Set width of bands |
||||
|
||||
.. ocv:function:: void BinaryDescriptor::setWidthOfBand( int width ) |
||||
|
||||
:param width: width of bands |
||||
|
||||
BinaryDescriptor::getReductionRatio |
||||
----------------------------------- |
||||
|
||||
Get current reduction ratio (used in Gaussian pyramids) |
||||
|
||||
.. ocv:function:: int BinaryDescriptor::getReductionRatio() |
||||
|
||||
|
||||
BinaryDescriptor::setReductionRatio |
||||
----------------------------------- |
||||
|
||||
Set reduction ratio (used in Gaussian pyramids) |
||||
|
||||
.. ocv:function:: void BinaryDescriptor::setReductionRatio( int rRatio ) |
||||
|
||||
:param rRatio: reduction ratio |
||||
|
||||
|
||||
BinaryDescriptor::createBinaryDescriptor |
||||
---------------------------------------- |
||||
|
||||
Create a BinaryDescriptor object with default parameters (or with the ones provided) and return a smart pointer to it |
||||
|
||||
.. ocv:function:: Ptr<BinaryDescriptor> BinaryDescriptor::createBinaryDescriptor() |
||||
.. ocv:function:: Ptr<BinaryDescriptor> BinaryDescriptor::createBinaryDescriptor( Params parameters ) |
||||
|
||||
|
||||
BinaryDescriptor::operator() |
||||
---------------------------- |
||||
|
||||
Define operator '()' to perform detection of KeyLines and computation of descriptors in a row. |
||||
|
||||
.. ocv:function:: void BinaryDescriptor::operator()( InputArray image, InputArray mask, vector<KeyLine>& keylines, OutputArray descriptors, bool useProvidedKeyLines=false, bool returnFloatDescr ) const |
||||
|
||||
:param image: input image |
||||
|
||||
:param mask: mask matrix to select which lines in KeyLines must be accepted among the ones extracted (used when *keylines* is not empty) |
||||
|
||||
:param keylines: vector that contains input lines (when filled, the detection part will be skipped and input lines will be passed as input to the algorithm computing descriptors) |
||||
|
||||
:param descriptors: matrix that will store final descriptors |
||||
|
||||
:param useProvidedKeyLines: flag (when set to true, detection phase will be skipped and only computation of descriptors will be executed, using lines provided in *keylines*) |
||||
|
||||
:param returnFloatDescr: flag (when set to true, original non-binary descriptors are returned) |
||||
|
||||
|
||||
BinaryDescriptor::read |
||||
---------------------- |
||||
|
||||
Read parameters from a FileNode object and store them |
||||
|
||||
.. ocv:function:: void BinaryDescriptor::read( const FileNode& fn ) |
||||
|
||||
:param fn: source FileNode file |
||||
|
||||
|
||||
BinaryDescriptor::write |
||||
----------------------- |
||||
|
||||
Store parameters to a FileStorage object |
||||
|
||||
.. ocv:function:: void BinaryDescriptor::write( FileStorage& fs ) const |
||||
|
||||
:param fs: output FileStorage file |
||||
|
||||
|
||||
BinaryDescriptor::defaultNorm |
||||
----------------------------- |
||||
|
||||
Return norm mode |
||||
|
||||
.. ocv:function:: int BinaryDescriptor::defaultNorm() const |
||||
|
||||
|
||||
BinaryDescriptor::descriptorType |
||||
-------------------------------- |
||||
|
||||
Return data type |
||||
|
||||
.. ocv:function:: int BinaryDescriptor::descriptorType() const |
||||
|
||||
|
||||
BinaryDescriptor::descriptorSize |
||||
-------------------------------- |
||||
|
||||
Return descriptor size |
||||
|
||||
.. ocv:function:: int BinaryDescriptor::descriptorSize() const |
||||
|
||||
|
||||
BinaryDescriptor::detect |
||||
------------------------ |
||||
|
||||
Requires line detection (for one or more images) |
||||
|
||||
.. ocv:function:: void detect( const Mat& image, vector<KeyLine>& keylines, Mat& mask=Mat() ) |
||||
.. ocv:function:: void detect( const vector<Mat>& images, vector<vector<KeyLine> >& keylines, vector<Mat>& masks=vector<Mat>() ) const |
||||
|
||||
:param image: input image |
||||
|
||||
:param images: input images |
||||
|
||||
:param keylines: vector or set of vectors that will store extracted lines for one or more images |
||||
|
||||
:param mask: mask matrix to detect only KeyLines of interest |
||||
|
||||
:param masks: vector of mask matrices to detect only KeyLines of interest from each input image |
||||
|
||||
|
||||
BinaryDescriptor::compute |
||||
------------------------- |
||||
|
||||
Requires descriptors computation (for one or more images) |
||||
|
||||
.. ocv:function:: void compute( const Mat& image, vector<KeyLine>& keylines, Mat& descriptors, bool returnFloatDescr ) const |
||||
.. ocv:function:: void compute( const vector<Mat>& images, vector<vector<KeyLine> >& keylines, vector<Mat>& descriptors, bool returnFloatDescr ) const |
||||
|
||||
:param image: input image |
||||
|
||||
:param images: input images |
||||
|
||||
:param keylines: vector or set of vectors containing lines for which descriptors must be computed |
||||
|
||||
:param mask: mask to select for which lines, among the ones provided in input, descriptors must be computed |
||||
|
||||
:param masks: set of masks to select for which lines, among the ones provided in input, descriptors must be computed |
||||
|
||||
:param returnFloatDescr: flag (when set to true, original non-binary descriptors are returned) |
||||
|
||||
|
||||
Related pages |
||||
------------- |
||||
|
||||
* :ref:`line_descriptor` |
||||
* :ref:`matching` |
||||
* :ref:`drawing` |
@ -0,0 +1,70 @@ |
||||
.. _drawing: |
||||
|
||||
Drawing Functions for Keylines and Matches |
||||
========================================== |
||||
|
||||
.. highlight:: cpp |
||||
|
||||
drawLineMatches |
||||
--------------- |
||||
|
||||
Draws the found matches of keylines from two images. |
||||
|
||||
.. ocv:function:: void drawLineMatches( const Mat& img1, const std::vector<KeyLine>& keylines1, const Mat& img2, const std::vector<KeyLine>& keylines2, const std::vector<DMatch>& matches1to2, Mat& outImg, const Scalar& matchColor=Scalar::all(-1), const Scalar& singleLineColor=Scalar::all(-1), const std::vector<char>& matchesMask=std::vector<char>(), int flags=DrawLinesMatchesFlags::DEFAULT ) |
||||
|
||||
:param img1: first image |
||||
:param keylines1: keylines extracted from first image |
||||
:param img2: second image |
||||
:param keylines2: keylines extracted from second image |
||||
:param matches1to2: vector of matches |
||||
:param outImg: output matrix to draw on |
||||
:param matchColor: drawing color for matches (chosen randomly in case of default value) |
||||
:param singleLineColor: drawing color for keylines (chosen randomly in case of default value) |
||||
:param matchesMask: mask to indicate which matches must be drawn |
||||
:param flags: drawing flags |
||||
|
||||
.. note:: If both *matchColor* and *singleLineColor* are set to their default values, function draws matched lines and line connecting them with same color |
||||
|
||||
The structure of drawing flags is shown in the following: |
||||
|
||||
.. code-block:: cpp |
||||
|
||||
/* struct for drawing options */ |
||||
struct CV_EXPORTS DrawLinesMatchesFlags |
||||
{ |
||||
enum |
||||
{ |
||||
DEFAULT = 0, // Output image matrix will be created (Mat::create), |
||||
// i.e. existing memory of output image may be reused. |
||||
// Two source images, matches, and single keylines |
||||
// will be drawn. |
||||
DRAW_OVER_OUTIMG = 1, // Output image matrix will not be |
||||
// created (using Mat::create). Matches will be drawn |
||||
// on existing content of output image. |
||||
NOT_DRAW_SINGLE_LINES = 2 // Single keylines will not be drawn. |
||||
}; |
||||
}; |
||||
|
||||
.. |
||||
|
||||
|
||||
drawKeylines |
||||
------------ |
||||
|
||||
Draws keylines. |
||||
|
||||
.. ocv:function:: void drawKeylines( const Mat& image, const std::vector<KeyLine>& keylines, Mat& outImage, const Scalar& color=Scalar::all(-1), int flags=DrawLinesMatchesFlags::DEFAULT ) |
||||
|
||||
:param image: input image |
||||
:param keylines: keylines to be drawn |
||||
:param outImage: output image to draw on |
||||
:param color: color of lines to be drawn (if set to defaul value, color is chosen randomly) |
||||
:param flags: drawing flags |
||||
|
||||
|
||||
Related pages |
||||
------------- |
||||
|
||||
* :ref:`line_descriptor` |
||||
* :ref:`binary_descriptor` |
||||
* :ref:`matching` |
@ -0,0 +1,142 @@ |
||||
.. _line_descriptor: |
||||
|
||||
Binary descriptors for lines extracted from an image |
||||
==================================================== |
||||
|
||||
.. highlight:: cpp |
||||
|
||||
|
||||
Introduction |
||||
------------ |
||||
|
||||
|
||||
One of the most challenging activities in computer vision is the extraction of useful information from a given image. Such information, usually comes in the form of points that preserve some kind of property (for instance, they are scale-invariant) and are actually representative of input image. |
||||
|
||||
The goal of this module is seeking a new kind of representative information inside an image and providing the functionalities for its extraction and representation. In particular, differently from previous methods for detection of relevant elements inside an image, lines are extracted in place of points; a new class is defined ad hoc to summarize a line's properties, for reuse and plotting purposes. |
||||
|
||||
|
||||
A class to represent a line: KeyLine |
||||
------------------------------------ |
||||
|
||||
As aformentioned, it is been necessary to design a class that fully stores the information needed to characterize completely a line and plot it on image it was extracted from, when required. |
||||
|
||||
*KeyLine* class has been created for such goal; it is mainly inspired to Feature2d's KeyPoint class, since KeyLine shares some of *KeyPoint*'s fields, even if a part of them assumes a different meaning, when speaking about lines. |
||||
In particular: |
||||
|
||||
* the *class_id* field is used to gather lines extracted from different octaves which refer to same line inside original image (such lines and the one they represent in original image share the same *class_id* value) |
||||
* the *angle* field represents line's slope with respect to (positive) X axis |
||||
* the *pt* field represents line's midpoint |
||||
* the *response* field is computed as the ratio between the line's length and maximum between image's width and height |
||||
* the *size* field is the area of the smallest rectangle containing line |
||||
|
||||
Apart from fields inspired to KeyPoint class, KeyLines stores information about extremes of line in original image and in octave it was extracted from, about line's length and number of pixels it covers. Code relative to KeyLine class is reported in the following snippet: |
||||
|
||||
.. ocv:class:: KeyLine |
||||
|
||||
:: |
||||
|
||||
class CV_EXPORTS_W KeyLine |
||||
{ |
||||
public: |
||||
/* orientation of the line */ |
||||
float angle; |
||||
|
||||
/* object ID, that can be used to cluster keylines by the line they represent */ |
||||
int class_id; |
||||
|
||||
/* octave (pyramid layer), from which the keyline has been extracted */ |
||||
int octave; |
||||
|
||||
/* coordinates of the middlepoint */ |
||||
Point pt; |
||||
|
||||
/* the response, by which the strongest keylines have been selected. |
||||
It's represented by the ratio between line's length and maximum between |
||||
image's width and height */ |
||||
float response; |
||||
|
||||
/* minimum area containing line */ |
||||
float size; |
||||
|
||||
/* lines's extremes in original image */ |
||||
float startPointX; |
||||
float startPointY; |
||||
float endPointX; |
||||
float endPointY; |
||||
|
||||
/* line's extremes in image it was extracted from */ |
||||
float sPointInOctaveX; |
||||
float sPointInOctaveY; |
||||
float ePointInOctaveX; |
||||
float ePointInOctaveY; |
||||
|
||||
/* the length of line */ |
||||
float lineLength; |
||||
|
||||
/* number of pixels covered by the line */ |
||||
unsigned int numOfPixels; |
||||
|
||||
/* constructor */ |
||||
KeyLine(){} |
||||
}; |
||||
|
||||
|
||||
Computation of binary descriptors |
||||
--------------------------------- |
||||
|
||||
To obtatin a binary descriptor representing a certain line detected from a certain octave of an image, we first compute a non-binary descriptor as described in [LBD]_. Such algorithm works on lines extracted using EDLine detector, as explained in [EDL]_. Given a line, we consider a rectangular region centered at it and called *line support region (LSR)*. Such region is divided into a set of bands :math:`\{B_1, B_2, ..., B_m\}`, whose length equals the one of line. |
||||
|
||||
If we indicate with :math:`\bf{d}_L` the direction of line, the orthogonal and clockwise direction to line :math:`\bf{d}_{\perp}` can be determined; these two directions, are used to construct a reference frame centered in the middle point of line. The gradients of pixels :math:`\bf{g'}` inside LSR can be projected to the newly determined frame, obtaining their local equivalent :math:`\bf{g'} = (\bf{g}^T \cdot \bf{d}_{\perp}, \bf{g}^T \cdot \bf{d}_L)^T \triangleq (\bf{g'}_{d_{\perp}}, \bf{g'}_{d_L})^T`. |
||||
|
||||
Later on, a Gaussian function is applied to all LSR's pixels along :math:`\bf{d}_\perp` direction; first, we assign a global weighting coefficient :math:`f_g(i) = (1/\sqrt{2\pi}\sigma_g)e^{-d^2_i/2\sigma^2_g}` to *i*-th row in LSR, where :math:`d_i` is the distance of *i*-th row from the center row in LSR, :math:`\sigma_g = 0.5(m \cdot w - 1)` and :math:`w` is the width of bands (the same for every band). Secondly, considering a band :math:`B_j` and its neighbor bands :math:`B_{j-1}, B_{j+1}`, we assign a local weighting :math:`F_l(k) = (1/\sqrt{2\pi}\sigma_l)e^{-d'^2_k/2\sigma_l^2}`, where :math:`d'_k` is the distance of *k*-th row from the center row in :math:`B_j` and :math:`\sigma_l = w`. Using the global and local weights, we obtain, at the same time, the reduction of role played by gradients far from line and of boundary effect, respectively. |
||||
|
||||
Each band :math:`B_j` in LSR has an associated *band descriptor(BD)* which is computed considering previous and next band (top and bottom bands are ignored when computing descriptor for first and last band). Once each band has been assignen its BD, the LBD descriptor of line is simply given by |
||||
|
||||
.. math:: |
||||
LBD = (BD_1^T, BD_2^T, ... , BD^T_m)^T. |
||||
|
||||
To compute a band descriptor :math:`B_j`, each *k*-th row in it is considered and the gradients in such row are accumulated: |
||||
|
||||
.. math:: |
||||
\begin{matrix} \bf{V1}^k_j = \lambda \sum\limits_{\bf{g}'_{d_\perp}>0}\bf{g}'_{d_\perp}, & \bf{V2}^k_j = \lambda \sum\limits_{\bf{g}'_{d_\perp}<0} -\bf{g}'_{d_\perp}, \\ \bf{V3}^k_j = \lambda \sum\limits_{\bf{g}'_{d_L}>0}\bf{g}'_{d_L}, & \bf{V4}^k_j = \lambda \sum\limits_{\bf{g}'_{d_L}<0} -\bf{g}'_{d_L}\end{matrix}. |
||||
|
||||
with :math:`\lambda = f_g(k)f_l(k)`. |
||||
|
||||
By stacking previous results, we obtain the *band description matrix (BDM)* |
||||
|
||||
.. math:: |
||||
BDM_j = \left(\begin{matrix} \bf{V1}_j^1 & \bf{V1}_j^2 & \ldots & \bf{V1}_j^n \\ \bf{V2}_j^1 & \bf{V2}_j^2 & \ldots & \bf{V2}_j^n \\ \bf{V3}_j^1 & \bf{V3}_j^2 & \ldots & \bf{V3}_j^n \\ \bf{V4}_j^1 & \bf{V4}_j^2 & \ldots & \bf{V4}_j^n \end{matrix} \right) \in \mathbb{R}^{4\times n}, |
||||
|
||||
with :math:`n` the number of rows in band :math:`B_j`: |
||||
|
||||
.. math:: |
||||
n = \begin{cases} 2w, & j = 1||m; \\ 3w, & \mbox{else}. \end{cases} |
||||
|
||||
Each :math:`BD_j` can be obtained using the standard deviation vector :math:`S_j` and mean vector :math:`M_j` of :math:`BDM_J`. Thus, finally: |
||||
|
||||
.. math:: |
||||
LBD = (M_1^T, S_1^T, M_2^T, S_2^T, \ldots, M_m^T, S_m^T)^T \in \mathbb{R}^{8m} |
||||
|
||||
|
||||
Once the LBD has been obtained, it must be converted into a binary form. For such purpose, we consider 32 possible pairs of BD inside it; each couple of BD is compared bit by bit and comparison generates an 8 bit string. Concatenating 32 comparison strings, we get the 256-bit final binary representation of a single LBD. |
||||
|
||||
References |
||||
---------- |
||||
|
||||
.. [LBD] Zhang, Lilian, and Reinhard Koch. *An efficient and robust line segment matching approach based on LBD descriptor and pairwise geometric consistency*, Journal of Visual Communication and Image Representation 24.7 (2013): 794-805. |
||||
|
||||
.. [EDL] Von Gioi, R. Grompone, et al. *LSD: A fast line segment detector with a false detection control*, IEEE Transactions on Pattern Analysis and Machine Intelligence 32.4 (2010): 722-732. |
||||
|
||||
|
||||
Summary |
||||
------- |
||||
|
||||
.. toctree:: |
||||
:maxdepth: 2 |
||||
|
||||
binary_descriptor |
||||
LSDDetector |
||||
matching |
||||
drawing_functions |
||||
tutorial |
||||
|
@ -0,0 +1,143 @@ |
||||
.. _matching: |
||||
|
||||
Matching with binary descriptors |
||||
================================ |
||||
|
||||
.. highlight:: cpp |
||||
|
||||
Once descriptors have been extracted from an image (both they represent lines and points), it becomes interesting to be able to match a descriptor with another one extracted from a different image and representing the same line or point, seen from a differente perspective or on a different scale. |
||||
In reaching such goal, the main headache is designing an efficient search algorithm to associate a query descriptor to one extracted from a dataset. |
||||
In the following, a matching modality based on *Multi-Index Hashing (MiHashing)* will be described. |
||||
|
||||
|
||||
Multi-Index Hashing |
||||
------------------- |
||||
|
||||
The theory described in this section is based on [MIH]_. |
||||
Given a dataset populated with binary codes, each code is indexed *m* times into *m* different hash tables, according to *m* substrings it has been divided into. Thus, given a query code, all the entries close to it at least in one substring are returned by search as *neighbor candidates*. Returned entries are then checked for validity by verifying that their full codes are not distant (in Hamming space) more than *r* bits from query code. |
||||
In details, each binary code **h** composed of *b* bits is divided into *m* disjoint substrings :math:`\mathbf{h}^{(1)}, ..., \mathbf{h}^{(m)}`, each with length :math:`\lfloor b/m \rfloor` or :math:`\lceil b/m \rceil` bits. Formally, when two codes **h** and **g** differ by at the most *r* bits, in at the least one of their *m* substrings they differ by at the most :math:`\lfloor r/m \rfloor` bits. In particular, when :math:`||\mathbf{h}-\mathbf{g}||_H \le r` (where :math:`||.||_H` is the Hamming norm), there must exist a substring *k* (with :math:`1 \le k \le m`) such that |
||||
|
||||
.. math:: |
||||
||\mathbf{h}^{(k)} - \mathbf{g}^{(k)}||_H \le \left\lfloor \frac{r}{m} \right\rfloor . |
||||
|
||||
That means that if Hamming distance between each of the *m* substring is strictly greater than :math:`\lfloor r/m \rfloor`, then :math:`||\mathbf{h}-\mathbf{g}||_H` must be larger that *r* and that is a contradiction. |
||||
If the codes in dataset are divided into *m* substrings, then *m* tables will be built. Given a query **q** with substrings :math:`\{\mathbf{q}^{(i)}\}^m_{i=1}`, *i*-th hash table is searched for entries distant at the most :math:`\lfloor r/m \rfloor` from :math:`\mathbf{q}^{(i)}` and a set of candidates :math:`\mathcal{N}_i(\mathbf{q})` is obtained. |
||||
The union of sets :math:`\mathcal{N}(\mathbf{q}) = \bigcup_i \mathcal{N}_i(\mathbf{q})` is a superset of the *r*-neighbors of **q**. Then, last step of algorithm is computing the Hamming distance between **q** and each element in :math:`\mathcal{N}(\mathbf{q})`, deleting the codes that are distant more that *r* from **q**. |
||||
|
||||
|
||||
BinaryDescriptorMatcher Class |
||||
============================= |
||||
|
||||
BinaryDescriptorMatcher Class furnishes all functionalities for querying a dataset provided by user or internal to class (that user must, anyway, populate) on the model of Feature2d's `DescriptorMatcher <http://docs.opencv.org/modules/features2d/doc/common_interfaces_of_descriptor_matchers.html?highlight=bfmatcher#descriptormatcher>`_. |
||||
|
||||
|
||||
BinaryDescriptorMatcher::BinaryDescriptorMatcher |
||||
-------------------------------------------------- |
||||
|
||||
Constructor. |
||||
|
||||
.. ocv:function:: BinaryDescriptorMatcher::BinaryDescriptorMatcher() |
||||
|
||||
The BinaryDescriptorMatcher constructed is able to store and manage 256-bits long entries. |
||||
|
||||
|
||||
BinaryDescriptorMatcher::createBinaryDescriptorMatcher |
||||
------------------------------------------------------ |
||||
|
||||
Create a BinaryDescriptorMatcher object and return a smart pointer to it. |
||||
|
||||
.. ocv:function:: Ptr<BinaryDescriptorMatcher> BinaryDescriptorMatcher::createBinaryDescriptorMatcher() |
||||
|
||||
|
||||
BinaryDescriptorMatcher::add |
||||
---------------------------- |
||||
|
||||
Store locally new descriptors to be inserted in dataset, without updating dataset. |
||||
|
||||
.. ocv:function:: void BinaryDescriptorMatcher::add( const std::vector<Mat>& descriptors ) |
||||
|
||||
:param descriptors: matrices containing descriptors to be inserted into dataset |
||||
|
||||
.. note:: Each matrix *i* in **descriptors** should contain descriptors relative to lines extracted from *i*-th image. |
||||
|
||||
|
||||
BinaryDescriptorMatcher::train |
||||
------------------------------ |
||||
|
||||
Update dataset by inserting into it all descriptors that were stored locally by *add* function. |
||||
|
||||
.. ocv:function:: void BinaryDescriptorMatcher::train() |
||||
|
||||
.. note:: Every time this function is invoked, current dataset is deleted and locally stored descriptors are inserted into dataset. The locally stored copy of just inserted descriptors is then removed. |
||||
|
||||
|
||||
BinaryDescriptorMatcher::clear |
||||
------------------------------ |
||||
|
||||
Clear dataset and internal data |
||||
|
||||
.. ocv:function:: void BinaryDescriptorMatcher::clear() |
||||
|
||||
|
||||
BinaryDescriptorMatcher::match |
||||
------------------------------ |
||||
|
||||
For every input query descriptor, retrieve the best matching one from a dataset provided from user or from the one internal to class |
||||
|
||||
.. ocv:function:: void BinaryDescriptorMatcher::match( const Mat& queryDescriptors, const Mat& trainDescriptors, std::vector<DMatch>& matches, const Mat& mask=Mat() ) const |
||||
.. ocv:function:: void BinaryDescriptorMatcher::match( const Mat& queryDescriptors, std::vector<DMatch>& matches, const std::vector<Mat>& masks=std::vector<Mat>() ) |
||||
|
||||
:param queryDescriptors: query descriptors |
||||
:param trainDescriptors: dataset of descriptors furnished by user |
||||
:param matches: vector to host retrieved matches |
||||
:param mask: mask to select which input descriptors must be matched to one in dataset |
||||
:param masks: vector of masks to select which input descriptors must be matched to one in dataset (the *i*-th mask in vector indicates whether each input query can be matched with descriptors in dataset relative to *i*-th image) |
||||
|
||||
|
||||
BinaryDescriptorMatcher::knnMatch |
||||
--------------------------------- |
||||
|
||||
For every input query descriptor, retrieve the best *k* matching ones from a dataset provided from user or from the one internal to class |
||||
|
||||
.. ocv:function:: void BinaryDescriptorMatcher::knnMatch( const Mat& queryDescriptors, const Mat& trainDescriptors, std::vector<std::vector<DMatch> >& matches, int k, const Mat& mask=Mat(), bool compactResult=false ) const |
||||
.. ocv:function:: void BinaryDescriptorMatcher::knnMatch( const Mat& queryDescriptors, std::vector<std::vector<DMatch> >& matches, int k, const std::vector<Mat>& masks=std::vector<Mat>(), bool compactResult=false ) |
||||
|
||||
:param queryDescriptors: query descriptors |
||||
:param trainDescriptors: dataset of descriptors furnished by user |
||||
:param matches: vector to host retrieved matches |
||||
:param k: number of the closest descriptors to be returned for every input query |
||||
:param mask: mask to select which input descriptors must be matched to ones in dataset |
||||
:param masks: vector of masks to select which input descriptors must be matched to ones in dataset (the *i*-th mask in vector indicates whether each input query can be matched with descriptors in dataset relative to *i*-th image) |
||||
:param compactResult: flag to obtain a compact result (if true, a vector that doesn't contain any matches for a given query is not inserted in final result) |
||||
|
||||
|
||||
BinaryDescriptorMatcher::radiusMatch |
||||
------------------------------------ |
||||
|
||||
For every input query descriptor, retrieve, from a dataset provided from user or from the one internal to class, all the descriptors that are not further than *maxDist* from input query |
||||
|
||||
.. ocv:function:: void BinaryDescriptorMatcher::radiusMatch( const Mat& queryDescriptors, const Mat& trainDescriptors, std::vector<std::vector<DMatch> >& matches, float maxDistance, const Mat& mask=Mat(), bool compactResult=false ) const |
||||
.. ocv:function:: void BinaryDescriptorMatcher::radiusMatch( const Mat& queryDescriptors, std::vector<std::vector<DMatch> >& matches, float maxDistance, const std::vector<Mat>& masks=std::vector<Mat>(), bool compactResult=false ) |
||||
|
||||
:param queryDescriptors: query descriptors |
||||
:param trainDescriptors: dataset of descriptors furnished by user |
||||
:param matches: vector to host retrieved matches |
||||
:param maxDist: search radius |
||||
:param mask: mask to select which input descriptors must be matched to ones in dataset |
||||
:param masks: vector of masks to select which input descriptors must be matched to ones in dataset (the *i*-th mask in vector indicates whether each input query can be matched with descriptors in dataset relative to *i*-th image) |
||||
:param compactResult: flag to obtain a compact result (if true, a vector that doesn't contain any matches for a given query is not inserted in final result) |
||||
|
||||
|
||||
|
||||
Related pages |
||||
------------- |
||||
|
||||
* :ref:`line_descriptor` |
||||
* :ref:`binary_descriptor` |
||||
* :ref:`drawing` |
||||
|
||||
|
||||
References |
||||
---------- |
||||
|
||||
.. [MIH] Norouzi, Mohammad, Ali Punjani, and David J. Fleet. *Fast search in hamming space with multi-index hashing*, Computer Vision and Pattern Recognition (CVPR), 2012 IEEE Conference on. IEEE, 2012. |
After Width: | Height: | Size: 138 KiB |
After Width: | Height: | Size: 164 KiB |
After Width: | Height: | Size: 451 KiB |
@ -0,0 +1,428 @@ |
||||
Line Features Tutorial |
||||
====================== |
||||
|
||||
In this tutorial it will be shown how to: |
||||
|
||||
* use the *BinaryDescriptor* interface to extract lines and store them in *KeyLine* objects |
||||
* use the same interface to compute descriptors for every extracted line |
||||
* use the *BynaryDescriptorMatcher* to determine matches among descriptors obtained from different images |
||||
|
||||
|
||||
Lines extraction and descriptors computation |
||||
-------------------------------------------- |
||||
|
||||
In the following snippet of code, it is shown how to detect lines from an image. The LSD extractor is initialized with *LSD_REFINE_ADV* option; remaining parameters are left to their default values. A mask of ones is used in order to accept all extracted lines, which, at the end, are displayed using random colors for octave 0. |
||||
|
||||
.. code-block:: cpp |
||||
|
||||
#include <opencv2/line_descriptor.hpp> |
||||
|
||||
#include "opencv2/core/utility.hpp" |
||||
#include "opencv2/core/private.hpp" |
||||
#include <opencv2/imgproc.hpp> |
||||
#include <opencv2/features2d.hpp> |
||||
#include <opencv2/highgui.hpp> |
||||
|
||||
#include <iostream> |
||||
|
||||
using namespace cv; |
||||
using namespace std; |
||||
|
||||
static const char* keys = |
||||
{ "{@image_path | | Image path }" }; |
||||
|
||||
static void help() |
||||
{ |
||||
cout << "\nThis example shows the functionalities of lines extraction " << "furnished by BinaryDescriptor class\n" |
||||
<< "Please, run this sample using a command in the form\n" << "./example_line_descriptor_lines_extraction <path_to_input_image>" << endl; |
||||
} |
||||
|
||||
int main( int argc, char** argv ) |
||||
{ |
||||
/* get parameters from comand line */ |
||||
CommandLineParser parser( argc, argv, keys ); |
||||
String image_path = parser.get<String>( 0 ); |
||||
|
||||
if( image_path.empty() ) |
||||
{ |
||||
help(); |
||||
return -1; |
||||
} |
||||
|
||||
/* load image */ |
||||
cv::Mat imageMat = imread( image_path, 1 ); |
||||
if( imageMat.data == NULL ) |
||||
{ |
||||
std::cout << "Error, image could not be loaded. Please, check its path" << std::endl; |
||||
} |
||||
|
||||
/* create a ramdom binary mask */ |
||||
cv::Mat mask = Mat::ones( imageMat.size(), CV_8UC1 ); |
||||
|
||||
/* create a pointer to a BinaryDescriptor object with deafult parameters */ |
||||
Ptr<BinaryDescriptor> bd = BinaryDescriptor::createBinaryDescriptor(); |
||||
|
||||
/* create a structure to store extracted lines */ |
||||
vector<KeyLine> lines; |
||||
|
||||
/* extract lines */ |
||||
bd->detect( imageMat, lines, mask ); |
||||
|
||||
/* draw lines extracted from octave 0 */ |
||||
cv::Mat output = imageMat.clone(); |
||||
if( output.channels() == 1 ) |
||||
cvtColor( output, output, COLOR_GRAY2BGR ); |
||||
for ( size_t i = 0; i < lines.size(); i++ ) |
||||
{ |
||||
KeyLine kl = lines[i]; |
||||
if( kl.octave == 0) |
||||
{ |
||||
/* get a random color */ |
||||
int R = ( rand() % (int) ( 255 + 1 ) ); |
||||
int G = ( rand() % (int) ( 255 + 1 ) ); |
||||
int B = ( rand() % (int) ( 255 + 1 ) ); |
||||
|
||||
/* get extremes of line */ |
||||
Point pt1 = Point( kl.startPointX, kl.startPointY ); |
||||
Point pt2 = Point( kl.endPointX, kl.endPointY ); |
||||
|
||||
/* draw line */ |
||||
line( output, pt1, pt2, Scalar( B, G, R ), 5 ); |
||||
} |
||||
|
||||
} |
||||
|
||||
/* show lines on image */ |
||||
imshow( "Lines", output ); |
||||
waitKey(); |
||||
} |
||||
|
||||
.. |
||||
|
||||
This is the result obtained for famous cameraman image: |
||||
|
||||
.. image:: pics/lines_cameraman_edl.png |
||||
:width: 512px |
||||
:align: center |
||||
:height: 512px |
||||
:alt: alternate text |
||||
|
||||
Another way to extract lines is using *LSDDetector* class; such class uses the LSD extractor to compute lines. To obtain this result, it is sufficient to use the snippet code seen above, just modifying it by the rows |
||||
|
||||
.. code-block:: cpp |
||||
|
||||
/* create a pointer to an LSDDetector object */ |
||||
Ptr<LSDDetector> lsd = LSDDetector::createLSDDetector(); |
||||
|
||||
/* compute lines */ |
||||
std::vector<KeyLine> keylines; |
||||
lsd->detect( imageMat, keylines, mask ); |
||||
|
||||
.. |
||||
|
||||
Here's the result returned by LSD detector again on cameraman picture: |
||||
|
||||
.. image:: pics/cameraman_lines2.png |
||||
:width: 512px |
||||
:align: center |
||||
:height: 512px |
||||
:alt: alternate text |
||||
|
||||
Once keylines have been detected, it is possible to compute their descriptors as shown in the following: |
||||
|
||||
.. code-block:: cpp |
||||
|
||||
#include <opencv2/line_descriptor.hpp> |
||||
|
||||
#include "opencv2/core/utility.hpp" |
||||
#include "opencv2/core/private.hpp" |
||||
#include <opencv2/imgproc.hpp> |
||||
#include <opencv2/features2d.hpp> |
||||
#include <opencv2/highgui.hpp> |
||||
|
||||
#include <iostream> |
||||
|
||||
using namespace cv; |
||||
|
||||
static const char* keys = |
||||
{ "{@image_path | | Image path }" }; |
||||
|
||||
static void help() |
||||
{ |
||||
std::cout << "\nThis example shows the functionalities of lines extraction " << "and descriptors computation furnished by BinaryDescriptor class\n" |
||||
<< "Please, run this sample using a command in the form\n" << "./example_line_descriptor_compute_descriptors <path_to_input_image>" |
||||
<< std::endl; |
||||
} |
||||
|
||||
int main( int argc, char** argv ) |
||||
{ |
||||
/* get parameters from command line */ |
||||
CommandLineParser parser( argc, argv, keys ); |
||||
String image_path = parser.get<String>( 0 ); |
||||
|
||||
if( image_path.empty() ) |
||||
{ |
||||
help(); |
||||
return -1; |
||||
} |
||||
|
||||
/* load image */ |
||||
cv::Mat imageMat = imread( image_path, 1 ); |
||||
if( imageMat.data == NULL ) |
||||
{ |
||||
std::cout << "Error, image could not be loaded. Please, check its path" << std::endl; |
||||
} |
||||
|
||||
/* create a binary mask */ |
||||
cv::Mat mask = Mat::ones( imageMat.size(), CV_8UC1 ); |
||||
|
||||
/* create a pointer to a BinaryDescriptor object with default parameters */ |
||||
Ptr<BinaryDescriptor> bd = BinaryDescriptor::createBinaryDescriptor(); |
||||
|
||||
/* compute lines */ |
||||
std::vector<KeyLine> keylines; |
||||
bd->detect( imageMat, keylines, mask ); |
||||
|
||||
/* compute descriptors */ |
||||
cv::Mat descriptors; |
||||
bd->compute( imageMat, keylines, descriptors ); |
||||
|
||||
} |
||||
|
||||
.. |
||||
|
||||
|
||||
Matching among descriptors |
||||
-------------------------- |
||||
|
||||
If we have extracted descriptors from two different images, it is possible to search for matches among them. One way of doing it is matching exactly a descriptor to each input query descriptor, choosing the one at closest distance: |
||||
|
||||
.. code-block:: cpp |
||||
|
||||
#include <opencv2/line_descriptor.hpp> |
||||
|
||||
#include "opencv2/core/utility.hpp" |
||||
#include "opencv2/core/private.hpp" |
||||
#include <opencv2/imgproc.hpp> |
||||
#include <opencv2/features2d.hpp> |
||||
#include <opencv2/highgui.hpp> |
||||
|
||||
#include <iostream> |
||||
|
||||
using namespace cv; |
||||
|
||||
static const char* keys = |
||||
{ "{@image_path1 | | Image path 1 }" |
||||
"{@image_path2 | | Image path 2 }" }; |
||||
|
||||
static void help() |
||||
{ |
||||
std::cout << "\nThis example shows the functionalities of lines extraction " << "and descriptors computation furnished by BinaryDescriptor class\n" |
||||
<< "Please, run this sample using a command in the form\n" << "./example_line_descriptor_compute_descriptors <path_to_input_image 1>" |
||||
<< "<path_to_input_image 2>" << std::endl; |
||||
|
||||
} |
||||
|
||||
int main( int argc, char** argv ) |
||||
{ |
||||
/* get parameters from comand line */ |
||||
CommandLineParser parser( argc, argv, keys ); |
||||
String image_path1 = parser.get<String>( 0 ); |
||||
String image_path2 = parser.get<String>( 1 ); |
||||
|
||||
if( image_path1.empty() || image_path2.empty() ) |
||||
{ |
||||
help(); |
||||
return -1; |
||||
} |
||||
|
||||
/* load image */ |
||||
cv::Mat imageMat1 = imread( image_path1, 1 ); |
||||
cv::Mat imageMat2 = imread( image_path2, 1 ); |
||||
|
||||
waitKey(); |
||||
if( imageMat1.data == NULL || imageMat2.data == NULL ) |
||||
{ |
||||
std::cout << "Error, images could not be loaded. Please, check their path" << std::endl; |
||||
} |
||||
|
||||
/* create binary masks */ |
||||
cv::Mat mask1 = Mat::ones( imageMat1.size(), CV_8UC1 ); |
||||
cv::Mat mask2 = Mat::ones( imageMat2.size(), CV_8UC1 ); |
||||
|
||||
/* create a pointer to a BinaryDescriptor object with default parameters */ |
||||
Ptr<BinaryDescriptor> bd = BinaryDescriptor::createBinaryDescriptor(); |
||||
|
||||
/* compute lines */ |
||||
std::vector<KeyLine> keylines1, keylines2; |
||||
bd->detect( imageMat1, keylines1, mask1 ); |
||||
bd->detect( imageMat2, keylines2, mask2 ); |
||||
|
||||
/* compute descriptors */ |
||||
cv::Mat descr1, descr2; |
||||
bd->compute( imageMat1, keylines1, descr1 ); |
||||
bd->compute( imageMat2, keylines2, descr2 ); |
||||
|
||||
/* create a BinaryDescriptorMatcher object */ |
||||
Ptr<BinaryDescriptorMatcher> bdm = BinaryDescriptorMatcher::createBinaryDescriptorMatcher(); |
||||
|
||||
/* require match */ |
||||
std::vector<DMatch> matches; |
||||
bdm->match( descr1, descr2, matches ); |
||||
|
||||
/* plot matches */ |
||||
cv::Mat outImg; |
||||
std::vector<char> mask( matches.size(), 1 ); |
||||
drawLineMatches( imageMat1, keylines1, imageMat2, keylines2, matches, outImg, Scalar::all( -1 ), Scalar::all( -1 ), mask, |
||||
DrawLinesMatchesFlags::DEFAULT ); |
||||
|
||||
imshow( "Matches", outImg ); |
||||
waitKey(); |
||||
} |
||||
|
||||
.. |
||||
|
||||
|
||||
|
||||
Sometimes, we could be interested in searching for the closest *k* descriptors, given an input one. This requires to modify slightly previous code: |
||||
|
||||
.. code-block:: cpp |
||||
|
||||
/* prepare a structure to host matches */ |
||||
std::vector<std::vector<DMatch> > matches; |
||||
|
||||
/* require knn match */ |
||||
bdm->knnMatch( descr1, descr2, matches, 6 ); |
||||
.. |
||||
|
||||
In the above example, the closest 6 descriptors are returned for every query. In some cases, we could have a search radius and look for all descriptors distant at the most *r* from input query. Previous code must me modified: |
||||
|
||||
.. code-block:: cpp |
||||
|
||||
|
||||
/* prepare a structure to host matches */ |
||||
std::vector<std::vector<DMatch> > matches; |
||||
|
||||
/* compute matches */ |
||||
bdm->radiusMatch( queries, matches, 30 ); |
||||
|
||||
.. |
||||
|
||||
Here's an example om matching among descriptors extratced from original cameraman image and its downsampled (and blurred) version: |
||||
|
||||
.. image:: pics/matching2.png |
||||
:width: 765px |
||||
:align: center |
||||
:height: 540px |
||||
:alt: alternate text |
||||
|
||||
Querying internal database |
||||
-------------------------- |
||||
|
||||
The *BynaryDescriptorMatcher* class, owns an internal database that can be populated with descriptors extracted from different images and queried using one of the modalities described in previous section. |
||||
Population of internal dataset can be done using the *add* function; such function doesn't directly add new data to database, but it just stores it them locally. The real update happens when function *train* is invoked or when any querying function is executed, since each of them invokes *train* before querying. |
||||
When queried, internal database not only returns required descriptors, but, for every returned match, it is able to tell which image matched descriptor was extracted from. |
||||
An example of internal dataset usage is described in the following code; after adding locally new descriptors, a radius search is invoked. This provokes local data to be transferred to dataset, which, in turn, is then queried. |
||||
|
||||
.. code-block:: cpp |
||||
|
||||
#include <opencv2/line_descriptor.hpp> |
||||
|
||||
#include "opencv2/core/utility.hpp" |
||||
#include "opencv2/core/private.hpp" |
||||
#include <opencv2/imgproc.hpp> |
||||
#include <opencv2/features2d.hpp> |
||||
#include <opencv2/highgui.hpp> |
||||
|
||||
#include <iostream> |
||||
#include <vector> |
||||
|
||||
using namespace cv; |
||||
|
||||
static const std::string images[] = |
||||
{ "cameraman.jpg", "church.jpg", "church2.png", "einstein.jpg", "stuff.jpg" }; |
||||
|
||||
static const char* keys = |
||||
{ "{@image_path | | Image path }" }; |
||||
|
||||
static void help() |
||||
{ |
||||
std::cout << "\nThis example shows the functionalities of radius matching " << "Please, run this sample using a command in the form\n" |
||||
<< "./example_line_descriptor_radius_matching <path_to_input_images>/" << std::endl; |
||||
} |
||||
|
||||
int main( int argc, char** argv ) |
||||
{ |
||||
/* get parameters from comand line */ |
||||
CommandLineParser parser( argc, argv, keys ); |
||||
String pathToImages = parser.get<String>( 0 ); |
||||
|
||||
/* create structures for hosting KeyLines and descriptors */ |
||||
int num_elements = sizeof ( images ) / sizeof ( images[0] ); |
||||
std::vector<Mat> descriptorsMat; |
||||
std::vector<std::vector<KeyLine> > linesMat; |
||||
|
||||
/*create a pointer to a BinaryDescriptor object */ |
||||
Ptr<BinaryDescriptor> bd = BinaryDescriptor::createBinaryDescriptor(); |
||||
|
||||
/* compute lines and descriptors */ |
||||
for ( int i = 0; i < num_elements; i++ ) |
||||
{ |
||||
/* get path to image */ |
||||
std::stringstream image_path; |
||||
image_path << pathToImages << images[i]; |
||||
|
||||
/* load image */ |
||||
Mat loadedImage = imread( image_path.str().c_str(), 1 ); |
||||
if( loadedImage.data == NULL ) |
||||
{ |
||||
std::cout << "Could not load images." << std::endl; |
||||
help(); |
||||
exit( -1 ); |
||||
} |
||||
|
||||
/* compute lines and descriptors */ |
||||
std::vector<KeyLine> lines; |
||||
Mat computedDescr; |
||||
bd->detect( loadedImage, lines ); |
||||
bd->compute( loadedImage, lines, computedDescr ); |
||||
|
||||
descriptorsMat.push_back( computedDescr ); |
||||
linesMat.push_back( lines ); |
||||
|
||||
} |
||||
|
||||
/* compose a queries matrix */ |
||||
Mat queries; |
||||
for ( size_t j = 0; j < descriptorsMat.size(); j++ ) |
||||
{ |
||||
if( descriptorsMat[j].rows >= 5 ) |
||||
queries.push_back( descriptorsMat[j].rowRange( 0, 5 ) ); |
||||
|
||||
else if( descriptorsMat[j].rows > 0 && descriptorsMat[j].rows < 5 ) |
||||
queries.push_back( descriptorsMat[j] ); |
||||
} |
||||
|
||||
std::cout << "It has been generated a matrix of " << queries.rows << " descriptors" << std::endl; |
||||
|
||||
/* create a BinaryDescriptorMatcher object */ |
||||
Ptr<BinaryDescriptorMatcher> bdm = BinaryDescriptorMatcher::createBinaryDescriptorMatcher(); |
||||
|
||||
/* populate matcher */ |
||||
bdm->add( descriptorsMat ); |
||||
|
||||
/* compute matches */ |
||||
std::vector<std::vector<DMatch> > matches; |
||||
bdm->radiusMatch( queries, matches, 30 ); |
||||
|
||||
/* print matches */ |
||||
for ( size_t q = 0; q < matches.size(); q++ ) |
||||
{ |
||||
for ( size_t m = 0; m < matches[q].size(); m++ ) |
||||
{ |
||||
DMatch dm = matches[q][m]; |
||||
std::cout << "Descriptor: " << q << " Image: " << dm.imgIdx << " Distance: " << dm.distance << std::endl; |
||||
} |
||||
} |
||||
} |
||||
.. |
@ -0,0 +1,53 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __OPENCV_LINE_DESCRIPTOR_HPP__ |
||||
#define __OPENCV_LINE_DESCRIPTOR_HPP__ |
||||
|
||||
#include "opencv2/line_descriptor/descriptor.hpp" |
||||
|
||||
namespace cv |
||||
{ |
||||
CV_EXPORTS bool initModule_line_descriptor( void ); |
||||
|
||||
} |
||||
|
||||
#endif |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,77 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Biagio Montesano, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "perf_precomp.hpp" |
||||
|
||||
using namespace cv; |
||||
using namespace cv::line_descriptor; |
||||
using namespace std; |
||||
using namespace perf; |
||||
using std::tr1::make_tuple; |
||||
using std::tr1::get; |
||||
|
||||
typedef perf::TestBaseWithParam<std::string> file_str; |
||||
|
||||
#define IMAGES \ |
||||
"line_descriptor_data/cameraman.jpg", "line_descriptor_data/lena.bmp" |
||||
|
||||
PERF_TEST_P(file_str, descriptors, testing::Values(IMAGES)) |
||||
{ |
||||
std::string filename = getDataPath( GetParam() ); |
||||
|
||||
Mat frame = imread( filename, 1 ); |
||||
|
||||
if( frame.empty() ) |
||||
FAIL()<< "Unable to load source image " << filename; |
||||
|
||||
Mat descriptors; |
||||
std::vector<KeyLine> keylines; |
||||
Ptr<BinaryDescriptor> bd = BinaryDescriptor::createBinaryDescriptor(); |
||||
|
||||
TEST_CYCLE() |
||||
{ |
||||
bd->detect( frame, keylines ); |
||||
bd->compute( frame, keylines, descriptors ); |
||||
} |
||||
|
||||
SANITY_CHECK( descriptors ); |
||||
|
||||
} |
@ -0,0 +1,138 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Biagio Montesano, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "perf_precomp.hpp" |
||||
|
||||
using namespace cv; |
||||
using namespace cv::line_descriptor; |
||||
using namespace std; |
||||
using namespace perf; |
||||
using std::tr1::make_tuple; |
||||
using std::tr1::get; |
||||
|
||||
typedef perf::TestBaseWithParam<std::string> file_str; |
||||
|
||||
#define IMAGES \ |
||||
"line_descriptor_data/cameraman.jpg", "line_descriptor_data/lena.bmp" |
||||
|
||||
void createMatFromVec( const std::vector<KeyLine>& linesVec, Mat& output ); |
||||
|
||||
void createMatFromVec( const std::vector<KeyLine>& linesVec, Mat& output ) |
||||
{ |
||||
output = Mat( (int) linesVec.size(), 17, CV_32FC1 ); |
||||
|
||||
for ( int i = 0; i < (int) linesVec.size(); i++ ) |
||||
{ |
||||
std::vector<float> klData; |
||||
KeyLine kl = linesVec[i]; |
||||
klData.push_back( kl.angle ); |
||||
klData.push_back( (float) kl.class_id ); |
||||
klData.push_back( kl.ePointInOctaveX ); |
||||
klData.push_back( kl.ePointInOctaveY ); |
||||
klData.push_back( kl.endPointX ); |
||||
klData.push_back( kl.endPointY ); |
||||
klData.push_back( kl.lineLength ); |
||||
klData.push_back( (float) kl.numOfPixels ); |
||||
klData.push_back( (float) kl.octave ); |
||||
klData.push_back( kl.pt.x ); |
||||
klData.push_back( kl.pt.y ); |
||||
klData.push_back( kl.response ); |
||||
klData.push_back( kl.sPointInOctaveX ); |
||||
klData.push_back( kl.sPointInOctaveY ); |
||||
klData.push_back( kl.size ); |
||||
klData.push_back( kl.startPointX ); |
||||
klData.push_back( kl.startPointY ); |
||||
|
||||
float* pointerToRow = output.ptr<float>( i ); |
||||
for ( int j = 0; j < 17; j++ ) |
||||
{ |
||||
*pointerToRow = klData[j]; |
||||
pointerToRow++; |
||||
} |
||||
} |
||||
} |
||||
|
||||
PERF_TEST_P(file_str, detect, testing::Values(IMAGES)) |
||||
{ |
||||
std::string filename = getDataPath( GetParam() ); |
||||
|
||||
Mat frame = imread( filename, 1 ); |
||||
|
||||
if( frame.empty() ) |
||||
FAIL()<< "Unable to load source image " << filename; |
||||
|
||||
Mat lines; |
||||
std::vector<KeyLine> keylines; |
||||
Ptr<BinaryDescriptor> bd = BinaryDescriptor::createBinaryDescriptor(); |
||||
|
||||
TEST_CYCLE() |
||||
{ |
||||
bd->detect( frame, keylines ); |
||||
createMatFromVec( keylines, lines ); |
||||
} |
||||
|
||||
SANITY_CHECK( lines ); |
||||
|
||||
} |
||||
|
||||
PERF_TEST_P(file_str, detect_lsd, testing::Values(IMAGES)) |
||||
{ |
||||
std::string filename = getDataPath( GetParam() ); |
||||
std::cout << filename.c_str() << std::endl; |
||||
|
||||
Mat frame = imread( filename, 1 ); |
||||
|
||||
if( frame.empty() ) |
||||
FAIL()<< "Unable to load source image " << filename; |
||||
|
||||
Mat lines; |
||||
std::vector<KeyLine> keylines; |
||||
Ptr<LSDDetector> lsd = LSDDetector::createLSDDetector(); |
||||
|
||||
TEST_CYCLE() |
||||
{ |
||||
lsd->detect( frame, keylines, 2, 1 ); |
||||
createMatFromVec( keylines, lines ); |
||||
} |
||||
|
||||
SANITY_CHECK( lines ); |
||||
|
||||
} |
@ -0,0 +1,45 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Biagio Montesano, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "perf_precomp.hpp" |
||||
|
||||
CV_PERF_TEST_MAIN( line_descriptor ) |
||||
|
@ -0,0 +1,187 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Biagio Montesano, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "perf_precomp.hpp" |
||||
|
||||
using namespace cv; |
||||
using namespace cv::line_descriptor; |
||||
using namespace std; |
||||
using namespace perf; |
||||
using std::tr1::make_tuple; |
||||
using std::tr1::get; |
||||
|
||||
#define QUERY_DES_COUNT 300 |
||||
#define DIM 32 |
||||
#define COUNT_FACTOR 4 |
||||
#define RADIUS 3 |
||||
|
||||
void generateData( Mat& query, Mat& train ); |
||||
uchar invertSingleBits( uchar dividend_char, int numBits ); |
||||
|
||||
/* invert numBits bits in input char */ |
||||
uchar invertSingleBits( uchar dividend_char, int numBits ) |
||||
{ |
||||
std::vector<int> bin_vector; |
||||
long dividend; |
||||
long bin_num; |
||||
|
||||
/* convert input char to a long */ |
||||
dividend = (long) dividend_char; |
||||
|
||||
/*if a 0 has been obtained, just generate a 8-bit long vector of zeros */ |
||||
if( dividend == 0 ) |
||||
bin_vector = std::vector<int>( 8, 0 ); |
||||
|
||||
/* else, apply classic decimal to binary conversion */ |
||||
else |
||||
{ |
||||
while ( dividend >= 1 ) |
||||
{ |
||||
bin_num = dividend % 2; |
||||
dividend /= 2; |
||||
bin_vector.push_back( bin_num ); |
||||
} |
||||
} |
||||
|
||||
/* ensure that binary vector always has length 8 */ |
||||
if( bin_vector.size() < 8 ) |
||||
{ |
||||
std::vector<int> zeros( 8 - bin_vector.size(), 0 ); |
||||
bin_vector.insert( bin_vector.end(), zeros.begin(), zeros.end() ); |
||||
} |
||||
|
||||
/* invert numBits bits */ |
||||
for ( int index = 0; index < numBits; index++ ) |
||||
{ |
||||
if( bin_vector[index] == 0 ) |
||||
bin_vector[index] = 1; |
||||
|
||||
else |
||||
bin_vector[index] = 0; |
||||
} |
||||
|
||||
/* reconvert to decimal */ |
||||
uchar result = 0; |
||||
for ( int i = (int) bin_vector.size() - 1; i >= 0; i-- ) |
||||
result += (uchar) ( bin_vector[i] * pow( 2, i ) ); |
||||
|
||||
return result; |
||||
} |
||||
|
||||
void generateData( Mat& query, Mat& train ) |
||||
{ |
||||
RNG& rng = theRNG(); |
||||
|
||||
Mat buf( QUERY_DES_COUNT, DIM, CV_8UC1 ); |
||||
rng.fill( buf, RNG::UNIFORM, Scalar( 0 ), Scalar( 255 ) ); |
||||
buf.convertTo( query, CV_8UC1 ); |
||||
|
||||
for ( int i = 0; i < query.rows; i++ ) |
||||
{ |
||||
for ( int j = 0; j < COUNT_FACTOR; j++ ) |
||||
{ |
||||
train.push_back( query.row( i ) ); |
||||
int randCol = rand() % 32; |
||||
uchar u = query.at<uchar>( i, randCol ); |
||||
uchar modified_u = invertSingleBits( u, j + 1 ); |
||||
train.at<uchar>( i * COUNT_FACTOR + j, randCol ) = modified_u; |
||||
} |
||||
} |
||||
} |
||||
|
||||
PERF_TEST(matching, single_match) |
||||
{ |
||||
Mat query, train; |
||||
std::vector<DMatch> dm; |
||||
Ptr<BinaryDescriptorMatcher> bd = BinaryDescriptorMatcher::createBinaryDescriptorMatcher(); |
||||
|
||||
generateData( query, train ); |
||||
|
||||
TEST_CYCLE() |
||||
bd->match( query, train, dm ); |
||||
|
||||
SANITY_CHECK_MATCHES( dm ); |
||||
|
||||
} |
||||
|
||||
PERF_TEST(knn_matching, knn_match_distances_test) |
||||
{ |
||||
Mat query, train, distances; |
||||
std::vector<std::vector<DMatch> > dm; |
||||
Ptr<BinaryDescriptorMatcher> bd = BinaryDescriptorMatcher::createBinaryDescriptorMatcher(); |
||||
|
||||
generateData( query, train ); |
||||
|
||||
TEST_CYCLE() |
||||
{ |
||||
bd->knnMatch( query, train, dm, QUERY_DES_COUNT ); |
||||
for ( int i = 0; i < (int) dm.size(); i++ ) |
||||
{ |
||||
for ( int j = 0; j < (int) dm[i].size(); j++ ) |
||||
distances.push_back( dm[i][j].distance ); |
||||
} |
||||
} |
||||
|
||||
SANITY_CHECK( distances ); |
||||
} |
||||
|
||||
PERF_TEST(radius_match, radius_match_distances_test) |
||||
{ |
||||
Mat query, train, distances; |
||||
std::vector<std::vector<DMatch> > dm; |
||||
Ptr<BinaryDescriptorMatcher> bd = BinaryDescriptorMatcher::createBinaryDescriptorMatcher(); |
||||
|
||||
generateData( query, train ); |
||||
|
||||
TEST_CYCLE() |
||||
{ |
||||
bd->radiusMatch( query, train, dm, RADIUS ); |
||||
for ( int i = 0; i < (int) dm.size(); i++ ) |
||||
{ |
||||
for ( int j = 0; j < (int) dm[i].size(); j++ ) |
||||
distances.push_back( dm[i][j].distance ); |
||||
} |
||||
} |
||||
|
||||
SANITY_CHECK( distances ); |
||||
|
||||
} |
||||
|
@ -0,0 +1,63 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Biagio Montesano, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
|
||||
#ifdef __GNUC__ |
||||
# pragma GCC diagnostic ignored "-Wmissing-declarations" |
||||
# if defined __clang__ || defined __APPLE__ |
||||
# pragma GCC diagnostic ignored "-Wmissing-prototypes" |
||||
# pragma GCC diagnostic ignored "-Wextra" |
||||
# endif |
||||
#endif |
||||
|
||||
#ifndef __OPENCV_PERF_PRECOMP_HPP__ |
||||
#define __OPENCV_PERF_PRECOMP_HPP__ |
||||
|
||||
#include "opencv2/ts.hpp" |
||||
#include "opencv2/highgui.hpp" |
||||
#include "opencv2/features2d.hpp" |
||||
#include "opencv2/line_descriptor.hpp" |
||||
|
||||
#ifdef GTEST_CREATE_SHARED_LIBRARY |
||||
#error no modules except ts should have GTEST_CREATE_SHARED_LIBRARY defined |
||||
#endif |
||||
|
||||
#endif |
@ -0,0 +1,102 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Biagio Montesano, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include <opencv2/line_descriptor.hpp> |
||||
|
||||
#include "opencv2/core/utility.hpp" |
||||
#include "opencv2/core/private.hpp" |
||||
#include <opencv2/imgproc.hpp> |
||||
#include <opencv2/features2d.hpp> |
||||
#include <opencv2/highgui.hpp> |
||||
|
||||
#include <iostream> |
||||
|
||||
using namespace cv; |
||||
using namespace cv::line_descriptor; |
||||
|
||||
|
||||
static const char* keys = |
||||
{ "{@image_path | | Image path }" }; |
||||
|
||||
static void help() |
||||
{ |
||||
std::cout << "\nThis example shows the functionalities of lines extraction " << "and descriptors computation furnished by BinaryDescriptor class\n" |
||||
<< "Please, run this sample using a command in the form\n" << "./example_line_descriptor_compute_descriptors <path_to_input_image>" |
||||
<< std::endl; |
||||
} |
||||
|
||||
int main( int argc, char** argv ) |
||||
{ |
||||
/* get parameters from command line */ |
||||
CommandLineParser parser( argc, argv, keys ); |
||||
String image_path = parser.get<String>( 0 ); |
||||
|
||||
if( image_path.empty() ) |
||||
{ |
||||
help(); |
||||
return -1; |
||||
} |
||||
|
||||
/* load image */ |
||||
cv::Mat imageMat = imread( image_path, 1 ); |
||||
if( imageMat.data == NULL ) |
||||
{ |
||||
std::cout << "Error, image could not be loaded. Please, check its path" << std::endl; |
||||
} |
||||
|
||||
/* create a binary mask */ |
||||
cv::Mat mask = Mat::ones( imageMat.size(), CV_8UC1 ); |
||||
|
||||
/* create a pointer to a BinaryDescriptor object with default parameters */ |
||||
Ptr<BinaryDescriptor> bd = BinaryDescriptor::createBinaryDescriptor(); |
||||
|
||||
/* compute lines */ |
||||
std::vector<KeyLine> keylines; |
||||
bd->detect( imageMat, keylines, mask ); |
||||
|
||||
/* compute descriptors */ |
||||
cv::Mat descriptors; |
||||
|
||||
bd->compute( imageMat, keylines, descriptors); |
||||
|
||||
} |
||||
|
||||
|
@ -0,0 +1,198 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Biagio Montesano, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include <opencv2/line_descriptor.hpp> |
||||
|
||||
#include "opencv2/core/utility.hpp" |
||||
#include "opencv2/core/private.hpp" |
||||
#include <opencv2/imgproc.hpp> |
||||
#include <opencv2/features2d.hpp> |
||||
#include <opencv2/highgui.hpp> |
||||
|
||||
#include <iostream> |
||||
#include <vector> |
||||
#include <time.h> |
||||
|
||||
using namespace cv; |
||||
using namespace cv::line_descriptor; |
||||
|
||||
static const char* keys = |
||||
{ "{@image_path1 | | Image path 1 }" |
||||
"{@image_path2 | | Image path 2 }" }; |
||||
|
||||
static void help() |
||||
{ |
||||
std::cout << "\nThis example shows the functionalities of descriptors matching\n" << "Please, run this sample using a command in the form\n" |
||||
<< "./example_line_descriptor_matching <path_to_input_image 1>" << "<path_to_input_image 2>" << std::endl; |
||||
|
||||
} |
||||
|
||||
uchar invertSingleBits( uchar dividend_char, int numBits ); |
||||
|
||||
/* invert numBits bits in input char */ |
||||
uchar invertSingleBits( uchar dividend_char, int numBits ) |
||||
{ |
||||
std::vector<int> bin_vector; |
||||
long dividend; |
||||
long bin_num; |
||||
|
||||
/* convert input char to a long */ |
||||
dividend = (long) dividend_char; |
||||
|
||||
/*if a 0 has been obtained, just generate a 8-bit long vector of zeros */ |
||||
if( dividend == 0 ) |
||||
bin_vector = std::vector<int>( 8, 0 ); |
||||
|
||||
/* else, apply classic decimal to binary conversion */ |
||||
else |
||||
{ |
||||
while ( dividend >= 1 ) |
||||
{ |
||||
bin_num = dividend % 2; |
||||
dividend /= 2; |
||||
bin_vector.push_back( bin_num ); |
||||
} |
||||
} |
||||
|
||||
/* ensure that binary vector always has length 8 */ |
||||
if( bin_vector.size() < 8 ) |
||||
{ |
||||
std::vector<int> zeros( 8 - bin_vector.size(), 0 ); |
||||
bin_vector.insert( bin_vector.end(), zeros.begin(), zeros.end() ); |
||||
} |
||||
|
||||
/* invert numBits bits */ |
||||
for ( int index = 0; index < numBits; index++ ) |
||||
{ |
||||
if( bin_vector[index] == 0 ) |
||||
bin_vector[index] = 1; |
||||
|
||||
else |
||||
bin_vector[index] = 0; |
||||
} |
||||
|
||||
/* reconvert to decimal */ |
||||
uchar result = 0; |
||||
for ( int i = (int) bin_vector.size() - 1; i >= 0; i-- ) |
||||
result += (uchar) ( bin_vector[i] * pow( 2, i ) ); |
||||
|
||||
return result; |
||||
} |
||||
|
||||
int main( int argc, char** argv ) |
||||
{ |
||||
/* get parameters from comand line */ |
||||
CommandLineParser parser( argc, argv, keys ); |
||||
String image_path1 = parser.get<String>( 0 ); |
||||
String image_path2 = parser.get<String>( 1 ); |
||||
|
||||
if( image_path1.empty() || image_path2.empty() ) |
||||
{ |
||||
help(); |
||||
return -1; |
||||
} |
||||
|
||||
/* load image */ |
||||
cv::Mat imageMat1 = imread( image_path1, 1 ); |
||||
cv::Mat imageMat2 = imread( image_path2, 1 ); |
||||
|
||||
if( imageMat1.data == NULL || imageMat2.data == NULL ) |
||||
{ |
||||
std::cout << "Error, images could not be loaded. Please, check their paths" << std::endl; |
||||
} |
||||
|
||||
/* create binary masks */ |
||||
cv::Mat mask1 = Mat::ones( imageMat1.size(), CV_8UC1 ); |
||||
cv::Mat mask2 = Mat::ones( imageMat2.size(), CV_8UC1 ); |
||||
|
||||
/* create a pointer to a BinaryDescriptor object with default parameters */ |
||||
Ptr<BinaryDescriptor> bd = BinaryDescriptor::createBinaryDescriptor(); |
||||
|
||||
/* compute lines */ |
||||
std::vector<KeyLine> keylines1, keylines2; |
||||
bd->detect( imageMat1, keylines1, mask1 ); |
||||
bd->detect( imageMat2, keylines2, mask2 ); |
||||
|
||||
/* compute descriptors */ |
||||
cv::Mat descr1, descr2; |
||||
bd->compute( imageMat1, keylines1, descr1 ); |
||||
bd->compute( imageMat2, keylines2, descr2 ); |
||||
|
||||
/* create a BinaryDescriptorMatcher object */ |
||||
Ptr<BinaryDescriptorMatcher> bdm = BinaryDescriptorMatcher::createBinaryDescriptorMatcher(); |
||||
|
||||
/* make a copy of descr2 mat */ |
||||
Mat descr2Copy = descr1.clone(); |
||||
|
||||
/* randomly change some bits in original descriptors */ |
||||
srand( (unsigned int) time( NULL ) ); |
||||
|
||||
for ( int j = 0; j < descr1.rows; j++ ) |
||||
{ |
||||
/* select a random column */ |
||||
int randCol = rand() % 32; |
||||
|
||||
/* get correspondent data */ |
||||
uchar u = descr1.at<uchar>( j, randCol ); |
||||
|
||||
/* change bits */ |
||||
for ( int k = 1; k <= 5; k++ ) |
||||
{ |
||||
/* copy current row to train matrix */ |
||||
descr2Copy.push_back( descr1.row( j ) ); |
||||
|
||||
/* invert k bits */ |
||||
uchar uc = invertSingleBits( u, k ); |
||||
|
||||
/* update current row in train matrix */ |
||||
descr2Copy.at<uchar>( descr2Copy.rows - 1, randCol ) = uc; |
||||
} |
||||
} |
||||
|
||||
/* prepare a structure to host matches */ |
||||
std::vector<std::vector<DMatch> > matches; |
||||
|
||||
/* require knn match */ |
||||
bdm->knnMatch( descr1, descr2, matches, 6 ); |
||||
|
||||
} |
||||
|
||||
|
@ -0,0 +1,124 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Biagio Montesano, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include <opencv2/line_descriptor.hpp> |
||||
|
||||
#include "opencv2/core/utility.hpp" |
||||
#include "opencv2/core/private.hpp" |
||||
#include <opencv2/imgproc.hpp> |
||||
#include <opencv2/features2d.hpp> |
||||
#include <opencv2/highgui.hpp> |
||||
|
||||
#include <iostream> |
||||
|
||||
using namespace cv; |
||||
using namespace cv::line_descriptor; |
||||
using namespace std; |
||||
|
||||
static const char* keys = |
||||
{ "{@image_path | | Image path }" }; |
||||
|
||||
static void help() |
||||
{ |
||||
cout << "\nThis example shows the functionalities of lines extraction " << "furnished by BinaryDescriptor class\n" |
||||
<< "Please, run this sample using a command in the form\n" << "./example_line_descriptor_lines_extraction <path_to_input_image>" << endl; |
||||
} |
||||
|
||||
int main( int argc, char** argv ) |
||||
{ |
||||
/* get parameters from comand line */ |
||||
CommandLineParser parser( argc, argv, keys ); |
||||
String image_path = parser.get<String>( 0 ); |
||||
|
||||
if( image_path.empty() ) |
||||
{ |
||||
help(); |
||||
return -1; |
||||
} |
||||
|
||||
/* load image */ |
||||
cv::Mat imageMat = imread( image_path, 1 ); |
||||
if( imageMat.data == NULL ) |
||||
{ |
||||
std::cout << "Error, image could not be loaded. Please, check its path" << std::endl; |
||||
return -1; |
||||
} |
||||
|
||||
/* create a random binary mask */ |
||||
cv::Mat mask = Mat::ones( imageMat.size(), CV_8UC1 ); |
||||
|
||||
/* create a pointer to a BinaryDescriptor object with deafult parameters */ |
||||
Ptr<BinaryDescriptor> bd = BinaryDescriptor::createBinaryDescriptor(); |
||||
|
||||
/* create a structure to store extracted lines */ |
||||
vector<KeyLine> lines; |
||||
|
||||
/* extract lines */ |
||||
cv::Mat output = imageMat.clone(); |
||||
bd->detect( imageMat, lines, mask ); |
||||
|
||||
/* draw lines extracted from octave 0 */ |
||||
if( output.channels() == 1 ) |
||||
cvtColor( output, output, COLOR_GRAY2BGR ); |
||||
for ( size_t i = 0; i < lines.size(); i++ ) |
||||
{ |
||||
KeyLine kl = lines[i]; |
||||
if( kl.octave == 0) |
||||
{ |
||||
/* get a random color */ |
||||
int R = ( rand() % (int) ( 255 + 1 ) ); |
||||
int G = ( rand() % (int) ( 255 + 1 ) ); |
||||
int B = ( rand() % (int) ( 255 + 1 ) ); |
||||
|
||||
/* get extremes of line */ |
||||
Point pt1 = Point2f( kl.startPointX, kl.startPointY ); |
||||
Point pt2 = Point2f( kl.endPointX, kl.endPointY ); |
||||
|
||||
/* draw line */ |
||||
line( output, pt1, pt2, Scalar( B, G, R ), 3 ); |
||||
} |
||||
|
||||
} |
||||
|
||||
/* show lines on image */ |
||||
imshow( "Lines", output ); |
||||
waitKey(); |
||||
} |
@ -0,0 +1,124 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Biagio Montesano, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include <opencv2/line_descriptor.hpp> |
||||
|
||||
#include "opencv2/core/utility.hpp" |
||||
#include "opencv2/core/private.hpp" |
||||
#include <opencv2/imgproc.hpp> |
||||
#include <opencv2/features2d.hpp> |
||||
#include <opencv2/highgui.hpp> |
||||
|
||||
#include <iostream> |
||||
|
||||
using namespace cv; |
||||
using namespace cv::line_descriptor; |
||||
using namespace std; |
||||
|
||||
static const char* keys = |
||||
{ "{@image_path | | Image path }" }; |
||||
|
||||
static void help() |
||||
{ |
||||
cout << "\nThis example shows the functionalities of lines extraction " << "furnished by BinaryDescriptor class\n" |
||||
<< "Please, run this sample using a command in the form\n" << "./example_line_descriptor_lines_extraction <path_to_input_image>" << endl; |
||||
} |
||||
|
||||
int main( int argc, char** argv ) |
||||
{ |
||||
/* get parameters from comand line */ |
||||
CommandLineParser parser( argc, argv, keys ); |
||||
String image_path = parser.get<String>( 0 ); |
||||
|
||||
if( image_path.empty() ) |
||||
{ |
||||
help(); |
||||
return -1; |
||||
} |
||||
|
||||
/* load image */ |
||||
cv::Mat imageMat = imread( image_path, 1 ); |
||||
if( imageMat.data == NULL ) |
||||
{ |
||||
std::cout << "Error, image could not be loaded. Please, check its path" << std::endl; |
||||
return -1; |
||||
} |
||||
|
||||
/* create a random binary mask */ |
||||
cv::Mat mask = Mat::ones( imageMat.size(), CV_8UC1 ); |
||||
|
||||
/* create a pointer to a BinaryDescriptor object with deafult parameters */ |
||||
Ptr<LSDDetector> bd = LSDDetector::createLSDDetector(); |
||||
|
||||
/* create a structure to store extracted lines */ |
||||
vector<KeyLine> lines; |
||||
|
||||
/* extract lines */ |
||||
cv::Mat output = imageMat.clone(); |
||||
bd->detect( imageMat, lines, 2, 1, mask ); |
||||
|
||||
/* draw lines extracted from octave 0 */ |
||||
if( output.channels() == 1 ) |
||||
cvtColor( output, output, COLOR_GRAY2BGR ); |
||||
for ( size_t i = 0; i < lines.size(); i++ ) |
||||
{ |
||||
KeyLine kl = lines[i]; |
||||
if( kl.octave == 0) |
||||
{ |
||||
/* get a random color */ |
||||
int R = ( rand() % (int) ( 255 + 1 ) ); |
||||
int G = ( rand() % (int) ( 255 + 1 ) ); |
||||
int B = ( rand() % (int) ( 255 + 1 ) ); |
||||
|
||||
/* get extremes of line */ |
||||
Point pt1 = Point2f( kl.startPointX, kl.startPointY ); |
||||
Point pt2 = Point2f( kl.endPointX, kl.endPointY ); |
||||
|
||||
/* draw line */ |
||||
line( output, pt1, pt2, Scalar( B, G, R ), 3 ); |
||||
} |
||||
|
||||
} |
||||
|
||||
/* show lines on image */ |
||||
imshow( "LSD lines", output ); |
||||
waitKey(); |
||||
} |
@ -0,0 +1,210 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Biagio Montesano, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include <opencv2/line_descriptor.hpp> |
||||
|
||||
#include "opencv2/core/utility.hpp" |
||||
#include "opencv2/core/private.hpp" |
||||
#include <opencv2/imgproc.hpp> |
||||
#include <opencv2/features2d.hpp> |
||||
#include <opencv2/highgui.hpp> |
||||
|
||||
#include <iostream> |
||||
|
||||
#define MATCHES_DIST_THRESHOLD 25 |
||||
|
||||
using namespace cv; |
||||
using namespace cv::line_descriptor; |
||||
|
||||
static const char* keys = |
||||
{ "{@image_path1 | | Image path 1 }" |
||||
"{@image_path2 | | Image path 2 }" }; |
||||
|
||||
static void help() |
||||
{ |
||||
std::cout << "\nThis example shows the functionalities of lines extraction " << "and descriptors computation furnished by BinaryDescriptor class\n" |
||||
<< "Please, run this sample using a command in the form\n" << "./example_line_descriptor_compute_descriptors <path_to_input_image 1>" |
||||
<< "<path_to_input_image 2>" << std::endl; |
||||
|
||||
} |
||||
|
||||
int main( int argc, char** argv ) |
||||
{ |
||||
/* get parameters from command line */ |
||||
CommandLineParser parser( argc, argv, keys ); |
||||
String image_path1 = parser.get<String>( 0 ); |
||||
String image_path2 = parser.get<String>( 1 ); |
||||
|
||||
if( image_path1.empty() || image_path2.empty() ) |
||||
{ |
||||
help(); |
||||
return -1; |
||||
} |
||||
|
||||
/* load image */ |
||||
cv::Mat imageMat1 = imread( image_path1, 1 ); |
||||
cv::Mat imageMat2 = imread( image_path2, 1 ); |
||||
|
||||
if( imageMat1.data == NULL || imageMat2.data == NULL ) |
||||
{ |
||||
std::cout << "Error, images could not be loaded. Please, check their path" << std::endl; |
||||
} |
||||
|
||||
/* create binary masks */ |
||||
cv::Mat mask1 = Mat::ones( imageMat1.size(), CV_8UC1 ); |
||||
cv::Mat mask2 = Mat::ones( imageMat2.size(), CV_8UC1 ); |
||||
|
||||
/* create a pointer to a BinaryDescriptor object with default parameters */ |
||||
Ptr<BinaryDescriptor> bd = BinaryDescriptor::createBinaryDescriptor( ); |
||||
|
||||
/* compute lines and descriptors */ |
||||
std::vector<KeyLine> keylines1, keylines2; |
||||
cv::Mat descr1, descr2; |
||||
|
||||
( *bd )( imageMat1, mask1, keylines1, descr1, false, false ); |
||||
( *bd )( imageMat2, mask2, keylines2, descr2, false, false ); |
||||
|
||||
/* select keylines from first octave and their descriptors */ |
||||
std::vector<KeyLine> lbd_octave1, lbd_octave2; |
||||
Mat left_lbd, right_lbd; |
||||
for ( int i = 0; i < (int) keylines1.size(); i++ ) |
||||
{ |
||||
if( keylines1[i].octave == 0 ) |
||||
{ |
||||
lbd_octave1.push_back( keylines1[i] ); |
||||
left_lbd.push_back( descr1.row( i ) ); |
||||
} |
||||
} |
||||
|
||||
for ( int j = 0; j < (int) keylines2.size(); j++ ) |
||||
{ |
||||
if( keylines2[j].octave == 0 ) |
||||
{ |
||||
lbd_octave2.push_back( keylines2[j] ); |
||||
right_lbd.push_back( descr2.row( j ) ); |
||||
} |
||||
} |
||||
|
||||
/* create a BinaryDescriptorMatcher object */ |
||||
Ptr<BinaryDescriptorMatcher> bdm = BinaryDescriptorMatcher::createBinaryDescriptorMatcher(); |
||||
|
||||
/* require match */ |
||||
std::vector<DMatch> matches; |
||||
bdm->match( left_lbd, right_lbd, matches ); |
||||
|
||||
/* select best matches */ |
||||
std::vector<DMatch> good_matches; |
||||
for ( int i = 0; i < (int) matches.size(); i++ ) |
||||
{ |
||||
if( matches[i].distance < MATCHES_DIST_THRESHOLD ) |
||||
good_matches.push_back( matches[i] ); |
||||
} |
||||
|
||||
/* plot matches */ |
||||
cv::Mat outImg; |
||||
cv::Mat scaled1, scaled2; |
||||
std::vector<char> mask( matches.size(), 1 ); |
||||
drawLineMatches( imageMat1, lbd_octave1, imageMat2, lbd_octave2, good_matches, outImg, Scalar::all( -1 ), Scalar::all( -1 ), mask, |
||||
DrawLinesMatchesFlags::DEFAULT ); |
||||
|
||||
imshow( "Matches", outImg ); |
||||
waitKey(); |
||||
imwrite("/home/ubisum/Desktop/images/env_match/matches.jpg", outImg); |
||||
/* create an LSD detector */ |
||||
Ptr<LSDDetector> lsd = LSDDetector::createLSDDetector(); |
||||
|
||||
/* detect lines */ |
||||
std::vector<KeyLine> klsd1, klsd2; |
||||
Mat lsd_descr1, lsd_descr2; |
||||
lsd->detect( imageMat1, klsd1, 2, 2, mask1 ); |
||||
lsd->detect( imageMat2, klsd2, 2, 2, mask2 ); |
||||
|
||||
/* compute descriptors for lines from first octave */ |
||||
bd->compute( imageMat1, klsd1, lsd_descr1 ); |
||||
bd->compute( imageMat2, klsd2, lsd_descr2 ); |
||||
|
||||
/* select lines and descriptors from first octave */ |
||||
std::vector<KeyLine> octave0_1, octave0_2; |
||||
Mat leftDEscr, rightDescr; |
||||
for ( int i = 0; i < (int) klsd1.size(); i++ ) |
||||
{ |
||||
if( klsd1[i].octave == 1 ) |
||||
{ |
||||
octave0_1.push_back( klsd1[i] ); |
||||
leftDEscr.push_back( lsd_descr1.row( i ) ); |
||||
} |
||||
} |
||||
|
||||
for ( int j = 0; j < (int) klsd2.size(); j++ ) |
||||
{ |
||||
if( klsd2[j].octave == 1 ) |
||||
{ |
||||
octave0_2.push_back( klsd2[j] ); |
||||
rightDescr.push_back( lsd_descr2.row( j ) ); |
||||
} |
||||
} |
||||
|
||||
/* compute matches */ |
||||
std::vector<DMatch> lsd_matches; |
||||
bdm->match( leftDEscr, rightDescr, lsd_matches ); |
||||
|
||||
/* select best matches */ |
||||
good_matches.clear(); |
||||
for ( int i = 0; i < (int) lsd_matches.size(); i++ ) |
||||
{ |
||||
if( lsd_matches[i].distance < MATCHES_DIST_THRESHOLD ) |
||||
good_matches.push_back( lsd_matches[i] ); |
||||
} |
||||
|
||||
/* plot matches */ |
||||
cv::Mat lsd_outImg; |
||||
resize( imageMat1, imageMat1, Size( imageMat1.cols / 2, imageMat1.rows / 2 ) ); |
||||
resize( imageMat2, imageMat2, Size( imageMat2.cols / 2, imageMat2.rows / 2 ) ); |
||||
std::vector<char> lsd_mask( matches.size(), 1 ); |
||||
drawLineMatches( imageMat1, octave0_1, imageMat2, octave0_2, good_matches, lsd_outImg, Scalar::all( -1 ), Scalar::all( -1 ), lsd_mask, |
||||
DrawLinesMatchesFlags::DEFAULT ); |
||||
|
||||
imshow( "LSD matches", lsd_outImg ); |
||||
waitKey(); |
||||
|
||||
|
||||
} |
||||
|
@ -0,0 +1,143 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Biagio Montesano, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include <opencv2/line_descriptor.hpp> |
||||
|
||||
#include "opencv2/core/utility.hpp" |
||||
#include "opencv2/core/private.hpp" |
||||
#include <opencv2/imgproc.hpp> |
||||
#include <opencv2/features2d.hpp> |
||||
#include <opencv2/highgui.hpp> |
||||
|
||||
#include <iostream> |
||||
#include <vector> |
||||
|
||||
using namespace cv; |
||||
using namespace cv::line_descriptor; |
||||
|
||||
static const std::string images[] = |
||||
{ "cameraman.jpg", "church.jpg", "church2.png", "einstein.jpg", "stuff.jpg" }; |
||||
|
||||
static const char* keys = |
||||
{ "{@image_path | | Image path }" }; |
||||
|
||||
static void help() |
||||
{ |
||||
std::cout << "\nThis example shows the functionalities of radius matching " << "Please, run this sample using a command in the form\n" |
||||
<< "./example_line_descriptor_radius_matching <path_to_input_images>/" << std::endl; |
||||
} |
||||
|
||||
int main( int argc, char** argv ) |
||||
{ |
||||
/* get parameters from comand line */ |
||||
CommandLineParser parser( argc, argv, keys ); |
||||
String pathToImages = parser.get < String > ( 0 ); |
||||
|
||||
/* create structures for hosting KeyLines and descriptors */ |
||||
int num_elements = sizeof ( images ) / sizeof ( images[0] ); |
||||
std::vector < Mat > descriptorsMat; |
||||
std::vector < std::vector<KeyLine> > linesMat; |
||||
|
||||
/*create a pointer to a BinaryDescriptor object */ |
||||
Ptr < BinaryDescriptor > bd = BinaryDescriptor::createBinaryDescriptor(); |
||||
|
||||
/* compute lines and descriptors */ |
||||
for ( int i = 0; i < num_elements; i++ ) |
||||
{ |
||||
/* get path to image */ |
||||
std::stringstream image_path; |
||||
image_path << pathToImages << images[i]; |
||||
std::cout << image_path.str().c_str() << std::endl; |
||||
|
||||
/* load image */ |
||||
Mat loadedImage = imread( image_path.str().c_str(), 1 ); |
||||
if( loadedImage.data == NULL ) |
||||
{ |
||||
std::cout << "Could not load images." << std::endl; |
||||
help(); |
||||
exit( -1 ); |
||||
} |
||||
|
||||
/* compute lines and descriptors */ |
||||
std::vector < KeyLine > lines; |
||||
Mat computedDescr; |
||||
bd->detect( loadedImage, lines ); |
||||
bd->compute( loadedImage, lines, computedDescr ); |
||||
|
||||
descriptorsMat.push_back( computedDescr ); |
||||
linesMat.push_back( lines ); |
||||
|
||||
} |
||||
|
||||
/* compose a queries matrix */ |
||||
Mat queries; |
||||
for ( size_t j = 0; j < descriptorsMat.size(); j++ ) |
||||
{ |
||||
if( descriptorsMat[j].rows >= 5 ) |
||||
queries.push_back( descriptorsMat[j].rowRange( 0, 5 ) ); |
||||
|
||||
else if( descriptorsMat[j].rows > 0 && descriptorsMat[j].rows < 5 ) |
||||
queries.push_back( descriptorsMat[j] ); |
||||
} |
||||
|
||||
std::cout << "It has been generated a matrix of " << queries.rows << " descriptors" << std::endl; |
||||
|
||||
/* create a BinaryDescriptorMatcher object */ |
||||
Ptr < BinaryDescriptorMatcher > bdm = BinaryDescriptorMatcher::createBinaryDescriptorMatcher(); |
||||
|
||||
/* populate matcher */ |
||||
bdm->add( descriptorsMat ); |
||||
|
||||
/* compute matches */ |
||||
std::vector < std::vector<DMatch> > matches; |
||||
bdm->radiusMatch( queries, matches, 30 ); |
||||
std::cout << "size matches sample " << matches.size() << std::endl; |
||||
|
||||
for ( int i = 0; i < (int) matches.size(); i++ ) |
||||
{ |
||||
for ( int j = 0; j < (int) matches[i].size(); j++ ) |
||||
{ |
||||
std::cout << "match: " << matches[i][j].queryIdx << " " << matches[i][j].trainIdx << " " << matches[i][j].distance << std::endl; |
||||
} |
||||
|
||||
} |
||||
|
||||
} |
@ -0,0 +1,213 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Biagio Montesano, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp" |
||||
|
||||
//using namespace cv;
|
||||
namespace cv |
||||
{ |
||||
namespace line_descriptor |
||||
{ |
||||
Ptr<LSDDetector> LSDDetector::createLSDDetector() |
||||
{ |
||||
return Ptr<LSDDetector>( new LSDDetector() ); |
||||
} |
||||
|
||||
/* compute Gaussian pyramid of input image */ |
||||
void LSDDetector::computeGaussianPyramid( const Mat& image, int numOctaves, int scale ) |
||||
{ |
||||
/* clear class fields */ |
||||
gaussianPyrs.clear(); |
||||
|
||||
/* insert input image into pyramid */ |
||||
cv::Mat currentMat = image.clone(); |
||||
//cv::GaussianBlur( currentMat, currentMat, cv::Size( 5, 5 ), 1 );
|
||||
gaussianPyrs.push_back( currentMat ); |
||||
|
||||
/* fill Gaussian pyramid */ |
||||
for ( int pyrCounter = 1; pyrCounter < numOctaves; pyrCounter++ ) |
||||
{ |
||||
/* compute and store next image in pyramid and its size */ |
||||
pyrDown( currentMat, currentMat, Size( currentMat.cols / scale, currentMat.rows / scale ) ); |
||||
gaussianPyrs.push_back( currentMat ); |
||||
} |
||||
} |
||||
|
||||
/* check lines' extremes */ |
||||
inline void checkLineExtremes( cv::Vec4i& extremes, cv::Size imageSize ) |
||||
{ |
||||
|
||||
if( extremes[0] < 0 ) |
||||
extremes[0] = 0; |
||||
|
||||
if( extremes[0] >= imageSize.width ) |
||||
extremes[0] = imageSize.width - 1; |
||||
|
||||
if( extremes[2] < 0 ) |
||||
extremes[2] = 0; |
||||
|
||||
if( extremes[2] >= imageSize.width ) |
||||
extremes[2] = imageSize.width - 1; |
||||
|
||||
if( extremes[1] < 0 ) |
||||
extremes[1] = 0; |
||||
|
||||
if( extremes[1] >= imageSize.height ) |
||||
extremes[1] = imageSize.height - 1; |
||||
|
||||
if( extremes[3] < 0 ) |
||||
extremes[3] = 0; |
||||
|
||||
if( extremes[3] >= imageSize.height ) |
||||
extremes[3] = imageSize.height - 1; |
||||
} |
||||
|
||||
/* requires line detection (only one image) */ |
||||
void LSDDetector::detect( const Mat& image, CV_OUT std::vector<KeyLine>& keylines, int scale, int numOctaves, const Mat& mask ) |
||||
{ |
||||
if( mask.data != NULL && ( mask.size() != image.size() || mask.type() != CV_8UC1 ) ) |
||||
throw std::runtime_error( "Mask error while detecting lines: please check its dimensions and that data type is CV_8UC1" ); |
||||
|
||||
else |
||||
detectImpl( image, keylines, numOctaves, scale, mask ); |
||||
} |
||||
|
||||
/* requires line detection (more than one image) */ |
||||
void LSDDetector::detect( const std::vector<Mat>& images, std::vector<std::vector<KeyLine> >& keylines, int scale, int numOctaves, |
||||
const std::vector<Mat>& masks ) const |
||||
{ |
||||
/* detect lines from each image */ |
||||
for ( size_t counter = 0; counter < images.size(); counter++ ) |
||||
{ |
||||
if( masks[counter].data != NULL && ( masks[counter].size() != images[counter].size() || masks[counter].type() != CV_8UC1 ) ) |
||||
throw std::runtime_error( "Masks error while detecting lines: please check their dimensions and that data types are CV_8UC1" ); |
||||
|
||||
else |
||||
detectImpl( images[counter], keylines[counter], numOctaves, scale, masks[counter] ); |
||||
} |
||||
} |
||||
|
||||
/* implementation of line detection */ |
||||
void LSDDetector::detectImpl( const Mat& imageSrc, std::vector<KeyLine>& keylines, int numOctaves, int scale, const Mat& mask ) const |
||||
{ |
||||
cv::Mat image; |
||||
if( imageSrc.channels() != 1 ) |
||||
cvtColor( imageSrc, image, COLOR_BGR2GRAY ); |
||||
else |
||||
image = imageSrc.clone(); |
||||
|
||||
/*check whether image depth is different from 0 */ |
||||
if( image.depth() != 0 ) |
||||
throw std::runtime_error( "Error, depth image!= 0" ); |
||||
|
||||
/* create a pointer to self */ |
||||
LSDDetector *lsd = const_cast<LSDDetector*>( this ); |
||||
|
||||
/* compute Gaussian pyramids */ |
||||
lsd->computeGaussianPyramid( image, numOctaves, scale ); |
||||
|
||||
/* create an LSD extractor */ |
||||
cv::Ptr<cv::LineSegmentDetector> ls = cv::createLineSegmentDetector( cv::LSD_REFINE_ADV ); |
||||
|
||||
/* prepare a vector to host extracted segments */ |
||||
std::vector<std::vector<cv::Vec4i> > lines_lsd; |
||||
|
||||
/* extract lines */ |
||||
for ( int i = 0; i < numOctaves; i++ ) |
||||
{ |
||||
std::vector<Vec4i> octave_lines; |
||||
ls->detect( gaussianPyrs[i], octave_lines ); |
||||
lines_lsd.push_back( octave_lines ); |
||||
} |
||||
|
||||
/* create keylines */ |
||||
int class_counter = -1; |
||||
for ( int j = 0; j < (int) lines_lsd.size(); j++ ) |
||||
{ |
||||
for ( int k = 0; k < (int) lines_lsd[j].size(); k++ ) |
||||
{ |
||||
KeyLine kl; |
||||
cv::Vec4i extremes = lines_lsd[j][k]; |
||||
|
||||
/* check data validity */ |
||||
checkLineExtremes( extremes, gaussianPyrs[j].size() ); |
||||
|
||||
/* fill KeyLine's fields */ |
||||
kl.startPointX = (float) extremes[0]; |
||||
kl.startPointY = (float) extremes[1]; |
||||
kl.endPointX = (float) extremes[2]; |
||||
kl.endPointY = (float) extremes[3]; |
||||
kl.sPointInOctaveX = (float) extremes[0]; |
||||
kl.sPointInOctaveY = (float) extremes[1]; |
||||
kl.ePointInOctaveX = (float) extremes[2]; |
||||
kl.ePointInOctaveY = (float) extremes[3]; |
||||
kl.lineLength = (float) sqrt( pow( extremes[0] - extremes[2], 2 ) + pow( extremes[1] - extremes[3], 2 ) ); |
||||
|
||||
/* compute number of pixels covered by line */ |
||||
LineIterator li( gaussianPyrs[j], Point( extremes[0], extremes[1] ), Point( extremes[2], extremes[3] ) ); |
||||
kl.numOfPixels = li.count; |
||||
|
||||
kl.angle = atan2( ( kl.endPointY - kl.startPointY ), ( kl.endPointX - kl.startPointX ) ); |
||||
kl.class_id = ++class_counter; |
||||
kl.octave = j; |
||||
kl.size = ( kl.endPointX - kl.startPointX ) * ( kl.endPointY - kl.startPointY ); |
||||
kl.response = kl.lineLength / max( gaussianPyrs[j].cols, gaussianPyrs[j].rows ); |
||||
kl.pt = Point2f( ( kl.endPointX + kl.startPointX ) / 2, ( kl.endPointY + kl.startPointY ) / 2 ); |
||||
|
||||
keylines.push_back( kl ); |
||||
} |
||||
} |
||||
|
||||
/* delete undesired KeyLines, according to input mask */ |
||||
if( !mask.empty() ) |
||||
{ |
||||
for ( size_t keyCounter = 0; keyCounter < keylines.size(); keyCounter++ ) |
||||
{ |
||||
KeyLine kl = keylines[keyCounter]; |
||||
if( mask.at<uchar>( (int) kl.startPointY, (int) kl.startPointX ) == 0 && mask.at<uchar>( (int) kl.endPointY, (int) kl.endPointX ) == 0 ) |
||||
keylines.erase( keylines.begin() + keyCounter ); |
||||
} |
||||
} |
||||
|
||||
} |
||||
} |
||||
} |
||||
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,971 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Biagio Montesano, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp" |
||||
|
||||
#define MAX_B 37 |
||||
double ARRAY_RESIZE_FACTOR = 1.1; // minimum is 1.0
|
||||
double ARRAY_RESIZE_ADD_FACTOR = 4; // minimum is 1
|
||||
|
||||
//using namespace cv;
|
||||
namespace cv |
||||
{ |
||||
namespace line_descriptor |
||||
{ |
||||
|
||||
/* constructor */ |
||||
BinaryDescriptorMatcher::BinaryDescriptorMatcher() |
||||
{ |
||||
dataset = new Mihasher( 256, 32 ); |
||||
nextAddedIndex = 0; |
||||
numImages = 0; |
||||
descrInDS = 0; |
||||
} |
||||
|
||||
/* constructor with smart pointer */ |
||||
Ptr<BinaryDescriptorMatcher> BinaryDescriptorMatcher::createBinaryDescriptorMatcher() |
||||
{ |
||||
return Ptr < BinaryDescriptorMatcher > ( new BinaryDescriptorMatcher() ); |
||||
} |
||||
|
||||
/* store new descriptors to be inserted in dataset */ |
||||
void BinaryDescriptorMatcher::add( const std::vector<Mat>& descriptors ) |
||||
{ |
||||
for ( size_t i = 0; i < descriptors.size(); i++ ) |
||||
{ |
||||
descriptorsMat.push_back( descriptors[i] ); |
||||
|
||||
indexesMap.insert( std::pair<int, int>( nextAddedIndex, numImages ) ); |
||||
nextAddedIndex += descriptors[i].rows; |
||||
numImages++; |
||||
} |
||||
} |
||||
|
||||
/* store new descriptors into dataset */ |
||||
void BinaryDescriptorMatcher::train() |
||||
{ |
||||
if( !dataset ) |
||||
dataset = new Mihasher( 256, 32 ); |
||||
|
||||
if( descriptorsMat.rows > 0 ) |
||||
dataset->populate( descriptorsMat, descriptorsMat.rows, descriptorsMat.cols ); |
||||
|
||||
descrInDS = descriptorsMat.rows; |
||||
descriptorsMat.release(); |
||||
} |
||||
|
||||
/* clear dataset and internal data */ |
||||
void BinaryDescriptorMatcher::clear() |
||||
{ |
||||
descriptorsMat.release(); |
||||
indexesMap.clear(); |
||||
dataset = 0; |
||||
nextAddedIndex = 0; |
||||
numImages = 0; |
||||
descrInDS = 0; |
||||
} |
||||
|
||||
/* retrieve Hamming distances */ |
||||
void BinaryDescriptorMatcher::checkKDistances( UINT32 * numres, int k, std::vector<int> & k_distances, int row, int string_length ) const |
||||
{ |
||||
int k_to_found = k; |
||||
|
||||
UINT32 * numres_tmp = numres + ( ( string_length + 1 ) * row ); |
||||
for ( int j = 0; j < ( string_length + 1 ) && k_to_found > 0; j++ ) |
||||
{ |
||||
if( ( * ( numres_tmp + j ) ) > 0 ) |
||||
{ |
||||
for ( int i = 0; i < (int) ( * ( numres_tmp + j ) ) && k_to_found > 0; i++ ) |
||||
{ |
||||
k_distances.push_back( j ); |
||||
k_to_found--; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
/* for every input descriptor,
|
||||
find the best matching one (from one image to a set) */ |
||||
void BinaryDescriptorMatcher::match( const Mat& queryDescriptors, std::vector<DMatch>& matches, const std::vector<Mat>& masks ) |
||||
{ |
||||
/* check data validity */ |
||||
if( queryDescriptors.rows == 0 ) |
||||
{ |
||||
std::cout << "Error: query descriptors'matrix is empty" << std::endl; |
||||
return; |
||||
} |
||||
|
||||
if( masks.size() != 0 && (int) masks.size() != numImages ) |
||||
{ |
||||
std::cout << "Error: the number of images in dataset is " << numImages << " but match function received " << masks.size() |
||||
<< " masks. Program will be terminated" << std::endl; |
||||
|
||||
return; |
||||
} |
||||
|
||||
/* add new descriptors to dataset, if needed */ |
||||
train(); |
||||
|
||||
/* set number of requested matches to return for each query */ |
||||
dataset->setK( 1 ); |
||||
|
||||
/* prepare structures for query */ |
||||
UINT32 *results = new UINT32[queryDescriptors.rows]; |
||||
UINT32 * numres = new UINT32[ ( 256 + 1 ) * ( queryDescriptors.rows )]; |
||||
|
||||
/* execute query */ |
||||
dataset->batchquery( results, numres, queryDescriptors, queryDescriptors.rows, queryDescriptors.cols ); |
||||
/* compose matches */ |
||||
for ( int counter = 0; counter < queryDescriptors.rows; counter++ ) |
||||
{ |
||||
/* create a map iterator */ |
||||
std::map<int, int>::iterator itup; |
||||
|
||||
/* get info about original image of each returned descriptor */ |
||||
itup = indexesMap.upper_bound( results[counter] - 1 ); |
||||
itup--; |
||||
/* data validity check */ |
||||
if( !masks.empty() && ( masks[itup->second].rows != queryDescriptors.rows || masks[itup->second].cols != 1 ) ) |
||||
{ |
||||
std::stringstream ss; |
||||
ss << "Error: mask " << itup->second << " in knnMatch function " << "should have " << queryDescriptors.rows << " and " |
||||
<< "1 column. Program will be terminated"; |
||||
//throw std::runtime_error( ss.str() );
|
||||
} |
||||
/* create a DMatch object if required by mask or if there is
|
||||
no mask at all */ |
||||
else if( masks.empty() || masks[itup->second].at < uchar > ( counter ) != 0 ) |
||||
{ |
||||
std::vector<int> k_distances; |
||||
checkKDistances( numres, 1, k_distances, counter, 256 ); |
||||
|
||||
DMatch dm; |
||||
dm.queryIdx = counter; |
||||
dm.trainIdx = results[counter] - 1; |
||||
dm.imgIdx = itup->second; |
||||
dm.distance = (float) k_distances[0]; |
||||
|
||||
matches.push_back( dm ); |
||||
} |
||||
|
||||
} |
||||
|
||||
/* delete data */ |
||||
delete results; |
||||
delete numres; |
||||
} |
||||
|
||||
/* for every input descriptor, find the best matching one (for a pair of images) */ |
||||
void BinaryDescriptorMatcher::match( const Mat& queryDescriptors, const Mat& trainDescriptors, std::vector<DMatch>& matches, const Mat& mask ) const |
||||
{ |
||||
|
||||
/* check data validity */ |
||||
if( queryDescriptors.rows == 0 || trainDescriptors.rows == 0 ) |
||||
{ |
||||
std::cout << "Error: descriptors matrices cannot be void" << std::endl; |
||||
return; |
||||
} |
||||
|
||||
if( !mask.empty() && ( mask.rows != queryDescriptors.rows && mask.cols != 1 ) ) |
||||
{ |
||||
std::cout << "Error: input mask should have " << queryDescriptors.rows << " rows and 1 column. " << "Program will be terminated" << std::endl; |
||||
|
||||
return; |
||||
} |
||||
|
||||
/* create a new mihasher object */ |
||||
Mihasher *mh = new Mihasher( 256, 32 ); |
||||
|
||||
/* populate mihasher */ |
||||
cv::Mat copy = trainDescriptors.clone(); |
||||
mh->populate( copy, copy.rows, copy.cols ); |
||||
mh->setK( 1 ); |
||||
|
||||
/* prepare structures for query */ |
||||
UINT32 *results = new UINT32[queryDescriptors.rows]; |
||||
UINT32 * numres = new UINT32[ ( 256 + 1 ) * ( queryDescriptors.rows )]; |
||||
|
||||
/* execute query */ |
||||
mh->batchquery( results, numres, queryDescriptors, queryDescriptors.rows, queryDescriptors.cols ); |
||||
|
||||
/* compose matches */ |
||||
for ( int counter = 0; counter < queryDescriptors.rows; counter++ ) |
||||
{ |
||||
/* create a DMatch object if required by mask or if there is
|
||||
no mask at all */ |
||||
if( mask.empty() || ( !mask.empty() && mask.at < uchar > ( counter ) != 0 ) ) |
||||
{ |
||||
std::vector<int> k_distances; |
||||
checkKDistances( numres, 1, k_distances, counter, 256 ); |
||||
|
||||
DMatch dm; |
||||
dm.queryIdx = counter; |
||||
dm.trainIdx = results[counter] - 1; |
||||
dm.imgIdx = 0; |
||||
dm.distance = (float) k_distances[0]; |
||||
|
||||
matches.push_back( dm ); |
||||
} |
||||
} |
||||
|
||||
/* delete data */ |
||||
delete mh; |
||||
delete results; |
||||
delete numres; |
||||
|
||||
} |
||||
|
||||
/* for every input descriptor,
|
||||
find the best k matching descriptors (for a pair of images) */ |
||||
void BinaryDescriptorMatcher::knnMatch( const Mat& queryDescriptors, const Mat& trainDescriptors, std::vector<std::vector<DMatch> >& matches, int k, |
||||
const Mat& mask, bool compactResult ) const |
||||
|
||||
{ |
||||
/* check data validity */ |
||||
if( queryDescriptors.rows == 0 || trainDescriptors.rows == 0 ) |
||||
{ |
||||
std::cout << "Error: descriptors matrices cannot be void" << std::endl; |
||||
return; |
||||
} |
||||
|
||||
if( !mask.empty() && ( mask.rows != queryDescriptors.rows || mask.cols != 1 ) ) |
||||
{ |
||||
std::cout << "Error: input mask should have " << queryDescriptors.rows << " rows and 1 column. " << "Program will be terminated" << std::endl; |
||||
|
||||
return; |
||||
} |
||||
|
||||
/* create a new mihasher object */ |
||||
Mihasher *mh = new Mihasher( 256, 32 ); |
||||
|
||||
/* populate mihasher */ |
||||
cv::Mat copy = trainDescriptors.clone(); |
||||
mh->populate( copy, copy.rows, copy.cols ); |
||||
|
||||
/* set K */ |
||||
mh->setK( k ); |
||||
|
||||
/* prepare structures for query */ |
||||
UINT32 *results = new UINT32[k * queryDescriptors.rows]; |
||||
UINT32 * numres = new UINT32[ ( 256 + 1 ) * ( queryDescriptors.rows )]; |
||||
|
||||
/* execute query */ |
||||
mh->batchquery( results, numres, queryDescriptors, queryDescriptors.rows, queryDescriptors.cols ); |
||||
|
||||
/* compose matches */ |
||||
int index = 0; |
||||
for ( int counter = 0; counter < queryDescriptors.rows; counter++ ) |
||||
{ |
||||
/* initialize a vector of matches */ |
||||
std::vector < DMatch > tempVec; |
||||
|
||||
/* chech whether query should be ignored */ |
||||
if( !mask.empty() && mask.at < uchar > ( counter ) == 0 ) |
||||
{ |
||||
/* if compact result is not requested, add an empty vector */ |
||||
if( !compactResult ) |
||||
matches.push_back( tempVec ); |
||||
} |
||||
|
||||
/* query matches must be considered */ |
||||
else |
||||
{ |
||||
std::vector<int> k_distances; |
||||
checkKDistances( numres, k, k_distances, counter, 256 ); |
||||
for ( int j = index; j < index + k; j++ ) |
||||
{ |
||||
DMatch dm; |
||||
dm.queryIdx = counter; |
||||
dm.trainIdx = results[j] - 1; |
||||
dm.imgIdx = 0; |
||||
dm.distance = (float) k_distances[j - index]; |
||||
|
||||
tempVec.push_back( dm ); |
||||
} |
||||
|
||||
matches.push_back( tempVec ); |
||||
} |
||||
|
||||
/* increment pointer */ |
||||
index += k; |
||||
} |
||||
|
||||
/* delete data */ |
||||
delete mh; |
||||
delete results; |
||||
delete numres; |
||||
} |
||||
|
||||
/* for every input descriptor,
|
||||
find the best k matching descriptors (from one image to a set) */ |
||||
void BinaryDescriptorMatcher::knnMatch( const Mat& queryDescriptors, std::vector<std::vector<DMatch> >& matches, int k, const std::vector<Mat>& masks, |
||||
bool compactResult ) |
||||
{ |
||||
|
||||
/* check data validity */ |
||||
if( queryDescriptors.rows == 0 ) |
||||
{ |
||||
std::cout << "Error: descriptors matrix cannot be void" << std::endl; |
||||
return; |
||||
} |
||||
|
||||
if( masks.size() != 0 && (int) masks.size() != numImages ) |
||||
{ |
||||
std::cout << "Error: the number of images in dataset is " << numImages << " but knnMatch function received " << masks.size() |
||||
<< " masks. Program will be terminated" << std::endl; |
||||
|
||||
return; |
||||
} |
||||
|
||||
/* add new descriptors to dataset, if needed */ |
||||
train(); |
||||
|
||||
/* set number of requested matches to return for each query */ |
||||
dataset->setK( k ); |
||||
|
||||
/* prepare structures for query */ |
||||
UINT32 *results = new UINT32[k * queryDescriptors.rows]; |
||||
UINT32 * numres = new UINT32[ ( 256 + 1 ) * ( queryDescriptors.rows )]; |
||||
|
||||
/* execute query */ |
||||
dataset->batchquery( results, numres, queryDescriptors, queryDescriptors.rows, queryDescriptors.cols ); |
||||
|
||||
/* compose matches */ |
||||
int index = 0; |
||||
for ( int counter = 0; counter < queryDescriptors.rows; counter++ ) |
||||
{ |
||||
/* create a void vector of matches */ |
||||
std::vector < DMatch > tempVector; |
||||
|
||||
/* loop over k results returned for every query */ |
||||
for ( int j = index; j < index + k; j++ ) |
||||
{ |
||||
/* retrieve which image returned index refers to */ |
||||
int currentIndex = results[j] - 1; |
||||
std::map<int, int>::iterator itup; |
||||
itup = indexesMap.upper_bound( currentIndex ); |
||||
itup--; |
||||
|
||||
/* data validity check */ |
||||
if( !masks.empty() && ( masks[itup->second].rows != queryDescriptors.rows || masks[itup->second].cols != 1 ) ) |
||||
{ |
||||
std::cout << "Error: mask " << itup->second << " in knnMatch function " << "should have " << queryDescriptors.rows << " and " |
||||
<< "1 column. Program will be terminated" << std::endl; |
||||
|
||||
return; |
||||
} |
||||
|
||||
/* decide if, according to relative mask, returned match should be
|
||||
considered */ |
||||
else if( masks.size() == 0 || masks[itup->second].at < uchar > ( counter ) != 0 ) |
||||
{ |
||||
std::vector<int> k_distances; |
||||
checkKDistances( numres, k, k_distances, counter, 256 ); |
||||
|
||||
DMatch dm; |
||||
dm.queryIdx = counter; |
||||
dm.trainIdx = results[j] - 1; |
||||
dm.imgIdx = itup->second; |
||||
dm.distance = (float) k_distances[j - index]; |
||||
|
||||
tempVector.push_back( dm ); |
||||
} |
||||
} |
||||
|
||||
/* decide whether temporary vector should be saved */ |
||||
if( ( tempVector.size() == 0 && !compactResult ) || tempVector.size() > 0 ) |
||||
matches.push_back( tempVector ); |
||||
|
||||
/* increment pointer */ |
||||
index += k; |
||||
} |
||||
|
||||
/* delete data */ |
||||
delete results; |
||||
delete numres; |
||||
} |
||||
|
||||
/* for every input desciptor, find all the ones falling in a
|
||||
certaing matching radius (for a pair of images) */ |
||||
void BinaryDescriptorMatcher::radiusMatch( const Mat& queryDescriptors, const Mat& trainDescriptors, std::vector<std::vector<DMatch> >& matches, |
||||
float maxDistance, const Mat& mask, bool compactResult ) const |
||||
|
||||
{ |
||||
|
||||
/* check data validity */ |
||||
if( queryDescriptors.rows == 0 || trainDescriptors.rows == 0 ) |
||||
{ |
||||
std::cout << "Error: descriptors matrices cannot be void" << std::endl; |
||||
return; |
||||
} |
||||
|
||||
if( !mask.empty() && ( mask.rows != queryDescriptors.rows && mask.cols != 1 ) ) |
||||
{ |
||||
std::cout << "Error: input mask should have " << queryDescriptors.rows << " rows and 1 column. " << "Program will be terminated" << std::endl; |
||||
|
||||
return; |
||||
} |
||||
|
||||
/* create a new Mihasher */ |
||||
Mihasher* mh = new Mihasher( 256, 32 ); |
||||
|
||||
/* populate Mihasher */ |
||||
//Mat copy = queryDescriptors.clone();
|
||||
Mat copy = trainDescriptors.clone(); |
||||
mh->populate( copy, copy.rows, copy.cols ); |
||||
|
||||
/* set K */ |
||||
mh->setK( trainDescriptors.rows ); |
||||
|
||||
/* prepare structures for query */ |
||||
UINT32 *results = new UINT32[trainDescriptors.rows * queryDescriptors.rows]; |
||||
UINT32 * numres = new UINT32[ ( 256 + 1 ) * ( queryDescriptors.rows )]; |
||||
|
||||
/* execute query */ |
||||
mh->batchquery( results, numres, queryDescriptors, queryDescriptors.rows, queryDescriptors.cols ); |
||||
|
||||
/* compose matches */ |
||||
int index = 0; |
||||
for ( int i = 0; i < queryDescriptors.rows; i++ ) |
||||
{ |
||||
std::vector<int> k_distances; |
||||
checkKDistances( numres, trainDescriptors.rows, k_distances, i, 256 ); |
||||
|
||||
std::vector < DMatch > tempVector; |
||||
for ( int j = index; j < index + trainDescriptors.rows; j++ ) |
||||
{ |
||||
// if( numres[j] <= maxDistance )
|
||||
if( k_distances[j - index] <= maxDistance ) |
||||
{ |
||||
if( mask.empty() || mask.at < uchar > ( i ) != 0 ) |
||||
{ |
||||
DMatch dm; |
||||
dm.queryIdx = i; |
||||
dm.trainIdx = (int) ( results[j] - 1 ); |
||||
dm.imgIdx = 0; |
||||
dm.distance = (float) k_distances[j - index]; |
||||
|
||||
tempVector.push_back( dm ); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/* decide whether temporary vector should be saved */ |
||||
if( ( tempVector.size() == 0 && !compactResult ) || tempVector.size() > 0 ) |
||||
matches.push_back( tempVector ); |
||||
|
||||
/* increment pointer */ |
||||
index += trainDescriptors.rows; |
||||
|
||||
} |
||||
|
||||
/* delete data */ |
||||
delete mh; |
||||
delete results; |
||||
delete numres; |
||||
} |
||||
|
||||
/* for every input descriptor, find all the ones falling in a
|
||||
certain matching radius (from one image to a set) */ |
||||
void BinaryDescriptorMatcher::radiusMatch( const Mat& queryDescriptors, std::vector<std::vector<DMatch> >& matches, float maxDistance, |
||||
const std::vector<Mat>& masks, bool compactResult ) |
||||
{ |
||||
|
||||
/* check data validity */ |
||||
if( queryDescriptors.rows == 0 ) |
||||
{ |
||||
std::cout << "Error: descriptors matrices cannot be void" << std::endl; |
||||
return; |
||||
} |
||||
|
||||
if( masks.size() != 0 && (int) masks.size() != numImages ) |
||||
{ |
||||
std::cout << "Error: the number of images in dataset is " << numImages << " but radiusMatch function received " << masks.size() |
||||
<< " masks. Program will be terminated" << std::endl; |
||||
|
||||
return; |
||||
} |
||||
|
||||
/* populate dataset */ |
||||
train(); |
||||
|
||||
/* set K */ |
||||
dataset->setK( descrInDS ); |
||||
|
||||
/* prepare structures for query */ |
||||
UINT32 *results = new UINT32[descrInDS * queryDescriptors.rows]; |
||||
UINT32 * numres = new UINT32[ ( 256 + 1 ) * ( queryDescriptors.rows )]; |
||||
|
||||
/* execute query */ |
||||
dataset->batchquery( results, numres, queryDescriptors, queryDescriptors.rows, queryDescriptors.cols ); |
||||
|
||||
/* compose matches */ |
||||
int index = 0; |
||||
for ( int counter = 0; counter < queryDescriptors.rows; counter++ ) |
||||
{ |
||||
std::vector < DMatch > tempVector; |
||||
for ( int j = index; j < index + descrInDS; j++ ) |
||||
{ |
||||
std::vector<int> k_distances; |
||||
checkKDistances( numres, descrInDS, k_distances, counter, 256 ); |
||||
|
||||
if( k_distances[j - index] <= maxDistance ) |
||||
{ |
||||
int currentIndex = results[j] - 1; |
||||
std::map<int, int>::iterator itup; |
||||
itup = indexesMap.upper_bound( currentIndex ); |
||||
itup--; |
||||
|
||||
/* data validity check */ |
||||
if( !masks.empty() && ( masks[itup->second].rows != queryDescriptors.rows || masks[itup->second].cols != 1 ) ) |
||||
{ |
||||
std::cout << "Error: mask " << itup->second << " in radiusMatch function " << "should have " << queryDescriptors.rows << " and " |
||||
<< "1 column. Program will be terminated" << std::endl; |
||||
|
||||
return; |
||||
} |
||||
|
||||
/* add match if necessary */ |
||||
else if( masks.empty() || masks[itup->second].at < uchar > ( counter ) != 0 ) |
||||
{ |
||||
|
||||
DMatch dm; |
||||
dm.queryIdx = counter; |
||||
dm.trainIdx = results[j] - 1; |
||||
dm.imgIdx = itup->second; |
||||
dm.distance = (float) k_distances[j - index]; |
||||
|
||||
tempVector.push_back( dm ); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/* decide whether temporary vector should be saved */ |
||||
if( ( tempVector.size() == 0 && !compactResult ) || tempVector.size() > 0 ) |
||||
matches.push_back( tempVector ); |
||||
|
||||
/* increment pointer */ |
||||
index += descrInDS; |
||||
} |
||||
|
||||
/* delete data */ |
||||
delete results; |
||||
delete numres; |
||||
|
||||
} |
||||
|
||||
/* execute a batch query */ |
||||
void BinaryDescriptorMatcher::Mihasher::batchquery( UINT32 * results, UINT32 *numres, const cv::Mat & queries, UINT32 numq, int dim1queries ) |
||||
{ |
||||
/* create and initialize a bitarray */ |
||||
counter = new bitarray; |
||||
counter->init( N ); |
||||
|
||||
UINT32 *res = new UINT32[K * ( D + 1 )]; |
||||
UINT64 *chunks = new UINT64[m]; |
||||
UINT32 * presults = results; |
||||
UINT32 *pnumres = numres; |
||||
|
||||
/* make a copy of input queries */ |
||||
cv::Mat queries_clone = queries.clone(); |
||||
|
||||
/* set a pointer to first query (row) */ |
||||
UINT8 *pq = queries_clone.ptr(); |
||||
|
||||
/* loop over number of descriptors */ |
||||
for ( size_t i = 0; i < numq; i++ ) |
||||
{ |
||||
/* for every descriptor, query database */ |
||||
query( presults, pnumres, pq, chunks, res ); |
||||
|
||||
/* move pointer to write next K indeces */ |
||||
presults += K; |
||||
pnumres += B + 1; |
||||
|
||||
/* move forward pointer to current row in descriptors matrix */ |
||||
pq += dim1queries; |
||||
|
||||
} |
||||
|
||||
delete[] res; |
||||
delete[] chunks; |
||||
|
||||
delete counter; |
||||
} |
||||
|
||||
/* execute a single query */ |
||||
void BinaryDescriptorMatcher::Mihasher::query( UINT32* results, UINT32* numres, UINT8 * Query, UINT64 *chunks, UINT32 *res ) |
||||
{ |
||||
/* if K == 0 that means we want everything to be processed.
|
||||
So maxres = N in that case. Otherwise K limits the results processed */ |
||||
UINT32 maxres = K ? K : (UINT32) N; |
||||
|
||||
/* number of results so far obtained (up to a distance of s per chunk) */ |
||||
UINT32 n = 0; |
||||
|
||||
/* number of candidates tested with full codes (not counting duplicates) */ |
||||
UINT32 nc = 0; |
||||
|
||||
/* counting everything retrieved (duplicates are counted multiple times)
|
||||
number of lookups (and xors) */ |
||||
UINT32 nl = 0; |
||||
|
||||
UINT32 nd = 0; |
||||
UINT32 *arr; |
||||
int size = 0; |
||||
UINT32 index; |
||||
int hammd; |
||||
|
||||
counter->erase(); |
||||
memset( numres, 0, ( B + 1 ) * sizeof ( *numres ) ); |
||||
|
||||
split( chunks, Query, m, mplus, b ); |
||||
|
||||
/* the growing search radius per substring */ |
||||
int s; |
||||
|
||||
/* current b: for the first mplus substrings it is b, for the rest it is (b-1) */ |
||||
int curb = b; |
||||
|
||||
for ( s = 0; s <= d && n < maxres; s++ ) |
||||
{ |
||||
for ( int k = 0; k < m; k++ ) |
||||
{ |
||||
if( k < mplus ) |
||||
curb = b; |
||||
else |
||||
curb = b - 1; |
||||
UINT64 chunksk = chunks[k]; |
||||
/* number of bit-strings with s number of 1s */ |
||||
nl += xornum[s + 1] - xornum[s]; |
||||
|
||||
/* the bit-string with s number of 1s */ |
||||
UINT64 bitstr = 0; |
||||
for ( int i = 0; i < s; i++ ) |
||||
/* power[i] stores the location of the i'th 1 */ |
||||
power[i] = i; |
||||
/* used for stopping criterion (location of (s+1)th 1) */ |
||||
power[s] = curb + 1; |
||||
|
||||
/* bit determines the 1 that should be moving to the left */ |
||||
int bit = s - 1; |
||||
|
||||
/* start from the left-most 1, and move it to the left until
|
||||
it touches another one */ |
||||
|
||||
/* the loop for changing bitstr */ |
||||
bool infiniteWhile = true; |
||||
while ( infiniteWhile ) |
||||
{ |
||||
if( bit != -1 ) |
||||
{ |
||||
bitstr ^= ( power[bit] == bit ) ? (UINT64) 1 << power[bit] : (UINT64) 3 << ( power[bit] - 1 ); |
||||
power[bit]++; |
||||
bit--; |
||||
} |
||||
|
||||
else |
||||
{ /* bit == -1 */ |
||||
/* the binary code bitstr is available for processing */ |
||||
arr = H[k].query( chunksk ^ bitstr, &size ); // lookup
|
||||
if( size ) |
||||
{ /* the corresponding bucket is not empty */ |
||||
nd += size; |
||||
for ( int c = 0; c < size; c++ ) |
||||
{ |
||||
index = arr[c]; |
||||
if( !counter->get( index ) ) |
||||
{ /* if it is not a duplicate */ |
||||
counter->set( index ); |
||||
hammd = cv::line_descriptor::match( codes.ptr() + (UINT64) index * ( B_over_8 ), Query, B_over_8 ); |
||||
|
||||
nc++; |
||||
if( hammd <= D && numres[hammd] < maxres ) |
||||
res[hammd * K + numres[hammd]] = index + 1; |
||||
|
||||
numres[hammd]++; |
||||
} |
||||
} |
||||
} |
||||
|
||||
/* end of processing */ |
||||
while ( ++bit < s && power[bit] == power[bit + 1] - 1 ) |
||||
{ |
||||
bitstr ^= (UINT64) 1 << ( power[bit] - 1 ); |
||||
power[bit] = bit; |
||||
} |
||||
if( bit == s ) |
||||
break; |
||||
} |
||||
} |
||||
|
||||
n = n + numres[s * m + k]; |
||||
if( n >= maxres ) |
||||
break; |
||||
} |
||||
} |
||||
|
||||
n = 0; |
||||
for ( s = 0; s <= D && (int) n < K; s++ ) |
||||
{ |
||||
for ( int c = 0; c < (int) numres[s] && (int) n < K; c++ ) |
||||
results[n++] = res[s * K + c]; |
||||
} |
||||
|
||||
} |
||||
|
||||
/* constructor 2 */ |
||||
BinaryDescriptorMatcher::Mihasher::Mihasher( int B_val, int _m ) |
||||
{ |
||||
B = B_val; |
||||
B_over_8 = B / 8; |
||||
m = _m; |
||||
b = (int) ceil( (double) B / m ); |
||||
|
||||
/* assuming that B/2 is large enough radius to include
|
||||
all of the k nearest neighbors */ |
||||
D = (int) ceil( B / 2.0 ); |
||||
d = (int) ceil( (double) D / m ); |
||||
|
||||
/* mplus is the number of chunks with b bits
|
||||
(m-mplus) is the number of chunks with (b-1) bits */ |
||||
mplus = B - m * ( b - 1 ); |
||||
|
||||
xornum = new UINT32[d + 2]; |
||||
xornum[0] = 0; |
||||
for ( int i = 0; i <= d; i++ ) |
||||
xornum[i + 1] = xornum[i] + (UINT32) choose( b, i ); |
||||
|
||||
H = new SparseHashtable[m]; |
||||
|
||||
/* H[i].init might fail */ |
||||
for ( int i = 0; i < mplus; i++ ) |
||||
H[i].init( b ); |
||||
for ( int i = mplus; i < m; i++ ) |
||||
H[i].init( b - 1 ); |
||||
} |
||||
|
||||
/* K setter */ |
||||
void BinaryDescriptorMatcher::Mihasher::setK( int K_val ) |
||||
{ |
||||
K = K_val; |
||||
} |
||||
|
||||
/* desctructor */ |
||||
BinaryDescriptorMatcher::Mihasher::~Mihasher() |
||||
{ |
||||
delete[] xornum; |
||||
delete[] H; |
||||
} |
||||
|
||||
/* populate tables */ |
||||
void BinaryDescriptorMatcher::Mihasher::populate( cv::Mat & _codes, UINT32 N_val, int dim1codes ) |
||||
{ |
||||
N = N_val; |
||||
codes = _codes; |
||||
UINT64 * chunks = new UINT64[m]; |
||||
|
||||
UINT8 * pcodes = codes.ptr(); |
||||
for ( UINT64 i = 0; i < N; i++, pcodes += dim1codes ) |
||||
{ |
||||
split( chunks, pcodes, m, mplus, b ); |
||||
|
||||
for ( int k = 0; k < m; k++ ) |
||||
H[k].insert( chunks[k], (UINT32) i ); |
||||
|
||||
if( i % (int) ceil( N / 1000.0 ) == 0 ) |
||||
fflush (stdout); |
||||
} |
||||
|
||||
delete[] chunks; |
||||
} |
||||
|
||||
/* constructor */ |
||||
BinaryDescriptorMatcher::SparseHashtable::SparseHashtable() |
||||
{ |
||||
table = NULL; |
||||
size = 0; |
||||
b = 0; |
||||
} |
||||
|
||||
/* initializer */ |
||||
int BinaryDescriptorMatcher::SparseHashtable::init( int _b ) |
||||
{ |
||||
b = _b; |
||||
|
||||
if( b < 5 || b > MAX_B || b > (int) ( sizeof(UINT64) * 8 ) ) |
||||
return 1; |
||||
|
||||
size = UINT64_1 << ( b - 5 ); // size = 2 ^ b
|
||||
table = (BucketGroup*) calloc( size, sizeof(BucketGroup) ); |
||||
|
||||
return 0; |
||||
|
||||
} |
||||
|
||||
/* destructor */ |
||||
BinaryDescriptorMatcher::SparseHashtable::~SparseHashtable() |
||||
{ |
||||
free (table); |
||||
} |
||||
|
||||
/* insert data */ |
||||
void BinaryDescriptorMatcher::SparseHashtable::insert( UINT64 index, UINT32 data ) |
||||
{ |
||||
table[index >> 5].insert( (int) ( index % 32 ), data ); |
||||
} |
||||
|
||||
/* query data */ |
||||
UINT32* BinaryDescriptorMatcher::SparseHashtable::query( UINT64 index, int *Size ) |
||||
{ |
||||
return table[index >> 5].query( (int) ( index % 32 ), Size ); |
||||
} |
||||
|
||||
/* constructor */ |
||||
BinaryDescriptorMatcher::BucketGroup::BucketGroup() |
||||
{ |
||||
empty = 0; |
||||
group = std::vector < uint32_t > ( 2, 0 ); |
||||
} |
||||
|
||||
/* destructor */ |
||||
BinaryDescriptorMatcher::BucketGroup::~BucketGroup() |
||||
{ |
||||
} |
||||
|
||||
void BinaryDescriptorMatcher::BucketGroup::insert_value( std::vector<uint32_t>& vec, int index, UINT32 data ) |
||||
{ |
||||
if( vec.size() > 1 ) |
||||
{ |
||||
if( vec[0] == vec[1] ) |
||||
{ |
||||
vec[1] = (UINT32) ceil( vec[0] * 1.1 ); |
||||
for ( int i = 0; i < (int) ( 2 + vec[1] - vec.size() ); i++ ) |
||||
vec.push_back( 0 ); |
||||
|
||||
} |
||||
|
||||
vec.insert( vec.begin() + 2 + index, data ); |
||||
vec[2 + index] = data; |
||||
vec[0]++; |
||||
} |
||||
|
||||
else |
||||
{ |
||||
vec = std::vector < uint32_t > ( 3, 0 ); |
||||
vec[0] = 1; |
||||
vec[1] = 1; |
||||
vec[2] = data; |
||||
} |
||||
} |
||||
|
||||
void BinaryDescriptorMatcher::BucketGroup::push_value( std::vector<uint32_t>& vec, UINT32 Data ) |
||||
{ |
||||
if( vec.size() > 0 ) |
||||
{ |
||||
if( vec[0] == vec[1] ) |
||||
{ |
||||
vec[1] = (UINT32) std::max( ceil( vec[1] * ARRAY_RESIZE_FACTOR ), vec[1] + ARRAY_RESIZE_ADD_FACTOR ); |
||||
for ( int i = 0; i < (int) ( 2 + vec[1] - vec.size() ); i++ ) |
||||
vec.push_back( 0 ); |
||||
} |
||||
|
||||
vec[2 + vec[0]] = Data; |
||||
vec[0]++; |
||||
|
||||
} |
||||
|
||||
else |
||||
{ |
||||
vec = std::vector < uint32_t > ( 2 + (uint32_t) ARRAY_RESIZE_ADD_FACTOR, 0 ); |
||||
vec[0] = 1; |
||||
vec[1] = 1; |
||||
vec[2] = Data; |
||||
} |
||||
} |
||||
|
||||
/* insert data into the bucket */ |
||||
void BinaryDescriptorMatcher::BucketGroup::insert( int subindex, UINT32 data ) |
||||
{ |
||||
if( group.size() == 0 ) |
||||
{ |
||||
push_value( group, 0 ); |
||||
} |
||||
|
||||
UINT32 lowerbits = ( (UINT32) 1 << subindex ) - 1; |
||||
int end = popcnt( empty & lowerbits ); |
||||
|
||||
if( ! ( empty & ( (UINT32) 1 << subindex ) ) ) |
||||
{ |
||||
insert_value( group, end, group[end + 2] ); |
||||
empty |= (UINT32) 1 << subindex; |
||||
} |
||||
|
||||
int totones = popcnt( empty ); |
||||
insert_value( group, totones + 1 + group[2 + end + 1], data ); |
||||
|
||||
for ( int i = end + 1; i < totones + 1; i++ ) |
||||
group[2 + i]++; |
||||
} |
||||
|
||||
/* perform a query to the bucket */ |
||||
UINT32* BinaryDescriptorMatcher::BucketGroup::query( int subindex, int *size ) |
||||
{ |
||||
if( empty & ( (UINT32) 1 << subindex ) ) |
||||
{ |
||||
UINT32 lowerbits = ( (UINT32) 1 << subindex ) - 1; |
||||
int end = popcnt( empty & lowerbits ); |
||||
int totones = popcnt( empty ); |
||||
|
||||
*size = group[2 + end + 1] - group[2 + end]; |
||||
return & ( * ( group.begin() + 2 + totones + 1 + (int) group[2 + end] ) ); |
||||
} |
||||
|
||||
else |
||||
{ |
||||
*size = 0; |
||||
return NULL; |
||||
} |
||||
} |
||||
|
||||
} |
||||
} |
||||
|
@ -0,0 +1,115 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Mohammad Norouzi, Ali Punjani, David J. Fleet,
|
||||
// all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __OPENCV_BITARRAY_HPP |
||||
#define __OPENCV_BITARRAY_HPP |
||||
|
||||
#ifdef _WIN32 |
||||
#pragma warning( disable : 4267 ) |
||||
#endif |
||||
|
||||
#include "types.hpp" |
||||
#include <stdio.h> |
||||
#include <math.h> |
||||
#include <string.h> |
||||
|
||||
/* class defining a sequence of bits */ |
||||
class bitarray |
||||
{ |
||||
|
||||
public: |
||||
/* pointer to bits sequence and sequence's length */ |
||||
UINT32 *arr; |
||||
UINT32 length; |
||||
|
||||
/* constructor setting default values */ |
||||
bitarray() |
||||
{ |
||||
arr = NULL; |
||||
length = 0; |
||||
} |
||||
|
||||
/* constructor setting sequence's length */ |
||||
bitarray( UINT64 _bits ) |
||||
{ |
||||
init( _bits ); |
||||
} |
||||
|
||||
/* initializer of private fields */ |
||||
void init( UINT64 _bits ) |
||||
{ |
||||
length = (UINT32) ceil( _bits / 32.00 ); |
||||
arr = new UINT32[length]; |
||||
erase(); |
||||
} |
||||
|
||||
/* destructor */ |
||||
~bitarray() |
||||
{ |
||||
if( arr ) |
||||
delete[] arr; |
||||
} |
||||
|
||||
inline void flip( UINT64 index ) |
||||
{ |
||||
arr[index >> 5] ^= ( (UINT32) 0x01 ) << ( index % 32 ); |
||||
} |
||||
|
||||
inline void set( UINT64 index ) |
||||
{ |
||||
arr[index >> 5] |= ( (UINT32) 0x01 ) << ( index % 32 ); |
||||
} |
||||
|
||||
inline UINT8 get( UINT64 index ) |
||||
{ |
||||
return ( arr[index >> 5] & ( ( (UINT32) 0x01 ) << ( index % 32 ) ) ) != 0; |
||||
} |
||||
|
||||
/* reserve menory for an UINT32 */ |
||||
inline void erase() |
||||
{ |
||||
memset( arr, 0, sizeof(UINT32) * length ); |
||||
} |
||||
|
||||
}; |
||||
|
||||
#endif |
@ -0,0 +1,175 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Mohammad Norouzi, Ali Punjani, David J. Fleet,
|
||||
// all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __OPENCV_BITOPTS_HPP |
||||
#define __OPENCV_BITOPTS_HPP |
||||
|
||||
#include "precomp.hpp" |
||||
|
||||
#ifdef _WIN32 |
||||
# include <intrin.h> |
||||
# define popcnt __popcnt |
||||
# define popcntll __popcnt64 |
||||
# pragma warning( disable : 4267 ) |
||||
#else |
||||
# define popcntll __builtin_popcountll |
||||
# define popcnt __builtin_popcount |
||||
|
||||
#endif |
||||
|
||||
/* LUT */ |
||||
const int lookup[] = |
||||
{ 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, |
||||
3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, |
||||
3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, |
||||
4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 2, 3, 3, 4, |
||||
3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 4, 5, 5, 6, 5, |
||||
6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8 }; |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace line_descriptor |
||||
{ |
||||
/*matching function */ |
||||
inline int match( UINT8*P, UINT8*Q, int codelb ) |
||||
{ |
||||
switch ( codelb ) |
||||
{ |
||||
case 4: // 32 bit
|
||||
return popcnt( *(UINT32*) P ^ *(UINT32*) Q ); |
||||
break; |
||||
case 8: // 64 bit
|
||||
return (int) popcntll( ( (UINT64*) P )[0] ^ ( (UINT64*) Q )[0] ); |
||||
break; |
||||
case 16: // 128 bit
|
||||
return (int) ( popcntll( ( (UINT64*) P )[0] ^ ( (UINT64*) Q )[0] ) + popcntll( ( (UINT64*) P )[1] ^ ( (UINT64*) Q )[1] ) ); |
||||
break; |
||||
case 32: // 256 bit
|
||||
return (int) ( popcntll( ( (UINT64*) P )[0] ^ ( (UINT64*) Q )[0] ) + popcntll( ( (UINT64*) P )[1] ^ ( (UINT64*) Q )[1] ) |
||||
+ popcntll( ( (UINT64*) P )[2] ^ ( (UINT64*) Q )[2] ) + popcntll( ( (UINT64*) P )[3] ^ ( (UINT64*) Q )[3] ) ); |
||||
break; |
||||
case 64: // 512 bit
|
||||
return (int) ( popcntll( ( (UINT64*) P )[0] ^ ( (UINT64*) Q )[0] ) + popcntll( ( (UINT64*) P )[1] ^ ( (UINT64*) Q )[1] ) |
||||
+ popcntll( ( (UINT64*) P )[2] ^ ( (UINT64*) Q )[2] ) + popcntll( ( (UINT64*) P )[3] ^ ( (UINT64*) Q )[3] ) |
||||
+ popcntll( ( (UINT64*) P )[4] ^ ( (UINT64*) Q )[4] ) + popcntll( ( (UINT64*) P )[5] ^ ( (UINT64*) Q )[5] ) |
||||
+ popcntll( ( (UINT64*) P )[6] ^ ( (UINT64*) Q )[6] ) + popcntll( ( (UINT64*) P )[7] ^ ( (UINT64*) Q )[7] ) ); |
||||
break; |
||||
default: |
||||
int output = 0; |
||||
for ( int i = 0; i < codelb; i++ ) |
||||
output += lookup[P[i] ^ Q[i]]; |
||||
return output; |
||||
break; |
||||
} |
||||
|
||||
} |
||||
|
||||
/* splitting function (b <= 64) */ |
||||
inline void split( UINT64 *chunks, UINT8 *code, int m, int mplus, int b ) |
||||
{ |
||||
UINT64 temp = 0x0; |
||||
int nbits = 0; |
||||
int nbyte = 0; |
||||
UINT64 mask = b == 64 ? 0xFFFFFFFFFFFFFFFFLLU : ( ( UINT64_1 << b ) - UINT64_1 ); |
||||
|
||||
for ( int i = 0; i < m; i++ ) |
||||
{ |
||||
while ( nbits < b ) |
||||
{ |
||||
temp |= ( (UINT64) code[nbyte++] << nbits ); |
||||
nbits += 8; |
||||
} |
||||
|
||||
chunks[i] = temp & mask; |
||||
temp = b == 64 ? 0x0 : temp >> b; |
||||
nbits -= b; |
||||
|
||||
if( i == mplus - 1 ) |
||||
{ |
||||
b--; /* b <= 63 */ |
||||
mask = ( ( UINT64_1 << b ) - UINT64_1 ); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/* generates the next binary code (in alphabetical order) with the
|
||||
same number of ones as the input x. Taken from |
||||
http://www.geeksforgeeks.org/archives/10375 */
|
||||
inline UINT64 next_set_of_n_elements( UINT64 x ) |
||||
{ |
||||
UINT64 smallest, ripple, new_smallest; |
||||
|
||||
smallest = x & -(signed) x; |
||||
ripple = x + smallest; |
||||
new_smallest = x ^ ripple; |
||||
new_smallest = new_smallest / smallest; |
||||
new_smallest >>= 2; |
||||
return ripple | new_smallest; |
||||
} |
||||
|
||||
/* print code */ |
||||
inline void print_code( UINT64 tmp, int b ) |
||||
{ |
||||
for ( long long int j = ( b - 1 ); j >= 0; j-- ) |
||||
{ |
||||
printf( "%llu", (long long int) tmp / (UINT64) ( 1 << j ) ); |
||||
tmp = tmp - ( tmp / (UINT64) ( 1 << j ) ) * (UINT64) ( 1 << j ); |
||||
} |
||||
|
||||
printf( "\n" ); |
||||
} |
||||
|
||||
inline UINT64 choose( int n, int r ) |
||||
{ |
||||
UINT64 nchooser = 1; |
||||
for ( int k = 0; k < r; k++ ) |
||||
{ |
||||
nchooser *= n - k; |
||||
nchooser /= k + 1; |
||||
} |
||||
|
||||
return nchooser; |
||||
} |
||||
} |
||||
} |
||||
|
||||
#endif |
@ -0,0 +1,190 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Biagio Montesano, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp" |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace line_descriptor |
||||
{ |
||||
/* draw matches between two images */ |
||||
void drawLineMatches( const Mat& img1, const std::vector<KeyLine>& keylines1, const Mat& img2, const std::vector<KeyLine>& keylines2, |
||||
const std::vector<DMatch>& matches1to2, Mat& outImg, const Scalar& matchColor, const Scalar& singleLineColor, |
||||
const std::vector<char>& matchesMask, int flags ) |
||||
{ |
||||
|
||||
if(img1.type() != img2.type()) |
||||
{ |
||||
std::cout << "Input images have different types" << std::endl; |
||||
CV_Assert(img1.type() == img2.type()); |
||||
} |
||||
|
||||
/* initialize output matrix (if necessary) */ |
||||
if( flags == DrawLinesMatchesFlags::DEFAULT ) |
||||
{ |
||||
/* check how many rows are necessary for output matrix */ |
||||
int totalRows = img1.rows >= img2.rows ? img1.rows : img2.rows; |
||||
|
||||
/* initialize output matrix */ |
||||
outImg = Mat::zeros( totalRows, img1.cols + img2.cols, img1.type() ); |
||||
|
||||
} |
||||
|
||||
/* initialize random seed: */ |
||||
srand( (unsigned int) time( NULL ) ); |
||||
|
||||
Scalar singleLineColorRGB; |
||||
if( singleLineColor == Scalar::all( -1 ) ) |
||||
{ |
||||
int R = ( rand() % (int) ( 255 + 1 ) ); |
||||
int G = ( rand() % (int) ( 255 + 1 ) ); |
||||
int B = ( rand() % (int) ( 255 + 1 ) ); |
||||
|
||||
singleLineColorRGB = Scalar( R, G, B ); |
||||
} |
||||
|
||||
else |
||||
singleLineColorRGB = singleLineColor; |
||||
|
||||
/* copy input images to output images */ |
||||
Mat roi_left( outImg, Rect( 0, 0, img1.cols, img1.rows ) ); |
||||
Mat roi_right( outImg, Rect( img1.cols, 0, img2.cols, img2.rows ) ); |
||||
img1.copyTo( roi_left ); |
||||
img2.copyTo( roi_right ); |
||||
|
||||
/* get columns offset */ |
||||
int offset = img1.cols; |
||||
|
||||
/* if requested, draw lines from both images */ |
||||
if( flags != DrawLinesMatchesFlags::NOT_DRAW_SINGLE_LINES ) |
||||
{ |
||||
for ( size_t i = 0; i < keylines1.size(); i++ ) |
||||
{ |
||||
KeyLine k1 = keylines1[i]; |
||||
//line( outImg, Point2f( k1.startPointX, k1.startPointY ), Point2f( k1.endPointX, k1.endPointY ), singleLineColorRGB, 2 );
|
||||
line( outImg, Point2f( k1.sPointInOctaveX, k1.sPointInOctaveY ), Point2f( k1.ePointInOctaveX, k1.ePointInOctaveY ), singleLineColorRGB, 2 ); |
||||
|
||||
} |
||||
|
||||
for ( size_t j = 0; j < keylines2.size(); j++ ) |
||||
{ |
||||
KeyLine k2 = keylines2[j]; |
||||
line( outImg, Point2f( k2.sPointInOctaveX + offset, k2.sPointInOctaveY ), Point2f( k2.ePointInOctaveX + offset, k2.ePointInOctaveY ), singleLineColorRGB, 2 ); |
||||
} |
||||
} |
||||
|
||||
/* draw matches */ |
||||
for ( size_t counter = 0; counter < matches1to2.size(); counter++ ) |
||||
{ |
||||
if( matchesMask[counter] != 0 ) |
||||
{ |
||||
DMatch dm = matches1to2[counter]; |
||||
KeyLine left = keylines1[dm.queryIdx]; |
||||
KeyLine right = keylines2[dm.trainIdx]; |
||||
|
||||
Scalar matchColorRGB; |
||||
if( matchColor == Scalar::all( -1 ) ) |
||||
{ |
||||
int R = ( rand() % (int) ( 255 + 1 ) ); |
||||
int G = ( rand() % (int) ( 255 + 1 ) ); |
||||
int B = ( rand() % (int) ( 255 + 1 ) ); |
||||
|
||||
matchColorRGB = Scalar( R, G, B ); |
||||
|
||||
if( singleLineColor == Scalar::all( -1 ) ) |
||||
singleLineColorRGB = matchColorRGB; |
||||
} |
||||
|
||||
else |
||||
matchColorRGB = matchColor; |
||||
|
||||
/* draw lines if necessary */ |
||||
// line( outImg, Point2f( left.startPointX, left.startPointY ), Point2f( left.endPointX, left.endPointY ), singleLineColorRGB, 2 );
|
||||
//
|
||||
// line( outImg, Point2f( right.startPointX + offset, right.startPointY ), Point2f( right.endPointX + offset, right.endPointY ), singleLineColorRGB,
|
||||
// 2 );
|
||||
//
|
||||
// /* link correspondent lines */
|
||||
// line( outImg, Point2f( left.startPointX, left.startPointY ), Point2f( right.startPointX + offset, right.startPointY ), matchColorRGB, 1 );
|
||||
|
||||
line( outImg, Point2f( left.sPointInOctaveX, left.sPointInOctaveY ), Point2f( left.ePointInOctaveX, left.ePointInOctaveY ), singleLineColorRGB, 2 ); |
||||
|
||||
line( outImg, Point2f( right.sPointInOctaveX + offset, right.sPointInOctaveY ), Point2f( right.ePointInOctaveX + offset, right.ePointInOctaveY ), singleLineColorRGB, |
||||
2 ); |
||||
|
||||
/* link correspondent lines */ |
||||
line( outImg, Point2f( left.sPointInOctaveX, left.sPointInOctaveY ), Point2f( right.sPointInOctaveX + offset, right.sPointInOctaveY ), matchColorRGB, 1 ); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/* draw extracted lines on original image */ |
||||
void drawKeylines( const Mat& image, const std::vector<KeyLine>& keylines, Mat& outImage, const Scalar& color, int flags ) |
||||
{ |
||||
if( flags == DrawLinesMatchesFlags::DEFAULT ) |
||||
outImage = image.clone(); |
||||
|
||||
for ( size_t i = 0; i < keylines.size(); i++ ) |
||||
{ |
||||
/* decide lines' color */ |
||||
Scalar lineColor; |
||||
if( color != Scalar::all( -1 ) ) |
||||
{ |
||||
int R = ( rand() % (int) ( 255 + 1 ) ); |
||||
int G = ( rand() % (int) ( 255 + 1 ) ); |
||||
int B = ( rand() % (int) ( 255 + 1 ) ); |
||||
|
||||
lineColor = Scalar( R, G, B ); |
||||
} |
||||
|
||||
else |
||||
lineColor = color; |
||||
|
||||
/* get line */ |
||||
KeyLine k = keylines[i]; |
||||
|
||||
/* draw line */ |
||||
line( outImage, Point2f( k.startPointX, k.startPointY ), Point2f( k.endPointX, k.endPointY ), lineColor, 1 ); |
||||
} |
||||
} |
||||
|
||||
} |
||||
} |
@ -0,0 +1,64 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Biagio Montesano, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp" |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace line_descriptor |
||||
{ |
||||
|
||||
CV_INIT_ALGORITHM( BinaryDescriptor, "BINARY.DESCRIPTOR", ); |
||||
CV_INIT_ALGORITHM( BinaryDescriptorMatcher, "BINARY.DESCRIPTOR.MATCHER", ); |
||||
CV_INIT_ALGORITHM( LSDDetector, "LSDDETECTOR", ); |
||||
|
||||
bool initModule_line_descriptor( void ) |
||||
{ |
||||
bool all = true; |
||||
all &= !BinaryDescriptor_info_auto.name().empty(); |
||||
all &= !BinaryDescriptorMatcher_info_auto.name().empty(); |
||||
all &= !LSDDetector_info_auto.name().empty(); |
||||
|
||||
return all; |
||||
} |
||||
|
||||
} |
||||
} |
@ -0,0 +1,77 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Biagio Montesano, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __OPENCV_PRECOMP_H__ |
||||
#define __OPENCV_PRECOMP_H__ |
||||
|
||||
#ifdef _WIN32 |
||||
#pragma warning( disable : 4267 ) |
||||
#endif |
||||
|
||||
#define _USE_MATH_DEFINES |
||||
|
||||
#include <algorithm> |
||||
#include "opencv2/core/utility.hpp" |
||||
#include "opencv2/core/private.hpp" |
||||
#include <opencv2/imgproc.hpp> |
||||
#include <opencv2/features2d.hpp> |
||||
#include <opencv2/highgui.hpp> |
||||
#include "opencv2/core.hpp" |
||||
|
||||
#include <iostream> |
||||
#include <map> |
||||
#include <stdio.h> |
||||
#include <string.h> |
||||
#include <cmath> |
||||
#include <algorithm> |
||||
#include <bitset> |
||||
#include <time.h> |
||||
#include <stdexcept> |
||||
#include <sstream> |
||||
#include <vector> |
||||
|
||||
#include "bitarray.hpp" |
||||
#include "bitops.hpp" |
||||
#include "types.hpp" |
||||
|
||||
#include "opencv2/line_descriptor.hpp" |
||||
|
||||
#endif |
@ -0,0 +1,62 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Mohammad Norouzi, Ali Punjani, David J. Fleet,
|
||||
// all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include <inttypes.h> |
||||
|
||||
#ifndef __OPENCV_TYPES_HPP |
||||
#define __OPENCV_TYPES_HPP |
||||
|
||||
#ifdef _WIN32 |
||||
#pragma warning( disable : 4267 ) |
||||
#endif |
||||
|
||||
/* define data types */ |
||||
typedef uint64_t UINT64; |
||||
typedef uint32_t UINT32; |
||||
typedef uint16_t UINT16; |
||||
typedef uint8_t UINT8; |
||||
|
||||
/* define constants */ |
||||
#define UINT64_1 ((UINT64)0x01) |
||||
#define UINT32_1 ((UINT32)0x01) |
||||
|
||||
#endif |
@ -0,0 +1,375 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Biagio Montesano, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "test_precomp.hpp" |
||||
|
||||
using namespace cv; |
||||
using namespace cv::line_descriptor; |
||||
|
||||
/****************************************************************************************\
|
||||
* Regression tests for line detector comparing keylines. * |
||||
\****************************************************************************************/ |
||||
|
||||
const std::string LINE_DESCRIPTOR_DIR = "line_descriptor"; |
||||
const std::string IMAGE_FILENAME = "cameraman.jpg"; |
||||
const std::string DESCRIPTORS_DIR = LINE_DESCRIPTOR_DIR + "/descriptors"; |
||||
|
||||
template<class Distance> |
||||
class CV_BD_DescriptorsTest : public cvtest::BaseTest |
||||
{ |
||||
|
||||
public: |
||||
typedef typename Distance::ValueType ValueType; |
||||
typedef typename Distance::ResultType DistanceType; |
||||
|
||||
CV_BD_DescriptorsTest( std::string fs, DistanceType _maxDist ): maxDist(_maxDist) |
||||
{ |
||||
bd = BinaryDescriptor::createBinaryDescriptor(); |
||||
fs_name = fs; |
||||
} |
||||
|
||||
protected: |
||||
// void compareDescriptors( const Mat& validDescriptors, const Mat& calcDescriptors );
|
||||
// void createVecFromMat( Mat& inputMat, std::vector<KeyLine>& output );
|
||||
// virtual bool writeDescriptors( Mat& descs );
|
||||
// virtual Mat readDescriptors();
|
||||
// void emptyDataTest();
|
||||
// void regressionTest();
|
||||
// virtual void run( int );
|
||||
|
||||
Ptr<BinaryDescriptor> bd; |
||||
std::string fs_name; |
||||
const DistanceType maxDist; |
||||
Distance distance; |
||||
|
||||
//};
|
||||
|
||||
void compareDescriptors( const Mat& validDescriptors, const Mat& calcDescriptors ) |
||||
{ |
||||
if( validDescriptors.size != calcDescriptors.size || validDescriptors.type() != calcDescriptors.type() ) |
||||
{ |
||||
ts->printf( cvtest::TS::LOG, "Valid and computed descriptors matrices must have the same size and type.\n" ); |
||||
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_TEST_DATA ); |
||||
return; |
||||
} |
||||
|
||||
CV_Assert( validDescriptors.type() == CV_8U ); |
||||
|
||||
int dimension = validDescriptors.cols; |
||||
DistanceType curMaxDist = std::numeric_limits<DistanceType>::min(); |
||||
for ( int y = 0; y < validDescriptors.rows; y++ ) |
||||
{ |
||||
DistanceType dist = distance( validDescriptors.ptr<ValueType>( y ), calcDescriptors.ptr<ValueType>( y ), dimension ); |
||||
if( dist > curMaxDist ) |
||||
curMaxDist = dist; |
||||
} |
||||
|
||||
std::stringstream ss; |
||||
ss << "Max distance between valid and computed descriptors " << curMaxDist; |
||||
|
||||
if( curMaxDist < maxDist ) |
||||
ss << "." << std::endl; |
||||
|
||||
else |
||||
{ |
||||
ss << ">" << maxDist << " - bad accuracy!" << "\n"; |
||||
ts->set_failed_test_info( cvtest::TS::FAIL_BAD_ACCURACY ); |
||||
} |
||||
|
||||
ts->printf( cvtest::TS::LOG, ss.str().c_str() ); |
||||
} |
||||
|
||||
Mat readDescriptors() |
||||
{ |
||||
Mat descriptors; |
||||
FileStorage fs( std::string( ts->get_data_path() ) + LINE_DESCRIPTOR_DIR + "/descriptors/" + fs_name, FileStorage::READ ); |
||||
fs["descriptors"] >> descriptors; |
||||
|
||||
return descriptors; |
||||
} |
||||
|
||||
bool writeDescriptors( Mat& descs ) |
||||
{ |
||||
FileStorage fs( std::string( ts->get_data_path() ) + LINE_DESCRIPTOR_DIR + "/descriptors/" + fs_name, FileStorage::WRITE ); |
||||
fs << "descriptors" << descs; |
||||
|
||||
return true; |
||||
} |
||||
|
||||
void createMatFromVec( const std::vector<KeyLine>& linesVec, Mat& output ) |
||||
{ |
||||
output = Mat( (int) linesVec.size(), 17, CV_32FC1 ); |
||||
|
||||
for ( int i = 0; i < (int) linesVec.size(); i++ ) |
||||
{ |
||||
std::vector<float> klData; |
||||
KeyLine kl = linesVec[i]; |
||||
klData.push_back( kl.angle ); |
||||
klData.push_back( (float) kl.class_id ); |
||||
klData.push_back( kl.ePointInOctaveX ); |
||||
klData.push_back( kl.ePointInOctaveY ); |
||||
klData.push_back( kl.endPointX ); |
||||
klData.push_back( kl.endPointY ); |
||||
klData.push_back( kl.lineLength ); |
||||
klData.push_back( (float) kl.numOfPixels ); |
||||
klData.push_back( (float) kl.octave ); |
||||
klData.push_back( kl.pt.x ); |
||||
klData.push_back( kl.pt.y ); |
||||
klData.push_back( kl.response ); |
||||
klData.push_back( kl.sPointInOctaveX ); |
||||
klData.push_back( kl.sPointInOctaveY ); |
||||
klData.push_back( kl.size ); |
||||
klData.push_back( kl.startPointX ); |
||||
klData.push_back( kl.startPointY ); |
||||
|
||||
float* pointerToRow = output.ptr<float>( i ); |
||||
for ( int j = 0; j < 17; j++ ) |
||||
{ |
||||
*pointerToRow = klData[j]; |
||||
pointerToRow++; |
||||
} |
||||
} |
||||
} |
||||
|
||||
void createVecFromMat( Mat& inputMat, std::vector<KeyLine>& output ) |
||||
{ |
||||
for ( int i = 0; i < inputMat.rows; i++ ) |
||||
{ |
||||
std::vector<float> tempFloat; |
||||
KeyLine kl; |
||||
float* pointerToRow = inputMat.ptr<float>( i ); |
||||
|
||||
for ( int j = 0; j < 17; j++ ) |
||||
{ |
||||
tempFloat.push_back( *pointerToRow ); |
||||
pointerToRow++; |
||||
} |
||||
|
||||
kl.angle = tempFloat[0]; |
||||
kl.class_id = (int) tempFloat[1]; |
||||
kl.ePointInOctaveX = tempFloat[2]; |
||||
kl.ePointInOctaveY = tempFloat[3]; |
||||
kl.endPointX = tempFloat[4]; |
||||
kl.endPointY = tempFloat[5]; |
||||
kl.lineLength = tempFloat[6]; |
||||
kl.numOfPixels = (int) tempFloat[7]; |
||||
kl.octave = (int) tempFloat[8]; |
||||
kl.pt.x = tempFloat[9]; |
||||
kl.pt.y = tempFloat[10]; |
||||
kl.response = tempFloat[11]; |
||||
kl.sPointInOctaveX = tempFloat[12]; |
||||
kl.sPointInOctaveY = tempFloat[13]; |
||||
kl.size = tempFloat[14]; |
||||
kl.startPointX = tempFloat[15]; |
||||
kl.startPointY = tempFloat[16]; |
||||
|
||||
output.push_back( kl ); |
||||
} |
||||
} |
||||
|
||||
void emptyDataTest() |
||||
{ |
||||
assert( bd ); |
||||
|
||||
// One image.
|
||||
Mat image; |
||||
std::vector<KeyLine> keypoints; |
||||
Mat descriptors; |
||||
|
||||
try |
||||
{ |
||||
bd->compute( image, keypoints, descriptors ); |
||||
} |
||||
|
||||
catch ( ... ) |
||||
{ |
||||
ts->printf( cvtest::TS::LOG, "compute() on empty image and empty keypoints must not generate exception (1).\n" ); |
||||
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_TEST_DATA ); |
||||
} |
||||
|
||||
image.create( 50, 50, CV_8UC3 ); |
||||
try |
||||
{ |
||||
bd->compute( image, keypoints, descriptors ); |
||||
} |
||||
|
||||
catch ( ... ) |
||||
{ |
||||
ts->printf( cvtest::TS::LOG, "compute() on nonempty image and empty keylines must not generate exception (1).\n" ); |
||||
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_TEST_DATA ); |
||||
} |
||||
|
||||
// Several images.
|
||||
std::vector<Mat> images; |
||||
std::vector<std::vector<KeyLine> > keylinesCollection; |
||||
std::vector<Mat> descriptorsCollection; |
||||
try |
||||
{ |
||||
bd->compute( images, keylinesCollection, descriptorsCollection ); |
||||
} |
||||
|
||||
catch ( ... ) |
||||
{ |
||||
ts->printf( cvtest::TS::LOG, "compute() on empty images and empty keylines collection must not generate exception (2).\n" ); |
||||
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_TEST_DATA ); |
||||
} |
||||
|
||||
} |
||||
|
||||
void regressionTest() |
||||
{ |
||||
assert( bd ); |
||||
|
||||
// Read the test image.
|
||||
std::string imgFilename = std::string( ts->get_data_path() ) + LINE_DESCRIPTOR_DIR + "/" + IMAGE_FILENAME; |
||||
|
||||
Mat img = imread( imgFilename ); |
||||
if( img.empty() ) |
||||
{ |
||||
ts->printf( cvtest::TS::LOG, "Image %s can not be read.\n", imgFilename.c_str() ); |
||||
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_TEST_DATA ); |
||||
return; |
||||
} |
||||
|
||||
std::vector<KeyLine> keylines; |
||||
FileStorage fs( std::string( ts->get_data_path() ) + LINE_DESCRIPTOR_DIR + "/detectors/edl_detector_keylines_cameraman.yaml", FileStorage::READ ); |
||||
if( fs.isOpened() ) |
||||
{ |
||||
//read( fs.getFirstTopLevelNode(), keypoints );
|
||||
|
||||
/* load keylines */ |
||||
Mat loadedKeylines; |
||||
fs["keylines"] >> loadedKeylines; |
||||
createVecFromMat( loadedKeylines, keylines ); |
||||
|
||||
/* compute descriptors */ |
||||
Mat calcDescriptors; |
||||
double t = (double) getTickCount(); |
||||
bd->compute( img, keylines, calcDescriptors ); |
||||
t = getTickCount() - t; |
||||
ts->printf( cvtest::TS::LOG, "\nAverage time of computing one descriptor = %g ms.\n", |
||||
t / ( (double) getTickFrequency() * 1000. ) / calcDescriptors.rows ); |
||||
|
||||
if( calcDescriptors.rows != (int) keylines.size() ) |
||||
{ |
||||
ts->printf( cvtest::TS::LOG, "Count of computed descriptors and keylines count must be equal.\n" ); |
||||
ts->printf( cvtest::TS::LOG, "Count of keylines is %d.\n", (int) keylines.size() ); |
||||
ts->printf( cvtest::TS::LOG, "Count of computed descriptors is %d.\n", calcDescriptors.rows ); |
||||
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT ); |
||||
return; |
||||
} |
||||
|
||||
if( calcDescriptors.cols != bd->descriptorSize() / 8 || calcDescriptors.type() != bd->descriptorType() ) |
||||
{ |
||||
ts->printf( cvtest::TS::LOG, "Incorrect descriptor size or descriptor type.\n" ); |
||||
ts->printf( cvtest::TS::LOG, "Expected size is %d.\n", bd->descriptorSize() ); |
||||
ts->printf( cvtest::TS::LOG, "Calculated size is %d.\n", calcDescriptors.cols ); |
||||
ts->printf( cvtest::TS::LOG, "Expected type is %d.\n", bd->descriptorType() ); |
||||
ts->printf( cvtest::TS::LOG, "Calculated type is %d.\n", calcDescriptors.type() ); |
||||
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT ); |
||||
return; |
||||
} |
||||
|
||||
// TODO read and write descriptor extractor parameters and check them
|
||||
Mat validDescriptors = readDescriptors(); |
||||
if( !validDescriptors.empty() ) |
||||
compareDescriptors( validDescriptors, calcDescriptors ); |
||||
else |
||||
{ |
||||
if( !writeDescriptors( calcDescriptors ) ) |
||||
{ |
||||
ts->printf( cvtest::TS::LOG, "Descriptors can not be written.\n" ); |
||||
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_TEST_DATA ); |
||||
return; |
||||
} |
||||
} |
||||
|
||||
} |
||||
else |
||||
{ |
||||
ts->printf( cvtest::TS::LOG, "Compute and write keylines.\n" ); |
||||
fs.open( std::string( ts->get_data_path() ) + LINE_DESCRIPTOR_DIR + "/detectors/edl_detector_keylines_cameraman.yaml", FileStorage::WRITE ); |
||||
if( fs.isOpened() ) |
||||
{ |
||||
bd->detect( img, keylines ); |
||||
Mat keyLinesToYaml; |
||||
createMatFromVec( keylines, keyLinesToYaml ); |
||||
fs << "keylines" << keyLinesToYaml; |
||||
} |
||||
else |
||||
{ |
||||
ts->printf( cvtest::TS::LOG, "File for writting keylines can not be opened.\n" ); |
||||
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_TEST_DATA ); |
||||
return; |
||||
} |
||||
} |
||||
} |
||||
|
||||
void run( int ) |
||||
{ |
||||
if( !bd ) |
||||
{ |
||||
ts->printf( cvtest::TS::LOG, "Feature detector is empty.\n" ); |
||||
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_TEST_DATA ); |
||||
return; |
||||
} |
||||
|
||||
emptyDataTest(); |
||||
regressionTest(); |
||||
|
||||
ts->set_failed_test_info( cvtest::TS::OK ); |
||||
} |
||||
|
||||
private: |
||||
CV_BD_DescriptorsTest& operator=( const CV_BD_DescriptorsTest& ) |
||||
{ |
||||
return *this; |
||||
} |
||||
}; |
||||
/****************************************************************************************\
|
||||
* Tests registrations * |
||||
\****************************************************************************************/ |
||||
|
||||
TEST( BinaryDescriptor_Descriptors, regression ) |
||||
{ |
||||
CV_BD_DescriptorsTest<Hamming> test( std::string( "lbd_descriptors_cameraman" ), 1 ); |
||||
test.safe_run(); |
||||
} |
@ -0,0 +1,340 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Biagio Montesano, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "test_precomp.hpp" |
||||
|
||||
using namespace cv; |
||||
using namespace cv::line_descriptor; |
||||
|
||||
/****************************************************************************************\
|
||||
* Regression tests for line detector comparing keylines. * |
||||
\****************************************************************************************/ |
||||
|
||||
const std::string LINE_DESCRIPTOR_DIR = "line_descriptor"; |
||||
const std::string IMAGE_FILENAME = "cameraman.jpg"; |
||||
const std::string DETECTOR_DIR = LINE_DESCRIPTOR_DIR + "/detectors"; |
||||
|
||||
class CV_BinaryDescriptorDetectorTest : public cvtest::BaseTest |
||||
{ |
||||
|
||||
public: |
||||
CV_BinaryDescriptorDetectorTest( std::string fs ) |
||||
{ |
||||
bd = BinaryDescriptor::createBinaryDescriptor(); |
||||
fs_name = fs; |
||||
} |
||||
|
||||
protected: |
||||
bool isSimilarKeylines( const KeyLine& k1, const KeyLine& k2 ); |
||||
void compareKeylineSets( const std::vector<KeyLine>& validKeylines, const std::vector<KeyLine>& calcKeylines ); |
||||
void createMatFromVec( const std::vector<KeyLine>& linesVec, Mat& output ); |
||||
void createVecFromMat( Mat& inputMat, std::vector<KeyLine>& output ); |
||||
|
||||
void emptyDataTest(); |
||||
void regressionTest(); |
||||
virtual void run( int ); |
||||
|
||||
Ptr<BinaryDescriptor> bd; |
||||
std::string fs_name; |
||||
|
||||
}; |
||||
|
||||
void CV_BinaryDescriptorDetectorTest::emptyDataTest() |
||||
{ |
||||
/* one image */ |
||||
Mat image; |
||||
std::vector<KeyLine> keylines; |
||||
|
||||
try |
||||
{ |
||||
bd->detect( image, keylines ); |
||||
} |
||||
|
||||
catch ( ... ) |
||||
{ |
||||
ts->printf( cvtest::TS::LOG, "detect() on empty image must return empty keylines vector (1).\n" ); |
||||
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT ); |
||||
} |
||||
|
||||
if( !keylines.empty() ) |
||||
{ |
||||
ts->printf( cvtest::TS::LOG, "detect() on empty image must return empty keylines vector (1).\n" ); |
||||
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT ); |
||||
return; |
||||
} |
||||
|
||||
/* more than one image */ |
||||
std::vector<Mat> images; |
||||
std::vector<std::vector<KeyLine> > keylineCollection; |
||||
|
||||
try |
||||
{ |
||||
bd->detect( images, keylineCollection ); |
||||
} |
||||
|
||||
catch ( ... ) |
||||
{ |
||||
ts->printf( cvtest::TS::LOG, "detect() on empty image vector must not generate exception (2).\n" ); |
||||
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT ); |
||||
} |
||||
|
||||
} |
||||
|
||||
void CV_BinaryDescriptorDetectorTest::createMatFromVec( const std::vector<KeyLine>& linesVec, Mat& output ) |
||||
{ |
||||
output = Mat( (int) linesVec.size(), 17, CV_32FC1 ); |
||||
|
||||
for ( int i = 0; i < (int) linesVec.size(); i++ ) |
||||
{ |
||||
std::vector<float> klData; |
||||
KeyLine kl = linesVec[i]; |
||||
klData.push_back( kl.angle ); |
||||
klData.push_back( (float) kl.class_id ); |
||||
klData.push_back( kl.ePointInOctaveX ); |
||||
klData.push_back( kl.ePointInOctaveY ); |
||||
klData.push_back( kl.endPointX ); |
||||
klData.push_back( kl.endPointY ); |
||||
klData.push_back( kl.lineLength ); |
||||
klData.push_back( (float) kl.numOfPixels ); |
||||
klData.push_back( (float) kl.octave ); |
||||
klData.push_back( kl.pt.x ); |
||||
klData.push_back( kl.pt.y ); |
||||
klData.push_back( kl.response ); |
||||
klData.push_back( kl.sPointInOctaveX ); |
||||
klData.push_back( kl.sPointInOctaveY ); |
||||
klData.push_back( kl.size ); |
||||
klData.push_back( kl.startPointX ); |
||||
klData.push_back( kl.startPointY ); |
||||
|
||||
float* pointerToRow = output.ptr<float>( i ); |
||||
for ( int j = 0; j < 17; j++ ) |
||||
{ |
||||
*pointerToRow = klData[j]; |
||||
pointerToRow++; |
||||
} |
||||
} |
||||
} |
||||
|
||||
void CV_BinaryDescriptorDetectorTest::createVecFromMat( Mat& inputMat, std::vector<KeyLine>& output ) |
||||
{ |
||||
for ( int i = 0; i < inputMat.rows; i++ ) |
||||
{ |
||||
std::vector<float> tempFloat; |
||||
KeyLine kl; |
||||
float* pointerToRow = inputMat.ptr<float>( i ); |
||||
|
||||
for ( int j = 0; j < 17; j++ ) |
||||
{ |
||||
tempFloat.push_back( *pointerToRow ); |
||||
pointerToRow++; |
||||
} |
||||
|
||||
kl.angle = tempFloat[0]; |
||||
kl.class_id = (int) tempFloat[1]; |
||||
kl.ePointInOctaveX = tempFloat[2]; |
||||
kl.ePointInOctaveY = tempFloat[3]; |
||||
kl.endPointX = tempFloat[4]; |
||||
kl.endPointY = tempFloat[5]; |
||||
kl.lineLength = tempFloat[6]; |
||||
kl.numOfPixels = (int) tempFloat[7]; |
||||
kl.octave = (int) tempFloat[8]; |
||||
kl.pt.x = tempFloat[9]; |
||||
kl.pt.y = tempFloat[10]; |
||||
kl.response = tempFloat[11]; |
||||
kl.sPointInOctaveX = tempFloat[12]; |
||||
kl.sPointInOctaveY = tempFloat[13]; |
||||
kl.size = tempFloat[14]; |
||||
kl.startPointX = tempFloat[15]; |
||||
kl.startPointY = tempFloat[16]; |
||||
|
||||
output.push_back( kl ); |
||||
} |
||||
} |
||||
|
||||
bool CV_BinaryDescriptorDetectorTest::isSimilarKeylines( const KeyLine& k1, const KeyLine& k2 ) |
||||
{ |
||||
const float maxPtDif = 1.f; |
||||
const float maxSizeDif = 1.f; |
||||
const float maxAngleDif = 2.f; |
||||
const float maxResponseDif = 0.1f; |
||||
|
||||
float dist = (float) norm( k1.pt - k2.pt ); |
||||
return ( dist < maxPtDif && fabs( k1.size - k2.size ) < maxSizeDif && abs( k1.angle - k2.angle ) < maxAngleDif |
||||
&& abs( k1.response - k2.response ) < maxResponseDif && k1.octave == k2.octave && k1.class_id == k2.class_id ); |
||||
} |
||||
|
||||
void CV_BinaryDescriptorDetectorTest::compareKeylineSets( const std::vector<KeyLine>& validKeylines, const std::vector<KeyLine>& calcKeylines ) |
||||
{ |
||||
const float maxCountRatioDif = 0.01f; |
||||
|
||||
// Compare counts of validation and calculated keylines.
|
||||
float countRatio = (float) validKeylines.size() / (float) calcKeylines.size(); |
||||
if( countRatio < 1 - maxCountRatioDif || countRatio > 1.f + maxCountRatioDif ) |
||||
{ |
||||
ts->printf( cvtest::TS::LOG, "Bad keylines count ratio (validCount = %d, calcCount = %d).\n", validKeylines.size(), calcKeylines.size() ); |
||||
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT ); |
||||
return; |
||||
} |
||||
|
||||
int progress = 0; |
||||
int progressCount = (int) ( validKeylines.size() * calcKeylines.size() ); |
||||
int badLineCount = 0; |
||||
int commonLineCount = max( (int) validKeylines.size(), (int) calcKeylines.size() ); |
||||
for ( size_t v = 0; v < validKeylines.size(); v++ ) |
||||
{ |
||||
int nearestIdx = -1; |
||||
float minDist = std::numeric_limits<float>::max(); |
||||
|
||||
for ( size_t c = 0; c < calcKeylines.size(); c++ ) |
||||
{ |
||||
progress = update_progress( progress, (int) ( v * calcKeylines.size() + c ), progressCount, 0 ); |
||||
float curDist = (float) norm( calcKeylines[c].pt - validKeylines[v].pt ); |
||||
if( curDist < minDist ) |
||||
{ |
||||
minDist = curDist; |
||||
nearestIdx = (int) c; |
||||
} |
||||
} |
||||
|
||||
assert( minDist >= 0 ); |
||||
if( !isSimilarKeylines( validKeylines[v], calcKeylines[nearestIdx] ) ) |
||||
badLineCount++; |
||||
} |
||||
|
||||
ts->printf( cvtest::TS::LOG, "badLineCount = %d; validLineCount = %d; calcLineCount = %d\n", badLineCount, validKeylines.size(), |
||||
calcKeylines.size() ); |
||||
|
||||
if( badLineCount > 0.9 * commonLineCount ) |
||||
{ |
||||
ts->printf( cvtest::TS::LOG, " - Bad accuracy!\n" ); |
||||
ts->set_failed_test_info( cvtest::TS::FAIL_BAD_ACCURACY ); |
||||
return; |
||||
} |
||||
|
||||
ts->printf( cvtest::TS::LOG, " - OK\n" ); |
||||
} |
||||
|
||||
void CV_BinaryDescriptorDetectorTest::regressionTest() |
||||
{ |
||||
assert( bd ); |
||||
std::string imgFilename = std::string( ts->get_data_path() ) + LINE_DESCRIPTOR_DIR + "/" + IMAGE_FILENAME; |
||||
std::string resFilename = std::string( ts->get_data_path() ) + DETECTOR_DIR + "/" + fs_name + ".yaml"; |
||||
|
||||
// Read the test image.
|
||||
Mat image = imread( imgFilename ); |
||||
if( image.empty() ) |
||||
{ |
||||
ts->printf( cvtest::TS::LOG, "Image %s can not be read.\n", imgFilename.c_str() ); |
||||
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_TEST_DATA ); |
||||
return; |
||||
} |
||||
|
||||
// open a storage for reading
|
||||
FileStorage fs( resFilename, FileStorage::READ ); |
||||
|
||||
// Compute keylines.
|
||||
std::vector<KeyLine> calcKeylines; |
||||
bd->detect( image, calcKeylines ); |
||||
|
||||
if( fs.isOpened() ) // Compare computed and valid keylines.
|
||||
{ |
||||
// Read validation keylines set.
|
||||
std::vector<KeyLine> validKeylines; |
||||
Mat storedKeylines; |
||||
fs["keylines"] >> storedKeylines; |
||||
createVecFromMat( storedKeylines, validKeylines ); |
||||
|
||||
if( validKeylines.empty() ) |
||||
{ |
||||
ts->printf( cvtest::TS::LOG, "keylines can not be read.\n" ); |
||||
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_TEST_DATA ); |
||||
return; |
||||
} |
||||
|
||||
compareKeylineSets( validKeylines, calcKeylines ); |
||||
} |
||||
|
||||
else // Write detector parameters and computed keylines as validation data.
|
||||
{ |
||||
fs.open( resFilename, FileStorage::WRITE ); |
||||
if( !fs.isOpened() ) |
||||
{ |
||||
ts->printf( cvtest::TS::LOG, "File %s can not be opened to write.\n", resFilename.c_str() ); |
||||
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_TEST_DATA ); |
||||
return; |
||||
} |
||||
|
||||
else |
||||
{ |
||||
fs << "detector_params" << "{"; |
||||
bd->write( fs ); |
||||
fs << "}"; |
||||
Mat lines; |
||||
createMatFromVec( calcKeylines, lines ); |
||||
fs << "keylines" << lines; |
||||
} |
||||
} |
||||
} |
||||
|
||||
void CV_BinaryDescriptorDetectorTest::run( int ) |
||||
{ |
||||
if( !bd ) |
||||
{ |
||||
ts->printf( cvtest::TS::LOG, "Feature detector is empty.\n" ); |
||||
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_TEST_DATA ); |
||||
return; |
||||
} |
||||
|
||||
emptyDataTest(); |
||||
regressionTest(); |
||||
|
||||
ts->set_failed_test_info( cvtest::TS::OK ); |
||||
} |
||||
|
||||
/****************************************************************************************\
|
||||
* Tests registrations * |
||||
\****************************************************************************************/ |
||||
|
||||
TEST( BinaryDescriptor_Detector, regression ) |
||||
{ |
||||
CV_BinaryDescriptorDetectorTest test( std::string( "edl_detector_keylines_cameraman" ) ); |
||||
test.safe_run(); |
||||
} |
@ -0,0 +1,3 @@ |
||||
#include "test_precomp.hpp" |
||||
|
||||
CV_TEST_MAIN("cv") |
@ -0,0 +1,579 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Biagio Montesano, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "test_precomp.hpp" |
||||
|
||||
using namespace cv; |
||||
using namespace cv::line_descriptor; |
||||
|
||||
class CV_BinaryDescriptorMatcherTest : public cvtest::BaseTest |
||||
{ |
||||
public: |
||||
CV_BinaryDescriptorMatcherTest( float _badPart ) : |
||||
badPart( _badPart ) |
||||
{ |
||||
dmatcher = BinaryDescriptorMatcher::createBinaryDescriptorMatcher(); |
||||
} |
||||
|
||||
protected: |
||||
static const int dim = 32; |
||||
static const int queryDescCount = 300; // must be even number because we split train data in some cases in two
|
||||
static const int countFactor = 4; // do not change it
|
||||
const float badPart; |
||||
|
||||
virtual void run( int ); |
||||
void generateData( Mat& query, Mat& train ); |
||||
uchar invertSingleBits( uchar dividend_char, int numBits ); |
||||
void emptyDataTest(); |
||||
void matchTest( const Mat& query, const Mat& train ); |
||||
void knnMatchTest( const Mat& query, const Mat& train ); |
||||
void radiusMatchTest( const Mat& query, const Mat& train ); |
||||
|
||||
std::string name; |
||||
Ptr<BinaryDescriptorMatcher> dmatcher; |
||||
|
||||
private: |
||||
CV_BinaryDescriptorMatcherTest& operator=( const CV_BinaryDescriptorMatcherTest& ) |
||||
{ |
||||
return *this; |
||||
} |
||||
|
||||
}; |
||||
|
||||
/* invert numBits bits in input char */ |
||||
uchar CV_BinaryDescriptorMatcherTest::invertSingleBits( uchar dividend_char, int numBits ) |
||||
{ |
||||
std::vector<int> bin_vector; |
||||
long dividend; |
||||
long bin_num; |
||||
|
||||
/* convert input char to a long */ |
||||
dividend = (long) dividend_char; |
||||
|
||||
/*if a 0 has been obtained, just generate a 8-bit long vector of zeros */ |
||||
if( dividend == 0 ) |
||||
bin_vector = std::vector<int>( 8, 0 ); |
||||
|
||||
/* else, apply classic decimal to binary conversion */ |
||||
else |
||||
{ |
||||
while ( dividend >= 1 ) |
||||
{ |
||||
bin_num = dividend % 2; |
||||
dividend /= 2; |
||||
bin_vector.push_back( bin_num ); |
||||
} |
||||
} |
||||
|
||||
/* ensure that binary vector always has length 8 */ |
||||
if( bin_vector.size() < 8 ) |
||||
{ |
||||
std::vector<int> zeros( 8 - bin_vector.size(), 0 ); |
||||
bin_vector.insert( bin_vector.end(), zeros.begin(), zeros.end() ); |
||||
} |
||||
|
||||
/* invert numBits bits */ |
||||
for ( int index = 0; index < numBits; index++ ) |
||||
{ |
||||
if( bin_vector[index] == 0 ) |
||||
bin_vector[index] = 1; |
||||
|
||||
else |
||||
bin_vector[index] = 0; |
||||
} |
||||
|
||||
/* reconvert to decimal */ |
||||
uchar result = 0; |
||||
for ( int i = (int) bin_vector.size() - 1; i >= 0; i-- ) |
||||
result += (uchar) ( bin_vector[i] * pow( 2, i ) ); |
||||
|
||||
return result; |
||||
} |
||||
|
||||
void CV_BinaryDescriptorMatcherTest::emptyDataTest() |
||||
{ |
||||
Mat queryDescriptors, trainDescriptors, mask; |
||||
std::vector<Mat> trainDescriptorCollection, masks; |
||||
std::vector<DMatch> matches; |
||||
std::vector<std::vector<DMatch> > vmatches; |
||||
|
||||
try |
||||
{ |
||||
dmatcher->match( queryDescriptors, trainDescriptors, matches, mask ); |
||||
} |
||||
|
||||
catch ( ... ) |
||||
{ |
||||
ts->printf( cvtest::TS::LOG, "match() on empty descriptors must not generate exception (1).\n" ); |
||||
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT ); |
||||
} |
||||
|
||||
try |
||||
{ |
||||
dmatcher->knnMatch( queryDescriptors, trainDescriptors, vmatches, 2, mask ); |
||||
} |
||||
|
||||
catch ( ... ) |
||||
{ |
||||
ts->printf( cvtest::TS::LOG, "knnMatch() on empty descriptors must not generate exception (1).\n" ); |
||||
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT ); |
||||
} |
||||
|
||||
try |
||||
{ |
||||
dmatcher->radiusMatch( queryDescriptors, trainDescriptors, vmatches, 10.f, mask ); |
||||
} |
||||
|
||||
catch ( ... ) |
||||
{ |
||||
ts->printf( cvtest::TS::LOG, "radiusMatch() on empty descriptors must not generate exception (1).\n" ); |
||||
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT ); |
||||
} |
||||
|
||||
try |
||||
{ |
||||
dmatcher->add( trainDescriptorCollection ); |
||||
} |
||||
|
||||
catch ( ... ) |
||||
{ |
||||
ts->printf( cvtest::TS::LOG, "add() on empty descriptors must not generate exception.\n" ); |
||||
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT ); |
||||
} |
||||
|
||||
try |
||||
{ |
||||
dmatcher->match( queryDescriptors, matches, masks ); |
||||
} |
||||
|
||||
catch ( ... ) |
||||
{ |
||||
ts->printf( cvtest::TS::LOG, "match() on empty descriptors must not generate exception (2).\n" ); |
||||
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT ); |
||||
} |
||||
|
||||
try |
||||
{ |
||||
dmatcher->knnMatch( queryDescriptors, vmatches, 2, masks ); |
||||
} |
||||
|
||||
catch ( ... ) |
||||
{ |
||||
ts->printf( cvtest::TS::LOG, "knnMatch() on empty descriptors must not generate exception (2).\n" ); |
||||
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT ); |
||||
} |
||||
|
||||
try |
||||
{ |
||||
dmatcher->radiusMatch( queryDescriptors, vmatches, 10.f, masks ); |
||||
} |
||||
|
||||
catch ( ... ) |
||||
{ |
||||
ts->printf( cvtest::TS::LOG, "radiusMatch() on empty descriptors must not generate exception (2).\n" ); |
||||
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT ); |
||||
} |
||||
|
||||
} |
||||
|
||||
void CV_BinaryDescriptorMatcherTest::generateData( Mat& query, Mat& train ) |
||||
{ |
||||
RNG& rng = theRNG(); |
||||
|
||||
/* Generate query descriptors randomly.
|
||||
Descriptor vector elements are binary values. */ |
||||
Mat buf( queryDescCount, dim, CV_8UC1 ); |
||||
rng.fill( buf, RNG::UNIFORM, Scalar( 0 ), Scalar( 255 ) ); |
||||
buf.convertTo( query, CV_8UC1 ); |
||||
|
||||
for ( int i = 0; i < query.rows; i++ ) |
||||
{ |
||||
for ( int j = 0; j < countFactor; j++ ) |
||||
{ |
||||
train.push_back( query.row( i ) ); |
||||
int randCol = rand() % 32; |
||||
uchar u = query.at<uchar>( i, randCol ); |
||||
uchar modified_u = invertSingleBits( u, j + 1 ); |
||||
train.at<uchar>( i * countFactor + j, randCol ) = modified_u; |
||||
} |
||||
} |
||||
} |
||||
|
||||
void CV_BinaryDescriptorMatcherTest::matchTest( const Mat& query, const Mat& train ) |
||||
{ |
||||
dmatcher->clear(); |
||||
|
||||
// test const version of match()
|
||||
{ |
||||
std::vector<DMatch> matches; |
||||
dmatcher->match( query, train, matches ); |
||||
|
||||
if( (int) matches.size() != queryDescCount ) |
||||
{ |
||||
ts->printf( cvtest::TS::LOG, "Incorrect matches count while test match() function (1).\n" ); |
||||
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT ); |
||||
} |
||||
|
||||
else |
||||
{ |
||||
int badCount = 0; |
||||
for ( size_t i = 0; i < matches.size(); i++ ) |
||||
{ |
||||
DMatch& match = matches[i]; |
||||
if( ( match.queryIdx != (int) i ) || ( match.trainIdx != (int) i * countFactor ) || ( match.imgIdx != 0 ) ) |
||||
badCount++; |
||||
} |
||||
if( (float) badCount > (float) queryDescCount * badPart ) |
||||
{ |
||||
ts->printf( cvtest::TS::LOG, "%f - too large bad matches part while test match() function (1).\n", |
||||
(float) badCount / (float) queryDescCount ); |
||||
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT ); |
||||
} |
||||
} |
||||
} |
||||
|
||||
// test const version of match() for the same query and test descriptors
|
||||
{ |
||||
std::vector<DMatch> matches; |
||||
dmatcher->match( query, query, matches ); |
||||
|
||||
if( (int) matches.size() != query.rows ) |
||||
{ |
||||
ts->printf( cvtest::TS::LOG, "Incorrect matches count while test match() function for the same query and test descriptors (1).\n" ); |
||||
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT ); |
||||
} |
||||
else |
||||
{ |
||||
for ( size_t i = 0; i < matches.size(); i++ ) |
||||
{ |
||||
DMatch& match = matches[i]; |
||||
if( match.queryIdx != (int) i || match.trainIdx != (int) i || std::abs( match.distance ) > FLT_EPSILON ) |
||||
{ |
||||
ts->printf( |
||||
cvtest::TS::LOG, |
||||
"Bad match (i=%d, queryIdx=%d, trainIdx=%d, distance=%f) while test match() function for the same query and test descriptors (1).\n", i, |
||||
match.queryIdx, match.trainIdx, match.distance ); |
||||
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT ); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
// test version of match() with add()
|
||||
{ |
||||
dmatcher->clear(); |
||||
std::vector<DMatch> matches; |
||||
|
||||
// make add() twice to test such case
|
||||
dmatcher->add( std::vector<Mat>( 1, train.rowRange( 0, train.rows / 2 ) ) ); |
||||
dmatcher->add( std::vector<Mat>( 1, train.rowRange( train.rows / 2, train.rows ) ) ); |
||||
|
||||
// prepare masks (make first nearest match illegal)
|
||||
std::vector<Mat> masks( 2 ); |
||||
for ( int mi = 0; mi < 2; mi++ ) |
||||
masks[mi] = Mat::ones( query.rows, 1/*train.rows / 2*/, CV_8UC1 ); |
||||
|
||||
dmatcher->match( query, matches, masks ); |
||||
if( (int) matches.size() != queryDescCount ) |
||||
{ |
||||
ts->printf( cvtest::TS::LOG, "Incorrect matches count while test match() function (2).\n" ); |
||||
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT ); |
||||
} |
||||
|
||||
else |
||||
{ |
||||
int badCount = 0; |
||||
for ( size_t i = 0; i < matches.size(); i++ ) |
||||
{ |
||||
DMatch& match = matches[i]; |
||||
|
||||
if( ( match.queryIdx != (int) i ) || ( match.trainIdx != (int) i * countFactor /*+ shift*/) || ( match.imgIdx > 1 ) ) |
||||
badCount++; |
||||
} |
||||
|
||||
if( (float) badCount > (float) queryDescCount * badPart ) |
||||
{ |
||||
ts->printf( cvtest::TS::LOG, "%f - too large bad matches part while test match() function (2).\n", |
||||
(float) badCount / (float) queryDescCount ); |
||||
ts->set_failed_test_info( cvtest::TS::FAIL_BAD_ACCURACY ); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
void CV_BinaryDescriptorMatcherTest::knnMatchTest( const Mat& query, const Mat& train ) |
||||
{ |
||||
dmatcher->clear(); |
||||
|
||||
// test const version of knnMatch()
|
||||
{ |
||||
const int knn = 3; |
||||
|
||||
std::vector<std::vector<DMatch> > matches; |
||||
dmatcher->knnMatch( query, train, matches, knn ); |
||||
|
||||
if( (int) matches.size() != queryDescCount ) |
||||
{ |
||||
ts->printf( cvtest::TS::LOG, "Incorrect matches count while test knnMatch() function (1).\n" ); |
||||
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT ); |
||||
} |
||||
|
||||
else |
||||
{ |
||||
int badCount = 0; |
||||
for ( size_t i = 0; i < matches.size(); i++ ) |
||||
{ |
||||
if( (int) matches[i].size() != knn ) |
||||
badCount++; |
||||
|
||||
else |
||||
{ |
||||
int localBadCount = 0; |
||||
for ( int k = 0; k < knn; k++ ) |
||||
{ |
||||
DMatch& match = matches[i][k]; |
||||
if( ( match.queryIdx != (int) i ) || ( match.trainIdx != (int) i * countFactor + k ) || ( match.imgIdx != 0 ) ) |
||||
localBadCount++; |
||||
} |
||||
badCount += localBadCount > 0 ? 1 : 0; |
||||
} |
||||
|
||||
} |
||||
|
||||
if( (float) badCount > (float) queryDescCount * badPart ) |
||||
{ |
||||
ts->printf( cvtest::TS::LOG, "%f - too large bad matches part while test knnMatch() function (1).\n", |
||||
(float) badCount / (float) queryDescCount ); |
||||
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT ); |
||||
} |
||||
} |
||||
} |
||||
|
||||
// // test version of knnMatch() with add()
|
||||
{ |
||||
const int knn = 2; |
||||
std::vector<std::vector<DMatch> > matches; |
||||
|
||||
// make add() twice to test such case
|
||||
dmatcher->add( std::vector<Mat>( 1, train.rowRange( 0, train.rows / 2 ) ) ); |
||||
dmatcher->add( std::vector<Mat>( 1, train.rowRange( train.rows / 2, train.rows ) ) ); |
||||
|
||||
// prepare masks (make first nearest match illegal)
|
||||
std::vector<Mat> masks( 2 ); |
||||
for ( int mi = 0; mi < 2; mi++ ) |
||||
{ |
||||
masks[mi] = Mat::ones( query.rows, 1, CV_8UC1 ); |
||||
} |
||||
|
||||
dmatcher->knnMatch( query, matches, knn, masks ); |
||||
|
||||
if( (int) matches.size() != queryDescCount ) |
||||
{ |
||||
ts->printf( cvtest::TS::LOG, "Incorrect matches count while test knnMatch() function (2).\n" ); |
||||
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT ); |
||||
} |
||||
|
||||
else |
||||
{ |
||||
int badCount = 0; |
||||
for ( size_t i = 0; i < matches.size(); i++ ) |
||||
{ |
||||
if( (int) matches[i].size() != knn ) |
||||
badCount++; |
||||
|
||||
else |
||||
{ |
||||
int localBadCount = 0; |
||||
for ( int k = 0; k < knn; k++ ) |
||||
{ |
||||
DMatch& match = matches[i][k]; |
||||
{ |
||||
if( i < queryDescCount / 2 ) |
||||
{ |
||||
if( ( match.queryIdx != (int) i ) || ( match.trainIdx != (int) i * countFactor + k ) || ( match.imgIdx != 0 ) ) |
||||
localBadCount++; |
||||
} |
||||
|
||||
else |
||||
{ |
||||
if( ( match.queryIdx != (int) i ) || ( match.trainIdx != (int) i * countFactor + k ) || ( match.imgIdx != 1 ) ) |
||||
localBadCount++; |
||||
} |
||||
} |
||||
} |
||||
|
||||
badCount += localBadCount > 0 ? 1 : 0; |
||||
} |
||||
} |
||||
|
||||
if( (float) badCount > (float) queryDescCount * badPart ) |
||||
{ |
||||
ts->printf( cvtest::TS::LOG, "%f - too large bad matches part while test knnMatch() function (2).\n", |
||||
(float) badCount / (float) queryDescCount ); |
||||
ts->set_failed_test_info( cvtest::TS::FAIL_BAD_ACCURACY ); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
void CV_BinaryDescriptorMatcherTest::radiusMatchTest( const Mat& query, const Mat& train ) |
||||
{ |
||||
dmatcher->clear(); |
||||
// test const version of match()
|
||||
{ |
||||
const float radius = 1; |
||||
std::vector<std::vector<DMatch> > matches; |
||||
dmatcher->radiusMatch( query, train, matches, radius ); |
||||
|
||||
if( (int) matches.size() != queryDescCount ) |
||||
{ |
||||
ts->printf( cvtest::TS::LOG, "Incorrect matches count while test radiusMatch() function (1).\n" ); |
||||
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT ); |
||||
} |
||||
else |
||||
{ |
||||
int badCount = 0; |
||||
for ( size_t i = 0; i < matches.size(); i++ ) |
||||
{ |
||||
|
||||
if( (int) matches[i].size() != 1 ) |
||||
{ |
||||
badCount++; |
||||
} |
||||
|
||||
else |
||||
{ |
||||
DMatch& match = matches[i][0]; |
||||
if( ( match.queryIdx != (int) i ) || ( match.trainIdx != (int) i * countFactor ) || ( match.imgIdx != 0 ) ) |
||||
badCount++; |
||||
} |
||||
} |
||||
|
||||
if( (float) badCount > (float) queryDescCount * badPart ) |
||||
{ |
||||
ts->printf( cvtest::TS::LOG, "%f - too large bad matches part while test radiusMatch() function (1).\n", |
||||
(float) badCount / (float) queryDescCount ); |
||||
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT ); |
||||
} |
||||
} |
||||
} |
||||
|
||||
{ |
||||
const float radius = 3; |
||||
std::vector<std::vector<DMatch> > matches; |
||||
// make add() twice to test such case
|
||||
dmatcher->add( std::vector<Mat>( 1, train.rowRange( 0, train.rows / 2 ) ) ); |
||||
dmatcher->add( std::vector<Mat>( 1, train.rowRange( train.rows / 2, train.rows ) ) ); |
||||
|
||||
// prepare masks
|
||||
std::vector<Mat> masks( 2 ); |
||||
for ( int mi = 0; mi < 2; mi++ ) |
||||
masks[mi] = Mat::ones( query.rows, 1, CV_8UC1 ); |
||||
|
||||
dmatcher->radiusMatch( query, matches, radius, masks ); |
||||
|
||||
//int curRes = cvtest::TS::OK;
|
||||
if( (int) matches.size() != queryDescCount ) |
||||
{ |
||||
ts->printf( cvtest::TS::LOG, "Incorrect matches count while test radiusMatch() function (1).\n" ); |
||||
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT ); |
||||
} |
||||
|
||||
int badCount = 0; |
||||
for ( size_t i = 0; i < matches.size(); i++ ) |
||||
{ |
||||
if( (int) matches[i].size() != radius ) |
||||
badCount++; |
||||
|
||||
else |
||||
{ |
||||
int localBadCount = 0; |
||||
for ( int k = 0; k < radius; k++ ) |
||||
{ |
||||
DMatch& match = matches[i][k]; |
||||
{ |
||||
if( i < queryDescCount / 2 ) |
||||
{ |
||||
if( ( match.queryIdx != (int) i ) || ( match.trainIdx != (int) i * countFactor + k ) || ( match.imgIdx != 0 ) ) |
||||
localBadCount++; |
||||
} |
||||
|
||||
else |
||||
{ |
||||
if( ( match.queryIdx != (int) i ) || ( match.trainIdx != (int) i * countFactor + k ) || ( match.imgIdx != 1 ) ) |
||||
localBadCount++; |
||||
} |
||||
} |
||||
} |
||||
|
||||
badCount += localBadCount > 0 ? 1 : 0; |
||||
} |
||||
} |
||||
|
||||
if( (float) badCount > (float) queryDescCount * badPart ) |
||||
{ |
||||
//curRes = cvtest::TS::FAIL_INVALID_OUTPUT;
|
||||
ts->printf( cvtest::TS::LOG, "%f - too large bad matches part while test radiusMatch() function (2).\n", |
||||
(float) badCount / (float) queryDescCount ); |
||||
ts->set_failed_test_info( cvtest::TS::FAIL_BAD_ACCURACY ); |
||||
} |
||||
} |
||||
} |
||||
|
||||
void CV_BinaryDescriptorMatcherTest::run( int ) |
||||
{ |
||||
Mat query, train; |
||||
emptyDataTest(); |
||||
generateData( query, train ); |
||||
matchTest( query, train ); |
||||
knnMatchTest( query, train ); |
||||
radiusMatchTest( query, train ); |
||||
} |
||||
|
||||
/****************************************************************************************\
|
||||
* Tests registrations * |
||||
\****************************************************************************************/ |
||||
|
||||
TEST( BinaryDescriptor_Matcher, regression) |
||||
{ |
||||
CV_BinaryDescriptorMatcherTest test( 0.01f ); |
||||
test.safe_run(); |
||||
} |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue