Skip to content

Commit 0d11814

Browse files
authored
Merge pull request #15 from mdeleau/add-imghash
Add img_hash module
2 parents 6fef1e3 + 3fd7798 commit 0d11814

File tree

11 files changed

+5645
-5059
lines changed

11 files changed

+5645
-5059
lines changed

.github/workflows/build_test_pr.yaml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: build test release
2+
3+
on:
4+
push:
5+
# branches: ["conan"]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
env:
10+
ANDROID_NDK_VERSION: r26c
11+
OPENCV_VERSION: 4.9.0
12+
LIB_NAME: libopencv_dart
13+
14+
jobs:
15+
build-windows:
16+
name: build-windows
17+
runs-on: windows-latest
18+
19+
steps:
20+
- uses: actions/checkout@v4
21+
with:
22+
submodules: true
23+
- uses: actions/setup-python@v5
24+
with:
25+
python-version: "3.11"
26+
- name: build-opencv-dart
27+
run: |
28+
python3 -m pip install conan
29+
conan profile detect -f
30+
conan build . -b missing -s compiler.cppstd=20
31+
32+
- uses: actions/upload-artifact@v4
33+
name: upload-windows-x64
34+
with:
35+
path: build/publish/libopencv_dart-windows-x64.tar.gz
36+
name: libopencv_dart-windows-x64.tar.gz
37+
- uses: subosito/flutter-action@v2
38+
with:
39+
# flutter-version: '3.16.9'
40+
channel: "stable"
41+
- name: Run Test
42+
run: |
43+
$env:PATH = "${{github.workspace}}\windows;${env:PATH}"
44+
flutter pub get
45+
flutter test -x no-local-files

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ find_package(OpenCV REQUIRED)
99

1010
set(OpenCV_LIBS
1111
opencv_aruco opencv_core opencv_calib3d opencv_dnn opencv_highgui
12-
opencv_features2d opencv_photo opencv_imgproc
12+
opencv_features2d opencv_photo opencv_imgproc opencv_img_hash
1313
opencv_objdetect opencv_video opencv_videoio opencv_stitching
1414
)
1515

README.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,18 @@ to download prebuilt binaries.
6262

6363
### Contrib Modules
6464

65-
| module | Binding status | Test status | description |
66-
| ------------- | ------------------ | ------------------ | ------------ |
67-
| aruco | :white_check_mark: | :white_check_mark: | ArUco module |
68-
| cuda | :x: | :x: | |
69-
| wechat_qrcode | :x: | :x: | |
70-
| bgsegm | :x: | :x: | |
71-
| superres | :x: | :x: | |
72-
| xfeatures2d | :x: | :x: | |
73-
| ximgproc | :x: | :x: | |
74-
| xobjdetect | :x: | :x: | |
75-
| xphoto | :x: | :x: | |
65+
| module | Binding status | Test status | description |
66+
| ------------- | ------------------ | ------------------ | -------------------- |
67+
| aruco | :white_check_mark: | :white_check_mark: | ArUco module |
68+
| img_hash | :white_check_mark: | :white_check_mark: | Image hashing module |
69+
| cuda | :x: | :x: | |
70+
| wechat_qrcode | :x: | :x: | |
71+
| bgsegm | :x: | :x: | |
72+
| superres | :x: | :x: | |
73+
| xfeatures2d | :x: | :x: | |
74+
| ximgproc | :x: | :x: | |
75+
| xobjdetect | :x: | :x: | |
76+
| xphoto | :x: | :x: | |
7677

7778
- :x: : not finished
7879
- :ballot_box_with_check: : partially supported

conanfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"videoio": True,
5151
# contrib
5252
"aruco": True,
53+
"img_hash": True,
5354
# not implemented
5455
"wechat_qrcode": False,
5556
"bgsegm": False,
@@ -61,7 +62,6 @@
6162
"face": False,
6263
"fuzzy": False,
6364
"hfs": False,
64-
"img_hash": False,
6565
"intensity_transform": False,
6666
"line_descriptor": False,
6767
"mcc": False,

ffigen.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ headers:
2020
- src/dnn.h
2121
- src/exception.h
2222
- src/features2d.h
23-
- src/highgui_gocv.h
23+
- src/highgui.h
2424
- src/imgcodecs.h
2525
- src/imgproc.h
26+
- src/img_hash.h
2627
- src/objdetect.h
2728
- src/photo.h
2829
- src/stitching.h
@@ -38,9 +39,10 @@ headers:
3839
- src/dnn.h
3940
- src/exception.h
4041
- src/features2d.h
41-
- src/highgui_gocv.h
42+
- src/highgui.h
4243
- src/imgcodecs.h
4344
- src/imgproc.h
45+
- src/img_hash.h
4446
- src/objdetect.h
4547
- src/photo.h
4648
- src/stitching.h

lib/src/contrib/img_hash.dart

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
// ignore_for_file: constant_identifier_names
2+
3+
library cv;
4+
5+
import '../core/base.dart';
6+
import '../core/mat.dart';
7+
import '../opencv.g.dart' as cvg;
8+
9+
final _bindings = cvg.CvNative(loadNativeLibrary());
10+
11+
12+
abstract class ImgHashBase {
13+
double compare (InputArray hashOne, InputArray hashTwo);
14+
void compute (InputArray inputArr, OutputArray outputArr);
15+
}
16+
17+
/// PHash is implementation of the PHash algorithm.
18+
class PHash implements ImgHashBase {
19+
20+
/// Compare compares the hash value between a and b using PHash.
21+
//
22+
/// For further information, see:
23+
/// https://docs.opencv.org/master/de/d29/classcv_1_1img__hash_1_1ImgHashBase.html#a444a3e9ec792cf029385809393f84ad5
24+
@override
25+
double compare(InputArray hashOne, InputArray hashTwo) {
26+
return _bindings.pHashCompare(hashOne.ptr, hashTwo.ptr);
27+
}
28+
29+
/// Compute computes hash of the input image using PHash.
30+
//
31+
/// For further information, see:
32+
/// https://docs.opencv.org/master/de/d29/classcv_1_1img__hash_1_1ImgHashBase.html#ae2d9288db370089dfd8aab85d5e0b0f3
33+
@override
34+
void compute(InputArray inputArr, OutputArray outputArr) {
35+
return _bindings.pHashCompute(inputArr.ptr, outputArr.ptr);
36+
}
37+
}
38+
39+
40+
/// AverageHash is implementation of the AverageHash algorithm.
41+
class AverageHash implements ImgHashBase {
42+
43+
/// Compare compares the hash value between a and b using AverageHash.
44+
//
45+
/// For further information, see:
46+
/// https://docs.opencv.org/master/de/d29/classcv_1_1img__hash_1_1ImgHashBase.html#a444a3e9ec792cf029385809393f84ad5
47+
@override
48+
double compare(InputArray hashOne, InputArray hashTwo) {
49+
return _bindings.averageHashCompare(hashOne.ptr, hashTwo.ptr);
50+
}
51+
52+
/// Compute computes hash of the input image using AverageHash.
53+
//
54+
/// For further information, see:
55+
/// https://docs.opencv.org/master/de/d29/classcv_1_1img__hash_1_1ImgHashBase.html#ae2d9288db370089dfd8aab85d5e0b0f3
56+
@override
57+
void compute(InputArray inputArr, OutputArray outputArr) {
58+
return _bindings.averageHashCompute(inputArr.ptr, outputArr.ptr);
59+
}
60+
}
61+
62+
63+
enum BlockMeanHashMode
64+
{
65+
BLOCK_MEAN_HASH_MODE_0, //!< use fewer block and generate 16*16/8 uchar hash value
66+
BLOCK_MEAN_HASH_MODE_1 , //!< use block blocks(step sizes/2), generate 31*31/8 + 1 uchar hash value
67+
}
68+
69+
70+
/// BlockMeanHash is implementation of the BlockMeanHash algorithm.
71+
class BlockMeanHash implements ImgHashBase {
72+
73+
BlockMeanHashMode mode = BlockMeanHashMode.BLOCK_MEAN_HASH_MODE_0;
74+
75+
BlockMeanHash({this.mode = BlockMeanHashMode.BLOCK_MEAN_HASH_MODE_0});
76+
77+
/// Compare compares the hash value between a and b using BlockMeanHash.
78+
//
79+
/// For further information, see:
80+
/// https://docs.opencv.org/master/de/d29/classcv_1_1img__hash_1_1ImgHashBase.html#a444a3e9ec792cf029385809393f84ad5
81+
@override
82+
double compare(InputArray hashOne, InputArray hashTwo) {
83+
return _bindings.blockMeanHashCompare(hashOne.ptr, hashTwo.ptr, mode.index);
84+
}
85+
86+
/// Compute computes hash of the input image using BlockMeanHash.
87+
//
88+
/// For further information, see:
89+
/// https://docs.opencv.org/master/de/d29/classcv_1_1img__hash_1_1ImgHashBase.html#ae2d9288db370089dfd8aab85d5e0b0f3
90+
@override
91+
void compute(InputArray inputArr, OutputArray outputArr) {
92+
return _bindings.blockMeanHashCompute(inputArr.ptr, outputArr.ptr, mode.index);
93+
}
94+
95+
// TODO: BlockMeanHash.GetMean isn't implemented, because it requires state from the last
96+
// call to Compute, and there's no easy way to keep it.
97+
98+
}
99+
100+
101+
/// ColorMomentHash is implementation of the ColorMomentHash algorithm.
102+
class ColorMomentHash implements ImgHashBase {
103+
104+
/// Compare compares the hash value between a and b using ColorMomentHash.
105+
//
106+
/// For further information, see:
107+
/// https://docs.opencv.org/master/de/d29/classcv_1_1img__hash_1_1ImgHashBase.html#a444a3e9ec792cf029385809393f84ad5
108+
@override
109+
double compare(InputArray hashOne, InputArray hashTwo) {
110+
return _bindings.colorMomentHashCompare(hashOne.ptr, hashTwo.ptr);
111+
}
112+
113+
/// Compute computes hash of the input image using ColorMomentHash.
114+
//
115+
/// For further information, see:
116+
/// https://docs.opencv.org/master/de/d29/classcv_1_1img__hash_1_1ImgHashBase.html#ae2d9288db370089dfd8aab85d5e0b0f3
117+
@override
118+
void compute(InputArray inputArr, OutputArray outputArr) {
119+
return _bindings.colorMomentHashCompute(inputArr.ptr, outputArr.ptr);
120+
}
121+
}
122+
123+
124+
/// MarrHildrethHash is implementation of the MarrHildrethHash algorithm.
125+
class NewMarrHildrethHash implements ImgHashBase {
126+
127+
double alpha = 2.0;
128+
double scale = 1.0;
129+
130+
NewMarrHildrethHash({this.alpha = 2.0, this.scale = 1.0});
131+
132+
/// Compare compares the hash value between a and b using MarrHildrethHash.
133+
//
134+
/// For further information, see:
135+
/// https://docs.opencv.org/master/de/d29/classcv_1_1img__hash_1_1ImgHashBase.html#a444a3e9ec792cf029385809393f84ad5
136+
@override
137+
double compare(InputArray hashOne, InputArray hashTwo) {
138+
return _bindings.marrHildrethHashCompare(hashOne.ptr, hashTwo.ptr, alpha, scale);
139+
}
140+
141+
/// Compute computes hash of the input image using MarrHildrethHash.
142+
//
143+
/// For further information, see:
144+
/// https://docs.opencv.org/master/de/d29/classcv_1_1img__hash_1_1ImgHashBase.html#ae2d9288db370089dfd8aab85d5e0b0f3
145+
@override
146+
void compute(InputArray inputArr, OutputArray outputArr) {
147+
return _bindings.marrHildrethHashCompute(inputArr.ptr, outputArr.ptr, alpha, scale);
148+
}
149+
}
150+
151+
152+
/// NewRadialVarianceHash is implementation of the NewRadialVarianceHash algorithm.
153+
class NewRadialVarianceHash implements ImgHashBase {
154+
155+
double sigma = 1;
156+
int numOfAngleLine = 180;
157+
158+
NewRadialVarianceHash({this.sigma = 1, this.numOfAngleLine = 180});
159+
160+
/// Compare compares the hash value between a and b using RadialVarianceHash.
161+
//
162+
/// For further information, see:
163+
/// https://docs.opencv.org/master/de/d29/classcv_1_1img__hash_1_1ImgHashBase.html#a444a3e9ec792cf029385809393f84ad5
164+
@override
165+
double compare(InputArray hashOne, InputArray hashTwo) {
166+
return _bindings.radialVarianceHashCompare(hashOne.ptr, hashTwo.ptr, sigma, numOfAngleLine);
167+
}
168+
169+
/// Compute computes hash of the input image using RadialVarianceHash.
170+
//
171+
/// For further information, see:
172+
/// https://docs.opencv.org/master/de/d29/classcv_1_1img__hash_1_1ImgHashBase.html#ae2d9288db370089dfd8aab85d5e0b0f3
173+
@override
174+
void compute(InputArray inputArr, OutputArray outputArr) {
175+
return _bindings.radialVarianceHashCompute(inputArr.ptr, outputArr.ptr, sigma, numOfAngleLine);
176+
}
177+
}

lib/src/opencv.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export 'constants.g.dart';
44

55
export 'contrib/aruco.dart';
66
export 'contrib/aruco_dict.dart';
7+
export 'contrib/img_hash.dart';
78

89
export 'core/asyncarray.dart';
910
export 'core/base.dart';

0 commit comments

Comments
 (0)