Skip to content

Commit f7c3099

Browse files
author
GilLevi
committed
cleaned the code a bit
1 parent e2dfa35 commit f7c3099

File tree

1 file changed

+82
-77
lines changed

1 file changed

+82
-77
lines changed

modules/xfeatures2d/src/latch.cpp

Lines changed: 82 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ namespace cv
7676

7777
protected:
7878
typedef void(*PixelTestFn)(const Mat& input_image, const std::vector<KeyPoint>& keypoints, OutputArray, const std::vector<int> &points, bool rotationInvariance, int half_ssd_size);
79-
79+
void setSamplingPoints();
8080
int bytes_;
8181
PixelTestFn test_fn_;
8282
bool rotationInvariance_;
@@ -432,7 +432,86 @@ namespace cv
432432
default:
433433
CV_Error(Error::StsBadArg, "descriptorSize must be 1,2, 4, 8, 16, 32, or 64");
434434
}
435-
int sampling_points_arr[3072]= { 13, -6, 19, 19, 23, -4,
435+
436+
setSamplingPoints();
437+
}
438+
439+
int LATCHDescriptorExtractorImpl::descriptorSize() const
440+
{
441+
return bytes_;
442+
}
443+
444+
int LATCHDescriptorExtractorImpl::descriptorType() const
445+
{
446+
return CV_8UC1;
447+
}
448+
449+
int LATCHDescriptorExtractorImpl::defaultNorm() const
450+
{
451+
return NORM_HAMMING;
452+
}
453+
454+
void LATCHDescriptorExtractorImpl::read(const FileNode& fn)
455+
{
456+
int dSize = fn["descriptorSize"];
457+
switch (dSize)
458+
{
459+
case 1:
460+
test_fn_ = pixelTests1;
461+
break;
462+
case 2:
463+
test_fn_ = pixelTests2;
464+
break;
465+
case 4:
466+
test_fn_ = pixelTests4;
467+
break;
468+
case 8:
469+
test_fn_ = pixelTests8;
470+
break;
471+
case 16:
472+
test_fn_ = pixelTests16;
473+
break;
474+
case 32:
475+
test_fn_ = pixelTests32;
476+
break;
477+
case 64:
478+
test_fn_ = pixelTests64;
479+
break;
480+
default:
481+
CV_Error(Error::StsBadArg, "descriptorSize must be 1,2, 4, 8, 16, 32, or 64");
482+
}
483+
bytes_ = dSize;
484+
}
485+
486+
void LATCHDescriptorExtractorImpl::write(FileStorage& fs) const
487+
{
488+
fs << "descriptorSize" << bytes_;
489+
}
490+
491+
void LATCHDescriptorExtractorImpl::compute(InputArray image,
492+
std::vector<KeyPoint>& keypoints,
493+
OutputArray descriptors)
494+
{
495+
496+
Mat grayImage;
497+
GaussianBlur(image, grayImage, cv::Size(3, 3), 2, 2);
498+
499+
if (image.type() != CV_8U) cvtColor(image, grayImage, COLOR_BGR2GRAY);
500+
501+
502+
503+
//Remove keypoints very close to the border
504+
KeyPointsFilter::runByImageBorder(keypoints, image.size(), PATCH_SIZE / 2 + half_ssd_size_);
505+
506+
507+
descriptors.create((int)keypoints.size(), bytes_, CV_8U);
508+
509+
test_fn_(grayImage, keypoints, descriptors, sampling_points_, rotationInvariance_, half_ssd_size_);
510+
}
511+
512+
513+
void LATCHDescriptorExtractorImpl::setSamplingPoints(){
514+
int sampling_points_arr[]= { 13, -6, 19, 19, 23, -4,
436515
4, 16, 24, -11, 4, -21,
437516
22, -14, -2, -20, 23, 5,
438517
17, -10, 2, 10, 14, -18,
@@ -945,82 +1024,8 @@ namespace cv
9451024
-19, 20, -11, -2, -20, -24,
9461025
11, -12, 5, -21, -2, -13};
9471026

948-
sampling_points_.assign(&sampling_points_arr[0],&sampling_points_arr[0]+3072);
949-
}
950-
951-
int LATCHDescriptorExtractorImpl::descriptorSize() const
952-
{
953-
return bytes_;
954-
}
955-
956-
int LATCHDescriptorExtractorImpl::descriptorType() const
957-
{
958-
return CV_8UC1;
959-
}
960-
961-
int LATCHDescriptorExtractorImpl::defaultNorm() const
962-
{
963-
return NORM_HAMMING;
964-
}
965-
966-
void LATCHDescriptorExtractorImpl::read(const FileNode& fn)
967-
{
968-
int dSize = fn["descriptorSize"];
969-
switch (dSize)
970-
{
971-
case 1:
972-
test_fn_ = pixelTests1;
973-
break;
974-
case 2:
975-
test_fn_ = pixelTests2;
976-
break;
977-
case 4:
978-
test_fn_ = pixelTests4;
979-
break;
980-
case 8:
981-
test_fn_ = pixelTests8;
982-
break;
983-
case 16:
984-
test_fn_ = pixelTests16;
985-
break;
986-
case 32:
987-
test_fn_ = pixelTests32;
988-
break;
989-
case 64:
990-
test_fn_ = pixelTests64;
991-
break;
992-
default:
993-
CV_Error(Error::StsBadArg, "descriptorSize must be 1,2, 4, 8, 16, 32, or 64");
994-
}
995-
bytes_ = dSize;
996-
}
997-
998-
void LATCHDescriptorExtractorImpl::write(FileStorage& fs) const
999-
{
1000-
fs << "descriptorSize" << bytes_;
1001-
}
1002-
1003-
void LATCHDescriptorExtractorImpl::compute(InputArray image,
1004-
std::vector<KeyPoint>& keypoints,
1005-
OutputArray descriptors)
1006-
{
1007-
1008-
Mat grayImage;
1009-
GaussianBlur(image, grayImage, cv::Size(3, 3), 2, 2);
1010-
1011-
if (image.type() != CV_8U) cvtColor(image, grayImage, COLOR_BGR2GRAY);
1012-
1013-
1027+
sampling_points_.assign(&sampling_points_arr[0],&sampling_points_arr[0]+sizeof(sampling_points_arr)/4); }
10141028

1015-
//Remove keypoints very close to the border
1016-
KeyPointsFilter::runByImageBorder(keypoints, image.size(), PATCH_SIZE / 2 + half_ssd_size_);
1017-
1018-
1019-
descriptors.create((int)keypoints.size(), bytes_, CV_8U);
1020-
1021-
test_fn_(grayImage, keypoints, descriptors, sampling_points_, rotationInvariance_, half_ssd_size_);
1022-
}
10231029
}
10241030

1025-
10261031
} // namespace cv

0 commit comments

Comments
 (0)