Skip to content

Commit

Permalink
svf demo
Browse files Browse the repository at this point in the history
  • Loading branch information
willard-yuan committed Jul 3, 2022
1 parent b0a1f42 commit e6849da
Show file tree
Hide file tree
Showing 15 changed files with 97 additions and 582 deletions.
69 changes: 69 additions & 0 deletions correspondence_matching/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
cmake_minimum_required(VERSION 2.8)
project(correspondence_matching_pro)

set(CMAKE_C_FLAGS "-m64")
set(CMAKE_CXX_FLAGS "-std=c++11 -m64")
#set(LIB_DIR "/opt/local/lib")

set(CMAKE_CXX_FLAGS "-std=c++11 -fno-operator-names")

option(USE_SIMD_SSE2 "Enable SSE2 optimizations" OFF)
option(USE_SIMD_SSE3 "Enable SSE3 optimizations" OFF)
option(USE_SIMD_SSSE3 "Enable SSSE3 optimizations" OFF)
option(USE_SIMD_SSE4_1 "Enable SSE 4.1 optimizations" ON)
option(USE_SIMD_SSE4_2 "Enable SSE 4.2 optimizations" ON)
option(USE_SIMD_AVX "Enable AVX optimizations" ON)
option(USE_SIMD_AVX2 "Enable AVX2 optimizations" ON)

find_package(OpenMP)
if (OPENMP_FOUND)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif()

if (USE_SIMD_SSE4_1)
add_definitions(-DUSE_SSE)
message(STATUS "Use SSE")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.1")
endif()

if (USE_SIMD_AVX2)
add_definitions(-DGLM_FORCE_PURE)
if((CMAKE_CXX_COMPILER_ID MATCHES "GNU") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
add_compile_options(-mavx2)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Intel")
add_compile_options(/QxAVX2)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
add_compile_options(/arch:AVX2)
endif()
endif()

#set(CUDA_TOOLKIT_ROOT_DIR "/usr/local/cuda")
#set(CUDA_INCLUDE_DIR "/usr/local/cuda/include")
#set(CUDA_LIBRARY "/usr/local/cuda/lib64")

set(OpenCV_DIR "/Users/willard/libs/opencv/4.6.0/lib/cmake/opencv4")
option( OpenCV_STATIC OFF )
find_package(OpenCV REQUIRED)

link_directories( ${OpenCV_LIB_DIR} )
include_directories(${OpenCV_INCLUDE_DIRS})

message(STATUS "OpenCV library status:")
message(STATUS " config: ${OpenCV_DIR}")
message(STATUS " version: ${OpenCV_VERSION}")
message(STATUS " libraries: ${OpenCV_LIBS}")
message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")

#set(Faiss_INCLUDE_DIRS "/raid/yuanyong/libs/faiss-1.5.3-build/include")
#set(Faiss_LIBS_DIRS "/raid/yuanyong/libs/faiss-1.5.3-build/lib/libfaiss.so")
#include_directories(${Faiss_INCLUDE_DIRS})

file(GLOB correspondence_matching_files
"./include/svf.h"
"./src/svf.cc"
"./examples/opencv_sift_matching.cc"
)

add_executable(correspondence_matching_demo ${correspondence_matching_files})
target_link_libraries(correspondence_matching_demo ${OpenCV_LIBS})
Binary file added correspondence_matching/data/pattern.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added correspondence_matching/data/query.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added correspondence_matching/examples/.DS_Store
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@

#include <stdio.h>
#include <time.h>
#include <glob.h>
#include "svf.hpp"
#include "../include/svf.h"

uint64_t constexpr mix(char m, uint64_t s)
{
Expand All @@ -15,18 +14,19 @@ uint64_t constexpr hash(const char * m)
}

int main(int argc, char** argv) {

const char* method = "1nn";
float siftRatio = 0.85;
float sift_near_thresh = 0.65;
sift_near_thresh *= 512*512*sift_near_thresh;
bool removeRepeat = true;
bool useRootSIFT = true;

cv::Ptr<cv::Feature2D> detector = cv::xfeatures2d::SIFT::create();

cv::Ptr<cv::SIFT> detector = cv::SIFT::create();
//cv::Ptr<cv::AffineFeature> detector = cv::AffineFeature::create(raw_detector);
cv::FlannBasedMatcher siftMatcher;
cv::Mat im1 = cv::imread("/Users/willard/svf/50521531988253_.pic.jpg", 1);

cv::Mat im1 = cv::imread("../data/query.jpg", 1);
if (im1.empty()) return 0;
std::vector<cv::KeyPoint> kpts1;
cv::Mat img1Descs;
Expand All @@ -37,7 +37,7 @@ int main(int argc, char** argv) {
}
detector->compute(im1, kpts1, img1Descs);

cv::Mat im2 = cv::imread("/Users/willard/svf/50531531988253_.pic.jpg", 1);
cv::Mat im2 = cv::imread("../data/pattern.jpg", 1);
if (im2.empty()) return 0;
std::vector<cv::KeyPoint> kpts2;
cv::Mat img2Descs;
Expand All @@ -47,17 +47,17 @@ int main(int argc, char** argv) {
return 0;
}
detector->compute(im2, kpts2, img2Descs);

if (useRootSIFT){
rootSift(img1Descs);
rootSift(img2Descs);
rootSift(img1Descs, 1e-7);
rootSift(img2Descs, 1e-7);
}

// 几何重排
std::vector<std::vector<cv::DMatch>> matches;
std::vector<cv::DMatch> goodMatches2;
siftMatcher.knnMatch(img1Descs, img2Descs, matches, 2);
for (size_t i = 0; i < matches.size(); i++){
for (size_t i = 0; i < matches.size(); i++) {
switch(hash(method))
{
case hash("1nn"):
Expand All @@ -71,12 +71,14 @@ int main(int argc, char** argv) {
}
}
std::vector<cv::DMatch> refineMatches = getInliers(kpts1, kpts2, goodMatches2, removeRepeat);

cv::Mat img_matches;
cv::drawMatches(im1, kpts1, im2, kpts2, refineMatches, img_matches);
//cv::resize(img_matches, img_matches, cv::Size(int(0.5*img_matches.rows), int(0.5*img_matches.cols)));
const cv::Scalar matchColor = cv::Scalar(0, 255, 0);
const cv::Scalar singlePointColor = cv::Scalar(0, 0, 255);
cv::drawMatches(im1, kpts1, im2, kpts2, refineMatches, img_matches, matchColor, singlePointColor);
cv::resize(img_matches, img_matches, cv::Size(int(0.8*img_matches.rows), int(0.8*img_matches.cols)));
cv::imshow("match", img_matches);
cv::waitKey();

return 0;
}
Binary file added correspondence_matching/include/.DS_Store
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@

#ifndef svf_hpp
#define svf_hpp
#pragma once

#include <stdio.h>

#include <opencv2/opencv.hpp>
#include <opencv2/features2d.hpp>
#include <opencv2/xfeatures2d/nonfree.hpp>

typedef unsigned char uint8;

std::vector<cv::DMatch> getInliers(std::vector<cv::KeyPoint> &qKpts1, std::vector<cv::KeyPoint> &qKpts2, std::vector<cv::DMatch> &rawMatches, bool removeRepeat);
int spaceValidate(const cv::KeyPoint &pa0, const cv::KeyPoint &pa1, const cv::KeyPoint &pb0, const cv::KeyPoint &pb1);
std::vector<cv::DMatch> getInliers(std::vector<cv::KeyPoint> &qKpts1,
std::vector<cv::KeyPoint> &qKpts2, std::vector<cv::DMatch> &rawMatches,
bool removeRepeat);
int spaceValidate(const cv::KeyPoint &pa0,
const cv::KeyPoint &pa1, const cv::KeyPoint &pb0, const cv::KeyPoint &pb1);
uint8 getSiteCode(int height, int width, cv::Point2f pt);
int getGlobalFeature(cv::Mat img, std::vector<float> &fea);
float distanceL2(const std::vector<float> &x, const std::vector<float> &y);
float distanceL2(const cv::KeyPoint &x, const cv::KeyPoint &y);
void rootSift(cv::Mat &descriptors, const float eps = 1e-7);

#endif /* svf_hpp */
58 changes: 0 additions & 58 deletions correspondence_matching/opencv_sift_matching_array.cpp

This file was deleted.

113 changes: 0 additions & 113 deletions correspondence_matching/siftsIndex.cpp

This file was deleted.

Loading

0 comments on commit e6849da

Please sign in to comment.