-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Searching of similar maps was improved.
- Loading branch information
Showing
20 changed files
with
379 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#include "Gauss2DHashAlgorithm.h" | ||
|
||
#include <vector> | ||
#include <sstream> | ||
#include <cmath> | ||
|
||
#include <opencv2/opencv.hpp> | ||
#include <dhash.h> | ||
|
||
#include "DHashException.h" | ||
|
||
using namespace std; | ||
|
||
Gauss2DHashAlgorithm::~Gauss2DHashAlgorithm() { | ||
} | ||
|
||
std::vector<uint64_t> Gauss2DHashAlgorithm::compute(const std::vector<uint8_t>* data) { | ||
cv::Mat image = cv::imdecode(*data, CV_LOAD_IMAGE_GRAYSCALE); | ||
cv::resize(image, image, getKeepRatioSize(image, 512), 0, 0, cv::INTER_LANCZOS4); | ||
|
||
cv::Mat g1, g2; | ||
cv::GaussianBlur(image, g1, cv::Size(3, 3), 0); | ||
cv::GaussianBlur(image, g2, cv::Size(9, 9), 60); | ||
image = g1 - g2; | ||
|
||
std::vector<uint8_t> gaussdata; | ||
cv::imencode(".png", image, gaussdata); | ||
|
||
dhash_err* err = dhash_new_err(); | ||
uint64_t hash = dhash_compute_blob(&gaussdata[0], gaussdata.size(), err); | ||
|
||
if (err->err_type != OK) { | ||
ostringstream os; | ||
os << "Error occured during compute dhash: " << err->description; | ||
dhash_free_err(err); | ||
throw DHashException(os.str()); | ||
} | ||
dhash_free_err(err); | ||
|
||
vector<uint64_t> result; | ||
result.push_back(hash); | ||
return result; | ||
} | ||
|
||
HashType Gauss2DHashAlgorithm::getType() { | ||
return Gauss2DHash; | ||
} | ||
|
||
size_t Gauss2DHashAlgorithm::getHashSize() { | ||
return 8; | ||
} | ||
|
||
cv::Size Gauss2DHashAlgorithm::getKeepRatioSize(const cv::Mat& image, int size) { | ||
int width = image.cols; | ||
int height = image.rows; | ||
|
||
double ratio; | ||
|
||
if (width < height) { | ||
ratio = size * 1.0 / width; | ||
} else { | ||
ratio = size * 1.0 / height; | ||
} | ||
return cv::Size((int) round(width*ratio), (int) round(height*ratio)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#ifndef GAUSS2DHASH_H | ||
#define GAUSS2DHASH_H | ||
|
||
#include <opencv2/opencv.hpp> | ||
|
||
#include "HashAlgorithm.h" | ||
#include "HashType.h" | ||
|
||
|
||
class Gauss2DHashAlgorithm : public HashAlgorithm { | ||
public: | ||
virtual ~Gauss2DHashAlgorithm(); | ||
|
||
virtual std::vector<uint64_t> compute(const std::vector<uint8_t>* data); | ||
virtual HashType getType(); | ||
virtual size_t getHashSize(); | ||
private: | ||
virtual cv::Size getKeepRatioSize(const cv::Mat& image, int size); | ||
}; | ||
|
||
#endif /* GAUSS2DHASH_H */ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#include "GaussBlockHashAlgorithm.h" | ||
|
||
#include <vector> | ||
#include <sstream> | ||
#include <cmath> | ||
|
||
#include <opencv2/opencv.hpp> | ||
#include <blockhash.h> | ||
|
||
using namespace std; | ||
|
||
GaussBlockHashAlgorithm::~GaussBlockHashAlgorithm() { | ||
} | ||
|
||
std::vector<uint64_t> GaussBlockHashAlgorithm::compute(const std::vector<uint8_t>* data) { | ||
cv::Mat image = cv::imdecode(*data, CV_LOAD_IMAGE_GRAYSCALE); | ||
cv::resize(image, image, getKeepRatioSize(image, 512), 0, 0, cv::INTER_LANCZOS4); | ||
|
||
cv::Mat g1, g2; | ||
cv::GaussianBlur(image, g1, cv::Size(1, 1), 0); | ||
cv::GaussianBlur(image, g2, cv::Size(3, 3), 60); | ||
image = g1 - g2; | ||
|
||
std::vector<uint8_t> gaussdata; | ||
cv::imencode(".png", image, gaussdata); | ||
|
||
return blockhash::compute(gaussdata, 256); | ||
} | ||
|
||
HashType GaussBlockHashAlgorithm::getType() { | ||
return GaussBlockHash; | ||
} | ||
|
||
size_t GaussBlockHashAlgorithm::getHashSize() { | ||
return 32; | ||
} | ||
|
||
cv::Size GaussBlockHashAlgorithm::getKeepRatioSize(const cv::Mat& image, int size) { | ||
int width = image.cols; | ||
int height = image.rows; | ||
|
||
double ratio; | ||
|
||
if (width < height) { | ||
ratio = size * 1.0 / width; | ||
} else { | ||
ratio = size * 1.0 / height; | ||
} | ||
return cv::Size((int) round(width*ratio), (int) round(height*ratio)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#ifndef GAUSSBLOCKHASH_H | ||
#define GAUSSBLOCKHASH_H | ||
|
||
#include <opencv2/opencv.hpp> | ||
|
||
#include "HashAlgorithm.h" | ||
#include "HashType.h" | ||
|
||
|
||
class GaussBlockHashAlgorithm : public HashAlgorithm { | ||
public: | ||
virtual ~GaussBlockHashAlgorithm(); | ||
|
||
virtual std::vector<uint64_t> compute(const std::vector<uint8_t>* data); | ||
virtual HashType getType(); | ||
virtual size_t getHashSize(); | ||
private: | ||
virtual cv::Size getKeepRatioSize(const cv::Mat& image, int size); | ||
}; | ||
|
||
#endif /* GAUSSBLOCKHASH_H */ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.