Skip to content

Commit

Permalink
Merge pull request #2 from ducha-aiki/ORB
Browse files Browse the repository at this point in the history
Orb
  • Loading branch information
ducha-aiki authored Aug 8, 2018
2 parents 5a9818c + 2e45b48 commit f952079
Show file tree
Hide file tree
Showing 8 changed files with 721 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ TARGET_LINK_LIBRARIES(synth-detection matching mser affinedetectors helpers ${Op
add_executable(mods mods.cpp correspondencebank.cpp imagerepresentation.cpp io_mods.cpp)
TARGET_LINK_LIBRARIES(mods inih matching synth-detection mser affinedetectors ${OpenCV_LIBS} zmq)

add_executable(mods-with-mask mods-with-mask.cpp correspondencebank.cpp imagerepresentation.cpp io_mods.cpp)
TARGET_LINK_LIBRARIES(mods-with-mask inih matching synth-detection mser affinedetectors ${OpenCV_LIBS} zmq)


add_executable(extract_features extract_features.cpp correspondencebank.cpp imagerepresentation.cpp io_mods.cpp)
TARGET_LINK_LIBRARIES(extract_features inih matching synth-detection mser affinedetectors ${OpenCV_LIBS} zmq)

Expand Down
33 changes: 33 additions & 0 deletions detectors/detectors_parameters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,38 @@ struct ReadAffsFromFileParams {
}
};

struct ORBParams
{
int nfeatures;
float scaleFactor;
int nlevels;
int edgeThreshold;
int firstLevel;
int WTA_K;
PatchExtractionParams PEParam;
bool doBaumberg;
int doNMS;
// int patchSize;
// double mrSize;
// bool FastPatchExtraction;
// bool photoNorm;
ORBParams()
{
doBaumberg = false;
nfeatures = 500;
scaleFactor = 1.2;
nlevels = 8;
edgeThreshold = 31;
firstLevel = 0;
WTA_K=2;
doNMS=1;
// patchSize=31;
// mrSize = 3.0*sqrt(3.0);
// FastPatchExtraction = false;
// photoNorm =false;
}
};


struct DetectorsParameters
{
Expand All @@ -23,6 +55,7 @@ struct DetectorsParameters
zmqDescriptorParams OriNetParam;
ReadAffsFromFileParams ReadAffsFromFileParam;
AffineShapeParams BaumbergParam;
ORBParams ORBParam;
};


Expand Down
6 changes: 4 additions & 2 deletions detectors/structures.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ enum detector_type {DET_HESSIAN = 0,
DET_HARRIS = 2,
DET_MSER = 3,
DET_READ = 4,
DET_ORB = 5,
DET_UNKNOWN = 1000};


const std::string _DetectorNames [] = {"HessianAffine", "DoG",
"HarrisAffine", "MSER",
"ReadAffs", "Unknown"};
"ReadAffs", "ORB", "Unknown"};


const std::vector<std::string> DetectorNames (_DetectorNames,_DetectorNames +
Expand Down Expand Up @@ -61,12 +62,13 @@ enum descriptor_type {DESC_SIFT = 0,
DESC_INV_SIFT = 4,
DESC_ZMQ = 6,
DESC_CLI = 7,
DESC_ORB = 8,
DESC_UNKNOWN = 1000};


const std::string _DescriptorNames [] = {"SIFT", "RootSIFT",
"HalfSIFT", "HalfRootSIFT",
"InvSIFT", "ZMQ", "CLIDescriptor"};
"InvSIFT", "ZMQ", "CLIDescriptor", "ORB"};

const std::vector<std::string> DescriptorNames (_DescriptorNames,_DescriptorNames +
sizeof(_DescriptorNames)/sizeof(*_DescriptorNames));
Expand Down
128 changes: 126 additions & 2 deletions imagerepresentation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,18 @@ void ImageRepresentation::SynthDetectDescribeKeypoints (IterationViewsynthesisPa
bool SIFT_like_desc = true;
bool HalfSIFT_like_desc = false;

cv::Mat CharImage; //for OpenCV detectors

std::vector<cv::KeyPoint> keypoints_1; //for binary-dets
cv::Mat descriptors_1; //for binary-dets

bool OpenCV_det = ((curr_det.compare("ORB") == 0) ||
(curr_det.compare("FAST") == 0) ||
(curr_det.compare("STAR") == 0) ||
(curr_det.compare("KAZE") == 0) ||
(curr_det.compare("BRISK") == 0) ||
(curr_det.compare("Saddle") == 0));

for (unsigned int i_desc=0; i_desc < synth_par[curr_det][synth].descriptors.size();i_desc++) {
std::string curr_desc = synth_par[curr_det][synth].descriptors[i_desc];
if (curr_desc.find("Half") != std::string::npos) {
Expand Down Expand Up @@ -745,7 +757,38 @@ void ImageRepresentation::SynthDetectDescribeKeypoints (IterationViewsynthesisPa
{
DetectAffineRegions(temp_img1, temp_kp1,det_par.MSERParam,DET_MSER,DetectMSERs);
}

else if (curr_det.compare("ORB")==0)
{
OpenCV_det = true;
doExternalAffineAdaptation = det_par.ORBParam.doBaumberg;
//cv::OrbFeatureDetector CurrentDetector(det_par.ORBParam.nfeatures,
cv::ORB CurrentDetector(det_par.ORBParam.nfeatures,
det_par.ORBParam.scaleFactor,
det_par.ORBParam.nlevels,
det_par.ORBParam.edgeThreshold,
det_par.ORBParam.firstLevel,
det_par.ORBParam.WTA_K,
ORB::HARRIS_SCORE,
det_par.ORBParam.PEParam.patchSize);//,
// det_par.ORBParam.doNMS);
temp_img1.pixels.convertTo(CharImage,CV_8U);
CurrentDetector.detect(CharImage, keypoints_1);
int kp_size = keypoints_1.size();
temp_kp1.resize(kp_size);

for (int kp_num=0; kp_num<kp_size; kp_num++)
{
temp_kp1[kp_num].det_kp.x = keypoints_1[kp_num].pt.x;
temp_kp1[kp_num].det_kp.y = keypoints_1[kp_num].pt.y;
temp_kp1[kp_num].det_kp.a11 = cos(keypoints_1[kp_num].angle*M_PI/180.0);
temp_kp1[kp_num].det_kp.a12 = sin(keypoints_1[kp_num].angle*M_PI/180.0);
temp_kp1[kp_num].det_kp.a21 = -sin(keypoints_1[kp_num].angle*M_PI/180.0);
temp_kp1[kp_num].det_kp.a22 = cos(keypoints_1[kp_num].angle*M_PI/180.0);
temp_kp1[kp_num].det_kp.s = keypoints_1[kp_num].size / det_par.ORBParam.PEParam.mrSize;
temp_kp1[kp_num].det_kp.response = keypoints_1[kp_num].response;
temp_kp1[kp_num].type = DET_ORB;
}
}
//Baumberg iteration
if (doExternalAffineAdaptation) {
AffineRegionVector temp_kp_aff;
Expand Down Expand Up @@ -933,7 +976,17 @@ void ImageRepresentation::SynthDetectDescribeKeypoints (IterationViewsynthesisPa
}
ReprojectRegions(temp_kp1_desc, temp_img1.H, OriginalImg.cols, OriginalImg.rows);
}

if (mask.cols == OriginalImg.cols) {
std::cout << "Mask filtering" << std::endl;
AffineRegionVector temp_kp1_filtered;
for (int kp_id = 0; kp_id < temp_kp1_desc.size(); kp_id++){
if (mask.at<unsigned char>(int(temp_kp1_desc[kp_id].reproj_kp.y),int(temp_kp1_desc[kp_id].reproj_kp.x)) > 0) {
temp_kp1_filtered.push_back(temp_kp1_desc[kp_id]);
}
}
std::cout << temp_kp1_filtered.size() << " out of " << temp_kp1_desc.size() << " left" << std::endl;
temp_kp1_desc = temp_kp1_filtered;
}
///Description
///
time1 = ((double) (getMilliSecs1() - s_time)) / 1000;
Expand Down Expand Up @@ -997,6 +1050,77 @@ void ImageRepresentation::SynthDetectDescribeKeypoints (IterationViewsynthesisPa
desc_par.SIFTParam.PEParam.FastPatchExtraction,
desc_par.SIFTParam.PEParam.photoNorm);
}
else if (curr_desc.compare("ORB") == 0) //ORB
{
// else if (curr_desc.compare("ORB") == 0) //ORB (not uses orientation estimated points)
// {
std::cout << "ORB desc" << std::endl;
const double mrSizeORB = 3.0;
cv::OrbFeatureDetector CurrentDescriptor(det_par.ORBParam.nfeatures,
det_par.ORBParam.scaleFactor,
det_par.ORBParam.nlevels,
det_par.ORBParam.edgeThreshold,
det_par.ORBParam.firstLevel,
det_par.ORBParam.WTA_K,
ORB::HARRIS_SCORE,
det_par.ORBParam.PEParam.patchSize);
if (OpenCV_det) //no data conversion needed
{

if (curr_det == "ORB") {
unsigned int kp_size = temp_kp1.size();
// keypoints_1.clear();
keypoints_1.resize(kp_size);
for (unsigned int kp_num = 0; kp_num < kp_size; kp_num++) {
cv::KeyPoint temp_pt;
temp_pt.pt.x = temp_kp1_desc[kp_num].det_kp.x;
temp_pt.pt.y = temp_kp1_desc[kp_num].det_kp.y;
temp_pt.angle = atan2( temp_kp1_desc[kp_num].det_kp.a12, temp_kp1_desc[kp_num].det_kp.a12);
temp_pt.size = temp_kp1_desc[kp_num].det_kp.s * det_par.ORBParam.PEParam.mrSize; //?mrSizeORB;
keypoints_1[kp_num]=temp_pt;
}
}
CurrentDescriptor.compute(CharImage, keypoints_1, descriptors_1);
}
else {
unsigned int kp_size = temp_kp1.size();
keypoints_1.reserve(kp_size);
for (unsigned int kp_num = 0; kp_num < kp_size; kp_num++) {
cv::KeyPoint temp_pt;
temp_pt.pt.x = temp_kp1_desc[kp_num].det_kp.x;
temp_pt.pt.y = temp_kp1_desc[kp_num].det_kp.y;
temp_pt.angle = 0;
temp_pt.size = temp_kp1_desc[kp_num].det_kp.s;
keypoints_1.push_back(temp_pt);
}
temp_img1.pixels.convertTo(CharImage, CV_8U);
CurrentDescriptor.compute(CharImage, keypoints_1, descriptors_1);
}
int kp_size = keypoints_1.size();
int desc_size = descriptors_1.cols;

temp_kp1_desc.resize(kp_size);

for (int kp_num = 0; kp_num < kp_size; kp_num++) {
temp_kp1_desc[kp_num].det_kp.x = keypoints_1[kp_num].pt.x;
temp_kp1_desc[kp_num].det_kp.y = keypoints_1[kp_num].pt.y;
temp_kp1_desc[kp_num].det_kp.a11 = cos(keypoints_1[kp_num].angle * M_PI / 180.0);
temp_kp1_desc[kp_num].det_kp.a12 = sin(keypoints_1[kp_num].angle * M_PI / 180.0);
temp_kp1_desc[kp_num].det_kp.a21 = -sin(keypoints_1[kp_num].angle * M_PI / 180.0);
temp_kp1_desc[kp_num].det_kp.a22 = cos(keypoints_1[kp_num].angle * M_PI / 180.0);
temp_kp1_desc[kp_num].det_kp.s = keypoints_1[kp_num].size / det_par.ORBParam.PEParam.mrSize;
temp_kp1_desc[kp_num].det_kp.response = keypoints_1[kp_num].response;
temp_kp1_desc[kp_num].type = temp_kp1[0].type;
temp_kp1_desc[kp_num].desc.type = DESC_ORB;
temp_kp1_desc[kp_num].desc.vec.resize(desc_size);

unsigned char *descPtr = descriptors_1.ptr<unsigned char>(kp_num);
for (int jj = 0; jj < desc_size; jj++, descPtr++)
temp_kp1_desc[kp_num].desc.vec[jj] = (float) *descPtr;
}
//ReprojectRegionsAndRemoveTouchBoundary(temp_kp1_desc, temp_img1.H, OriginalImg.cols, OriginalImg.rows, mrSizeORB);
// std::cout << "new size=" << temp_kp1_desc.size() << std::endl;
}
else if (curr_desc.compare("CLIDescriptor") == 0) //ResSIFT
{
cv::Mat patches;
Expand Down
1 change: 1 addition & 0 deletions imagerepresentation.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class ImageRepresentation
DominantOrientationParams &dom_ori_par, double* H,
const int width2, const int height2);
cv::Mat OriginalImg;
cv::Mat mask;
void SaveRegions(std::string fname, int mode);
void SaveRegionsAMatrix(std::string fname);
void SaveRegionsMichal(std::string fname, int mode);
Expand Down
20 changes: 18 additions & 2 deletions io_mods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,21 @@ void GetHarrPars(ScaleSpaceDetectorParams &HarrPars, INIReader &reader,const cha
HarrPars.PyramidPars.DetectorMode = FIXED_TH;

}

void GetORBPars(ORBParams &pars, INIReader &reader,const char* section)
{
pars.edgeThreshold = reader.GetInteger(section, "edgeThreshold", pars.edgeThreshold);
pars.firstLevel= reader.GetInteger(section, "firstLevel", pars.firstLevel);
pars.nfeatures = reader.GetInteger(section, "nfeatures", pars.nfeatures);
pars.nlevels = reader.GetInteger(section, "nlevels", pars.nlevels);
pars.scaleFactor = reader.GetDouble(section, "scaleFactor", pars.scaleFactor);
pars.WTA_K = reader.GetInteger(section, "WTA_K", pars.WTA_K);
GetPatchExtractionPars(pars.PEParam,reader,section);
pars.doBaumberg = reader.GetBoolean(section,"doBaumberg",pars.doBaumberg);
pars.doNMS = reader.GetInteger(section,"doNMS",pars.doNMS);

}

void GetDoGPars(ScaleSpaceDetectorParams &DoGPars, INIReader &reader,const char* section)
{
DoGPars.PyramidPars.DetectorType = DET_DOG;
Expand Down Expand Up @@ -495,7 +510,8 @@ int getCLIparamExtractFeatures(configs &conf1,int argc, char **argv)
std::cerr << "Can't load "<< conf1.CLIparams.iters_fname << std::endl;
return 1;
}
GetDoGPars(conf1.DetectorsPars.DoGParam,ConfigIni);
GetDoGPars(conf1.DetectorsPars.DoGParam,ConfigIni);GetORBPars(conf1.DetectorsPars.ORBParam,ConfigIni);

GetHessPars(conf1.DetectorsPars.HessParam,ConfigIni);
GetDomOriPars(conf1.DomOriPars,ConfigIni);
GetHarrPars(conf1.DetectorsPars.HarrParam,ConfigIni);
Expand Down Expand Up @@ -598,7 +614,7 @@ int getCLIparam(configs &conf1,int argc, char **argv)
std::cerr << "Can't load "<< conf1.CLIparams.iters_fname << std::endl;
return 1;
}
GetDoGPars(conf1.DetectorsPars.DoGParam,ConfigIni);
GetDoGPars(conf1.DetectorsPars.DoGParam,ConfigIni);GetORBPars(conf1.DetectorsPars.ORBParam,ConfigIni);
GetHessPars(conf1.DetectorsPars.HessParam,ConfigIni);
GetDomOriPars(conf1.DomOriPars,ConfigIni);
GetHarrPars(conf1.DetectorsPars.HarrParam,ConfigIni);
Expand Down
1 change: 1 addition & 0 deletions io_mods.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ void GetMSERPars(extrema::ExtremaParams &MSERPars, INIReader &reader,const char*
void GetCLIDescPars(CLIDescriptorParams &pars, INIReader &reader,const char* section = "CLIDescriptor");
void GetReadPars(ReadAffsFromFileParams &pars, INIReader &reader,const char* section="ReadAffs");
void GetHessPars(ScaleSpaceDetectorParams &HessPars, INIReader &reader,const char* section="HessianAffine");
void GetORBPars(ORBParams &pars, INIReader &reader,const char* section="ORB");
void GetPatchExtractionPars(PatchExtractionParams &PEPars, INIReader &reader,const char* section);
void GetHarrPars(ScaleSpaceDetectorParams &HarrPars, INIReader &reader,const char* section="HarrisAffine");
void GetDoGPars(ScaleSpaceDetectorParams &DoGPars, INIReader &reader,const char* section="DoG");
Expand Down
Loading

0 comments on commit f952079

Please sign in to comment.