This commit is contained in:
Thomas FORGIONE 2015-03-15 16:48:42 +01:00
parent 794c95ad33
commit 4e858b20ee
11 changed files with 152 additions and 95 deletions

View File

@ -30,6 +30,15 @@
#ifndef DETECTIONANDMATCHING_HPP
#define DETECTIONANDMATCHING_HPP
#include <vector>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <opencv2/nonfree/features2d.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/calib3d/calib3d.hpp>
/////////////////////////////////////////////////////////
/// \defgroup detectionandmatching Detection and Matching module
///

View File

@ -35,12 +35,6 @@
#include "Geometry/Vector.hpp"
#include "Geometry/MathFunctions.hpp"
// Forward declaration of cv::Point
namespace cv
{
}
namespace geo
{
@ -92,8 +86,8 @@ struct vector_size<Vector<T,N>>
static constexpr std::size_t value = N;
};
template<>
struct vector_size<cv::Point2f>
template<typename T>
struct vector_size<cv::Point_<T>>
{
static constexpr std::size_t value = 2;
};

View File

@ -205,7 +205,7 @@ class Skeleton
/// \param branches1
/// \param branches2
////////////////////////////////////////////////////////////////////////
friend couples<unsigned int> branchesMatching(couples<cv::KeyPoint> const& keypoints,
friend couples<unsigned int> branchesMatching(couples<cv::Point> const& keypoints,
Skeleton branches1,
Skeleton branches2
);
@ -253,7 +253,7 @@ class Skeleton
/// \param branches The list of branches in which we look for the
/// nearest branche to associate the keypoint
////////////////////////////////////////////////////////////////////////
unsigned int searchNearestBrancheIndex(cv::KeyPoint const& keypoint,
unsigned int searchNearestBrancheIndex(cv::Point const& keypoint,
Skeleton branches
);

View File

@ -1,3 +1,6 @@
add_executable(DetectionAndMatching DetectionAndMatching.cpp)
target_link_libraries(DetectionAndMatching ${OpenCV_LIBS})
add_library(DetectionAndMatching DetectionAndMatching.cpp)
add_executable(DetectionMain main.cpp)
target_link_libraries(DetectionMain DetectionAndMatching ${OpenCV_LIBS})

View File

@ -41,50 +41,6 @@
#include "DetectionAndMatching/DetectionAndMatching.hpp"
int main( int argc, char** argv )
{
cv::Mat img_1;
cv::Mat img_2;
cv::Mat masque_1;
cv::Mat masque_2;
cv::Size s1;
cv::Size s2;
if( argc != 5 )
{
if (argc==3) {
img_1 = cv::imread( argv[1], CV_LOAD_IMAGE_GRAYSCALE );
img_2 = cv::imread( argv[2], CV_LOAD_IMAGE_GRAYSCALE );
s1 = img_1.size();
s2 = img_2.size();
masque_1 = cv::Mat::ones(s1.height,s1.width, CV_8UC1);
masque_2 = cv::Mat::ones(s2.height,s2.width, CV_8UC1);
} else {
readme(); return -1;
}
}
if (argc!=3)
{
img_1 = cv::imread( argv[1], CV_LOAD_IMAGE_GRAYSCALE );
img_2 = cv::imread( argv[2], CV_LOAD_IMAGE_GRAYSCALE );
masque_1 = cv::imread( argv[3], CV_LOAD_IMAGE_GRAYSCALE );
masque_2 = cv::imread( argv[4], CV_LOAD_IMAGE_GRAYSCALE );
}
//std::cout << masque_1 << std::endl;
if( !img_1.data || !img_2.data )
{ std::cout<< " --(!) Error reading images " << std::endl; return -1; }
std::vector<std::pair<cv::Point, cv::Point>> matchPoints;
cv::Mat masque_1_resize = resizeMask(masque_1,img_1.size());
cv::Mat masque_2_resize = resizeMask(masque_2,img_2.size());
matchPoints = detectAndMatch(img_1, img_2, masque_1_resize, masque_2_resize);
return 0;
}
std::vector<std::pair<cv::Point,cv::Point>> detectAndMatch(cv::Mat const& img_1, cv::Mat const& img_2, cv::Mat const& masque_1, cv::Mat const& masque_2)
{
//-- Step 1: Detect the keypoints using BRISK Detector

View File

@ -0,0 +1,91 @@
////////////////////////////////////////////////////////////////////////////////
//
// Paella
// Copyright (C) 2015 - Thomas FORGIONE, Emilie JALRAS, Marion LENFANT, Thierry MALON, Amandine PAILLOUX
// Authors :
// Thomas FORGIONE
// Emilie JALRAS
// Marion LENFANT
// Thierry MALON
// Amandine PAILLOUX
//
// This file is part of the project Paella
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
////////////////////////////////////////////////////////////////////////////////
#include "DetectionAndMatching/DetectionAndMatching.hpp"
#include <iostream>
#include <vector>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <opencv2/nonfree/features2d.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/calib3d/calib3d.hpp>
int main( int argc, char** argv )
{
cv::Mat img_1;
cv::Mat img_2;
cv::Mat masque_1;
cv::Mat masque_2;
cv::Size s1;
cv::Size s2;
if( argc != 5 )
{
if (argc==3) {
img_1 = cv::imread( argv[1], CV_LOAD_IMAGE_GRAYSCALE );
img_2 = cv::imread( argv[2], CV_LOAD_IMAGE_GRAYSCALE );
s1 = img_1.size();
s2 = img_2.size();
masque_1 = cv::Mat::ones(s1.height,s1.width, CV_8UC1);
masque_2 = cv::Mat::ones(s2.height,s2.width, CV_8UC1);
} else {
readme(); return -1;
}
}
if (argc!=3)
{
img_1 = cv::imread( argv[1], CV_LOAD_IMAGE_GRAYSCALE );
img_2 = cv::imread( argv[2], CV_LOAD_IMAGE_GRAYSCALE );
masque_1 = cv::imread( argv[3], CV_LOAD_IMAGE_GRAYSCALE );
masque_2 = cv::imread( argv[4], CV_LOAD_IMAGE_GRAYSCALE );
}
//std::cout << masque_1 << std::endl;
if( !img_1.data || !img_2.data )
{
std::cout<< " --(!) Error reading images " << std::endl;
return -1;
}
std::vector<std::pair<cv::Point, cv::Point>> matchPoints;
cv::Mat masque_1_resize = resizeMask(masque_1,img_1.size());
cv::Mat masque_2_resize = resizeMask(masque_2,img_2.size());
matchPoints = detectAndMatch(img_1, img_2, masque_1_resize, masque_2_resize);
return 0;
}

View File

@ -4,4 +4,4 @@ add_executable(SkeletonDrawing draw.cpp)
target_link_libraries(SkeletonDrawing ${SFML_LIBRARIES} ${OPENGL_LIBRARIES} SFMLTools Skeleton2D)
add_executable(Skeleton main.cpp)
target_link_libraries(Skeleton SFMLTools Skeleton2D ${OPENGL_LIBRARIES} ${OpenCV_LIBRARIES} ${Boost_LIBRARIES})
target_link_libraries(Skeleton SFMLTools Skeleton2D DetectionAndMatching ${OPENGL_LIBRARIES} ${OpenCV_LIBRARIES} ${Boost_LIBRARIES})

View File

@ -262,7 +262,7 @@ std::vector<unsigned int> Skeleton::findOnes(std::vector<std::vector<bool>> cons
return onesPosition;
}
std::vector<std::pair<unsigned int,unsigned int>> branchesMatching(std::vector<std::pair<cv::KeyPoint,cv::KeyPoint>> const& keypoints, Skeleton branches1, Skeleton branches2)
std::vector<std::pair<unsigned int,unsigned int>> branchesMatching(std::vector<std::pair<cv::Point,cv::Point>> const& keypoints, Skeleton branches1, Skeleton branches2)
{
std::vector<std::pair<unsigned int,unsigned int>> matchingBranches;
@ -351,7 +351,7 @@ std::vector<std::pair<unsigned int,unsigned int>> branchesMatching(std::vector<s
return matchingBranches;
}
unsigned int Skeleton::searchNearestBrancheIndex(cv::KeyPoint const& keypoint, Skeleton branches)
unsigned int Skeleton::searchNearestBrancheIndex(cv::Point const& keypoint, Skeleton branches)
{
unsigned int nearest_branche_index = 0;
float shortest_distance = std::numeric_limits<float>::max();
@ -367,7 +367,7 @@ unsigned int Skeleton::searchNearestBrancheIndex(cv::KeyPoint const& keypoint, S
{
// We compute the coordinates of the projection of the keypoint on each edge
float d_keypoint_edge = geo::distanceToSegment(
keypoint.pt,
keypoint,
// m_vertices[m_edges[branche[k]].x()],
// m_vertices[m_edges[branche[k]].y()]
geo::Vector<float,2>{m_vertices.at(branche.at(k)).x(),

View File

@ -38,6 +38,8 @@
#include <GL/glu.h>
#include <SFMLTools/FreeFlyCamera.hpp>
// Yes, this is a uggly hack... I need it to make this test work
#define private public
#include <Skeleton/Skeleton.hpp>
#undef private

View File

@ -27,36 +27,35 @@
//
// 3. This notice may not be removed or altered from any source distribution.
////////////////////////////////////////////////////////////////////////////////
std::vector<std::pair<cv::KeyPoint,cv::KeyPoint>> keypoints1 = {
// Pairs of keypoints supposed to be matched with branche[0]
{cv::KeyPoint{cv::Point{100,400},0}, cv::KeyPoint{cv::Point{400,400},0}},
{cv::KeyPoint{cv::Point{200,200},0}, cv::KeyPoint{cv::Point{400,300},0}},
{cv::KeyPoint{cv::Point{400,400},0}, cv::KeyPoint{cv::Point{500,300},0}},
{cv::KeyPoint{cv::Point{300,600},0}, cv::KeyPoint{cv::Point{500,600},0}},
{cv::KeyPoint{cv::Point{100,400},0}, cv::KeyPoint{cv::Point{500,300},0}},
// Pairs of keypoints supposed to be matched with branches[1]
{cv::KeyPoint{cv::Point{700,300},0}, cv::KeyPoint{cv::Point{650,400},0}},
{cv::KeyPoint{cv::Point{900,200},0}, cv::KeyPoint{cv::Point{700,200},0}},
{cv::KeyPoint{cv::Point{1100,400},0}, cv::KeyPoint{cv::Point{900,300},0}},
{cv::KeyPoint{cv::Point{1000,600},0}, cv::KeyPoint{cv::Point{800,500},0}},
{cv::KeyPoint{cv::Point{800,600},0}, cv::KeyPoint{cv::Point{700,600},0}},
// Pairs of keypoints supposed to be matched with branches[2]
{cv::KeyPoint{cv::Point{400,800},0}, cv::KeyPoint{cv::Point{500,800},0}},
{cv::KeyPoint{cv::Point{600,700},0}, cv::KeyPoint{cv::Point{700,700},0}},
{cv::KeyPoint{cv::Point{700,900},0}, cv::KeyPoint{cv::Point{750,900},0}},
// Pairs of keypoints supposed to be matched with branches[3]
{cv::KeyPoint{cv::Point{300,1000},0}, cv::KeyPoint{cv::Point{400,1000},0}},
{cv::KeyPoint{cv::Point{100,1100},0}, cv::KeyPoint{cv::Point{300,1100},0}},
{cv::KeyPoint{cv::Point{300,1200},0}, cv::KeyPoint{cv::Point{500,1100},0}},
// Pairs of keypoints supposed to be matched with branches[4]
{cv::KeyPoint{cv::Point{1000,1100},0}, cv::KeyPoint{cv::Point{900,1100},0}},
{cv::KeyPoint{cv::Point{1100,1300},0}, cv::KeyPoint{cv::Point{1000,1300},0}},
{cv::KeyPoint{cv::Point{900,1400},0}, cv::KeyPoint{cv::Point{900,1400},0}},
// {cv::KeyPoint{cv::Point{800,1200},0}, cv::KeyPoint{cv::Point{800,1200},0}},
{cv::KeyPoint{cv::Point{800,1200},0}, cv::KeyPoint{cv::Point{670,1200},0}},
// Pairs of keypoints supposed to be matched with branches[5]
{cv::KeyPoint{cv::Point{500,1100},0}, cv::KeyPoint{cv::Point{600,1100},0}},
{cv::KeyPoint{cv::Point{400,1300},0}, cv::KeyPoint{cv::Point{500,1300},0}},
{cv::KeyPoint{cv::Point{600,1400},0}, cv::KeyPoint{cv::Point{700,1400},0}},
{cv::KeyPoint{cv::Point{400,1500},0}, cv::KeyPoint{cv::Point{500,1500},0}}
std::vector<std::pair<cv::Point,cv::Point>> keypoints1 = {
{cv::Point{100,400}, cv::Point{400,400}},
{cv::Point{200,200}, cv::Point{400,300}},
{cv::Point{400,400}, cv::Point{500,300}},
{cv::Point{300,600}, cv::Point{500,600}},
{cv::Point{100,400}, cv::Point{500,300}},
{cv::Point{700,300}, cv::Point{650,400}},
{cv::Point{900,200}, cv::Point{700,200}},
{cv::Point{1100,400}, cv::Point{900,300}},
{cv::Point{1000,600}, cv::Point{800,500}},
{cv::Point{800,600}, cv::Point{700,600}},
{cv::Point{400,800}, cv::Point{500,800}},
{cv::Point{600,700}, cv::Point{700,700}},
{cv::Point{700,900}, cv::Point{750,900}},
{cv::Point{300,1000}, cv::Point{400,1000}},
{cv::Point{100,1100}, cv::Point{300,1100}},
{cv::Point{300,1200}, cv::Point{500,1100}},
{cv::Point{1000,1100}, cv::Point{900,1100}},
{cv::Point{1100,1300}, cv::Point{1000,1300}},
{cv::Point{900,1400}, cv::Point{900,1400}},
{cv::Point{800,1200}, cv::Point{670,1200}},
{cv::Point{500,1100}, cv::Point{600,1100}},
{cv::Point{400,1300}, cv::Point{500,1300}},
{cv::Point{600,1400}, cv::Point{700,1400}},
{cv::Point{400,1500}, cv::Point{500,1500}}
};

View File

@ -38,6 +38,7 @@
#include <opencv2/highgui/highgui.hpp>
#include "Skeleton/Skeleton.hpp"
#include "DetectionAndMatching/DetectionAndMatching.hpp"
// std::pair<bool, bool>
// first is true if program should continue
@ -142,12 +143,14 @@ int main(int argc, char *argv[])
std::ofstream file{output};
// Compute the keypoints
auto keypoints = detectAndMatch(img1, img2, mask1, mask2);
// Match the branches of skeletons
// matching = branchesMatching(keypoints, skl1, skl2);
auto matching = branchesMatching(keypoints, skl1, skl2);
// Write to file
// for (auto const& pair : matching)
// file << "m " << pair.first << " " << pair.second << "\n";
for (auto const& pair : matching)
file << "m " << pair.first << " " << pair.second << "\n";
return 0;
}