Skip to content

Commit 785c7c8

Browse files
committed
2.0.0
Rewrite the core algorithm. Add research code and target.
1 parent e02d22b commit 785c7c8

16 files changed

+553
-213
lines changed

CMakeLists.txt

+32-5
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ add_subdirectory(${PROJECT_SOURCE_DIR}/cxxopts)
77

88
include_directories(${PROJECT_SOURCE_DIR}/cxxopts/include)
99
include_directories(${PROJECT_SOURCE_DIR}/jsoncpp/dist/json)
10-
10+
include_directories(${PROJECT_SOURCE_DIR}/research)
1111

1212
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
1313

14-
set(SOURCE_FILES
14+
set(CLI_SOURCE_FILES
1515
animeloop-cli/algorithm.cpp
1616
animeloop-cli/algorithm.hpp
1717
animeloop-cli/filter.cpp
@@ -23,17 +23,43 @@ set(SOURCE_FILES
2323
animeloop-cli/models.hpp
2424
animeloop-cli/utils.cpp
2525
animeloop-cli/utils.hpp
26-
jsoncpp/dist/jsoncpp.cpp)
26+
jsoncpp/dist/jsoncpp.cpp
27+
)
28+
29+
add_executable(animeloop-cli ${CLI_SOURCE_FILES})
30+
31+
set(SIMILAR_SAME_SOURCE_FILES
32+
animeloop-cli/algorithm.cpp
33+
animeloop-cli/algorithm.hpp
34+
research/similar_and_same.cpp)
35+
36+
add_executable(similar-and-same ${SIMILAR_SAME_SOURCE_FILES})
37+
38+
set(CUTS_SWITCH_SOURCE_FILES
39+
animeloop-cli/algorithm.cpp
40+
animeloop-cli/algorithm.hpp
41+
animeloop-cli/utils.cpp
42+
animeloop-cli/utils.hpp
43+
research/cuts_switch.cpp)
44+
45+
add_executable(cuts-switch ${CUTS_SWITCH_SOURCE_FILES})
46+
47+
set(COLOR_SOURCE_FILES
48+
research/color.cpp)
2749

28-
add_executable(animeloop-cli ${SOURCE_FILES})
50+
add_executable(color ${COLOR_SOURCE_FILES})
2951

3052
# OpenCV
3153
find_package( OpenCV 3.2 REQUIRED )
3254
target_link_libraries( animeloop-cli ${OpenCV_LIBS} )
55+
target_link_libraries( similar-and-same ${OpenCV_LIBS})
56+
target_link_libraries( cuts-switch ${OpenCV_LIBS})
57+
target_link_libraries( color ${OpenCV_LIBS})
3358

3459
# Boost
35-
find_package(Boost COMPONENTS filesystem date_time system REQUIRED)
60+
find_package(Boost COMPONENTS filesystem date_time system program_options REQUIRED)
3661
target_link_libraries( animeloop-cli ${Boost_LIBRARIES} )
62+
target_link_libraries( cuts-switch ${Boost_LIBRARIES} )
3763

3864
# Search OpenSSL
3965
pkg_search_module(OPENSSL REQUIRED openssl)
@@ -46,3 +72,4 @@ else()
4672
endif()
4773

4874
target_link_libraries( animeloop-cli ${OPENSSL_LIBRARIES})
75+
target_link_libraries( cuts-switch ${OPENSSL_LIBRARIES})

animeloop-cli.xcodeproj/project.pbxproj

+6-4
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@
1919
8818F2EC1E920F260085F368 /* models.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8818F2EA1E920F260085F368 /* models.cpp */; };
2020
8818F2EF1E920F3E0085F368 /* utils.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8818F2ED1E920F3E0085F368 /* utils.cpp */; };
2121
8818F2F51E9242310085F368 /* filter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8818F2F31E9242310085F368 /* filter.cpp */; };
22-
883E5A5D1E5C346C004E1554 /* libcrypto.1.0.0.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 883E5A5C1E5C346C004E1554 /* libcrypto.1.0.0.dylib */; };
22+
884E2E261F30D787001EA03E /* libcrypto.1.0.0.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 884E2E241F30D769001EA03E /* libcrypto.1.0.0.dylib */; };
2323
88537E9D1E4C501900385BCB /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 88537E9C1E4C501900385BCB /* main.cpp */; };
24-
889337CD1E9E31AE004C69AD /* libopencv_objdetect.3.2.0.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 889337CC1E9E31AE004C69AD /* libopencv_objdetect.3.2.0.dylib */; };
2524
88DC61451E585CCE0062B914 /* algorithm.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 88DC61431E585CCE0062B914 /* algorithm.cpp */; };
2625
88E08EB61E5ACAD60080D35E /* jsoncpp.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 88E08EB51E5ACAD60080D35E /* jsoncpp.cpp */; };
2726
/* End PBXBuildFile section */
@@ -55,6 +54,7 @@
5554
8818F2F31E9242310085F368 /* filter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = filter.cpp; path = "animeloop-cli/filter.cpp"; sourceTree = "<group>"; };
5655
8818F2F41E9242310085F368 /* filter.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = filter.hpp; path = "animeloop-cli/filter.hpp"; sourceTree = "<group>"; };
5756
883E5A5C1E5C346C004E1554 /* libcrypto.1.0.0.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libcrypto.1.0.0.dylib; path = ../../../../../usr/local/Cellar/openssl/1.0.2j/lib/libcrypto.1.0.0.dylib; sourceTree = "<group>"; };
57+
884E2E241F30D769001EA03E /* libcrypto.1.0.0.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libcrypto.1.0.0.dylib; path = ../../../../../usr/local/Cellar/openssl/1.0.2l/lib/libcrypto.1.0.0.dylib; sourceTree = "<group>"; };
5858
88537E991E4C501900385BCB /* animeloop-cli */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "animeloop-cli"; sourceTree = BUILT_PRODUCTS_DIR; };
5959
88537E9C1E4C501900385BCB /* main.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = "<group>"; };
6060
88537EA71E4C52CC00385BCB /* libopencv_core.3.2.0.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libopencv_core.3.2.0.dylib; path = ../../../../../usr/local/lib/libopencv_core.3.2.0.dylib; sourceTree = "<group>"; };
@@ -76,8 +76,7 @@
7676
isa = PBXFrameworksBuildPhase;
7777
buildActionMask = 2147483647;
7878
files = (
79-
889337CD1E9E31AE004C69AD /* libopencv_objdetect.3.2.0.dylib in Frameworks */,
80-
883E5A5D1E5C346C004E1554 /* libcrypto.1.0.0.dylib in Frameworks */,
79+
884E2E261F30D787001EA03E /* libcrypto.1.0.0.dylib in Frameworks */,
8180
88088C1A1E4E333A00601DBD /* libboost_date_time.dylib in Frameworks */,
8281
88088C181E4E29E400601DBD /* libboost_system.dylib in Frameworks */,
8382
88088C121E4E294600601DBD /* libopencv_core.3.2.0.dylib in Frameworks */,
@@ -156,6 +155,7 @@
156155
88537EA61E4C52CC00385BCB /* Frameworks */ = {
157156
isa = PBXGroup;
158157
children = (
158+
884E2E241F30D769001EA03E /* libcrypto.1.0.0.dylib */,
159159
889337CC1E9E31AE004C69AD /* libopencv_objdetect.3.2.0.dylib */,
160160
889337CA1E9E318C004C69AD /* libopencv_face.3.2.0.dylib */,
161161
88DC91551E7FD7BF005C122D /* libMagick++-7.Q16HDRI.a */,
@@ -373,6 +373,7 @@
373373
/usr/local/Cellar/ffmpeg/3.2.3/lib,
374374
/usr/local/Cellar/boost/1.63.0/lib,
375375
/usr/local/Cellar/openssl/1.0.2j/lib,
376+
/usr/local/Cellar/openssl/1.0.2l/lib,
376377
);
377378
MACOSX_DEPLOYMENT_TARGET = 10.10;
378379
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -390,6 +391,7 @@
390391
/usr/local/Cellar/ffmpeg/3.2.3/lib,
391392
/usr/local/Cellar/boost/1.63.0/lib,
392393
/usr/local/Cellar/openssl/1.0.2j/lib,
394+
/usr/local/Cellar/openssl/1.0.2l/lib,
393395
);
394396
MACOSX_DEPLOYMENT_TARGET = 10.10;
395397
PRODUCT_NAME = "$(TARGET_NAME)";

animeloop-cli/algorithm.cpp

+17-32
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,6 @@ void cvt_image(cv::Mat &image, int length) {
2626
}
2727
}
2828

29-
string al::hash(string type, Mat image, int length) {
30-
transform(type.begin(), type.end(), type.begin(), [](unsigned char c) { return std::tolower(c); });
31-
if (type == "ahash") {
32-
return al::aHash(image, length);
33-
} else if (type == "dhash") {
34-
return al::dHash(image, length);
35-
} else if (type == "phash") {
36-
return al::pHash(image, length);
37-
} else {
38-
return string();
39-
}
40-
}
41-
4229
string al::aHash(Mat image, int length) {
4330
cvt_image(image, length);
4431

@@ -70,19 +57,27 @@ string al::dHash(Mat image, int length) {
7057
return hash_string;
7158
}
7259

73-
string al::pHash(Mat image, int length) {
60+
string al::pHash(Mat image, int length, int dct_length) {
7461
cvt_image(image, length);
7562

76-
Mat img = Mat_<double>(image);
77-
dct(img, img);
63+
Mat dct = Mat_<double>(image);
64+
cv::dct(dct, dct);
7865

7966
string hash_string = "";
8067

81-
double mean = accumulate(img.begin<double>(), img.end<double>(), 0.0) / (length * length);
82-
83-
for (int i = 0; i < length; ++i) {
84-
for (int j = 0; j < length; ++j) {
85-
hash_string += (img.at<double>(i, j) >= mean ? "1" : "0");
68+
double mean = 0.0;
69+
for (int i = 0; i < dct_length; ++i)
70+
{
71+
for (int j = 0; j < dct_length; ++j)
72+
{
73+
mean += dct.at<double>(i, j);
74+
}
75+
}
76+
mean /= length * length;
77+
78+
for (int i = 0; i < dct_length; ++i) {
79+
for (int j = 0; j < dct_length; ++j) {
80+
hash_string += (dct.at<double>(i, j) >= mean ? "1" : "0");
8681
}
8782
}
8883
return hash_string;
@@ -112,14 +107,4 @@ unsigned int al::hamming_distance(int64_t n1, int64_t n2) {
112107
count += difference & 1;
113108
}
114109
return count;
115-
}
116-
117-
vector<Rect> detect_face(Mat image, CascadeClassifier &face_cascade) {
118-
vector<Rect> faces;
119-
120-
cvt_image(image, 0);
121-
cv::equalizeHist(image, image);
122-
123-
face_cascade.detectMultiScale(image, faces);
124-
return faces;
125-
}
110+
}

animeloop-cli/algorithm.hpp

+8-18
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,6 @@
1414
#include <opencv2/opencv.hpp>
1515

1616
namespace al {
17-
/**
18-
choose which hash type
19-
value can be "ahash", "dhash" or "phash"
20-
21-
@param type which type of hash
22-
@param image target image
23-
@param length resize height and width
24-
@return aHash tring
25-
*/
26-
std::string hash(std::string type, cv::Mat image, int length);
27-
2817
/**
2918
calculate aHash string of an image.
3019
@@ -33,7 +22,7 @@ namespace al {
3322
@return aHash tring
3423
*/
3524
std::string aHash(cv::Mat image, int length);
36-
25+
3726
/**
3827
calculate dHash string of an image.
3928
@@ -42,17 +31,18 @@ namespace al {
4231
@return dHash string
4332
*/
4433
std::string dHash(cv::Mat image, int length);
45-
34+
4635
/**
4736
calculate pHash string of an image.
4837
4938
@param image target image
50-
@param length resize height and width(length > 8)
39+
@param length resize height and width (recommend length > 32)
40+
@param dct_length dct size (recommend length > 8)
5141
@return pHash string
5242
*/
53-
std::string pHash(cv::Mat image, int length);
54-
55-
43+
std::string pHash(cv::Mat image, int length, int dct_length);
44+
45+
5646
/**
5747
Calculate hamming distance between two image hash strings.
5848
@@ -61,7 +51,7 @@ namespace al {
6151
@return hamming distance value
6252
*/
6353
unsigned int hamming_distance(std::string str1, std::string str2);
64-
54+
6555
/**
6656
Calculate hamming distance between two image hash int64 value.
6757

0 commit comments

Comments
 (0)