Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add img_hash module #15

Merged
merged 2 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/workflows/build_test_pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: build test release

on:
push:
# branches: ["conan"]
pull_request:
branches: [ "main" ]

env:
ANDROID_NDK_VERSION: r26c
OPENCV_VERSION: 4.9.0
LIB_NAME: libopencv_dart

jobs:
build-windows:
name: build-windows
runs-on: windows-latest

steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: build-opencv-dart
run: |
python3 -m pip install conan
conan profile detect -f
conan build . -b missing -s compiler.cppstd=20

- uses: actions/upload-artifact@v4
name: upload-windows-x64
with:
path: build/publish/libopencv_dart-windows-x64.tar.gz
name: libopencv_dart-windows-x64.tar.gz
- uses: subosito/flutter-action@v2
with:
# flutter-version: '3.16.9'
channel: "stable"
- name: Run Test
run: |
$env:PATH = "${{github.workspace}}\windows;${env:PATH}"
flutter pub get
flutter test -x no-local-files
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ find_package(OpenCV REQUIRED)

set(OpenCV_LIBS
opencv_aruco opencv_core opencv_calib3d opencv_dnn opencv_highgui
opencv_features2d opencv_photo opencv_imgproc
opencv_features2d opencv_photo opencv_imgproc opencv_img_hash
opencv_objdetect opencv_video opencv_videoio opencv_stitching
)

Expand Down
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,18 @@ to download prebuilt binaries.

### Contrib Modules

| module | Binding status | Test status | description |
| ------------- | ------------------ | ------------------ | ------------ |
| aruco | :white_check_mark: | :white_check_mark: | ArUco module |
| cuda | :x: | :x: | |
| wechat_qrcode | :x: | :x: | |
| bgsegm | :x: | :x: | |
| superres | :x: | :x: | |
| xfeatures2d | :x: | :x: | |
| ximgproc | :x: | :x: | |
| xobjdetect | :x: | :x: | |
| xphoto | :x: | :x: | |
| module | Binding status | Test status | description |
| ------------- | ------------------ | ------------------ | -------------------- |
| aruco | :white_check_mark: | :white_check_mark: | ArUco module |
| img_hash | :white_check_mark: | :white_check_mark: | Image hashing module |
| cuda | :x: | :x: | |
| wechat_qrcode | :x: | :x: | |
| bgsegm | :x: | :x: | |
| superres | :x: | :x: | |
| xfeatures2d | :x: | :x: | |
| ximgproc | :x: | :x: | |
| xobjdetect | :x: | :x: | |
| xphoto | :x: | :x: | |

- :x: : not finished
- :ballot_box_with_check: : partially supported
Expand Down
2 changes: 1 addition & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"videoio": True,
# contrib
"aruco": True,
"img_hash": True,
# not implemented
"wechat_qrcode": False,
"bgsegm": False,
Expand All @@ -61,7 +62,6 @@
"face": False,
"fuzzy": False,
"hfs": False,
"img_hash": False,
"intensity_transform": False,
"line_descriptor": False,
"mcc": False,
Expand Down
6 changes: 4 additions & 2 deletions ffigen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ headers:
- src/dnn.h
- src/exception.h
- src/features2d.h
- src/highgui_gocv.h
- src/highgui.h
- src/imgcodecs.h
- src/imgproc.h
- src/img_hash.h
- src/objdetect.h
- src/photo.h
- src/stitching.h
Expand All @@ -38,9 +39,10 @@ headers:
- src/dnn.h
- src/exception.h
- src/features2d.h
- src/highgui_gocv.h
- src/highgui.h
- src/imgcodecs.h
- src/imgproc.h
- src/img_hash.h
- src/objdetect.h
- src/photo.h
- src/stitching.h
Expand Down
177 changes: 177 additions & 0 deletions lib/src/contrib/img_hash.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
// ignore_for_file: constant_identifier_names

library cv;

import '../core/base.dart';
import '../core/mat.dart';
import '../opencv.g.dart' as cvg;

final _bindings = cvg.CvNative(loadNativeLibrary());


abstract class ImgHashBase {
double compare (InputArray hashOne, InputArray hashTwo);
void compute (InputArray inputArr, OutputArray outputArr);
}

/// PHash is implementation of the PHash algorithm.
class PHash implements ImgHashBase {

/// Compare compares the hash value between a and b using PHash.
//
/// For further information, see:
/// https://docs.opencv.org/master/de/d29/classcv_1_1img__hash_1_1ImgHashBase.html#a444a3e9ec792cf029385809393f84ad5
@override
double compare(InputArray hashOne, InputArray hashTwo) {
return _bindings.pHashCompare(hashOne.ptr, hashTwo.ptr);
}

/// Compute computes hash of the input image using PHash.
//
/// For further information, see:
/// https://docs.opencv.org/master/de/d29/classcv_1_1img__hash_1_1ImgHashBase.html#ae2d9288db370089dfd8aab85d5e0b0f3
@override
void compute(InputArray inputArr, OutputArray outputArr) {
return _bindings.pHashCompute(inputArr.ptr, outputArr.ptr);
}
}


/// AverageHash is implementation of the AverageHash algorithm.
class AverageHash implements ImgHashBase {

/// Compare compares the hash value between a and b using AverageHash.
//
/// For further information, see:
/// https://docs.opencv.org/master/de/d29/classcv_1_1img__hash_1_1ImgHashBase.html#a444a3e9ec792cf029385809393f84ad5
@override
double compare(InputArray hashOne, InputArray hashTwo) {
return _bindings.averageHashCompare(hashOne.ptr, hashTwo.ptr);
}

/// Compute computes hash of the input image using AverageHash.
//
/// For further information, see:
/// https://docs.opencv.org/master/de/d29/classcv_1_1img__hash_1_1ImgHashBase.html#ae2d9288db370089dfd8aab85d5e0b0f3
@override
void compute(InputArray inputArr, OutputArray outputArr) {
return _bindings.averageHashCompute(inputArr.ptr, outputArr.ptr);
}
}


enum BlockMeanHashMode
{
BLOCK_MEAN_HASH_MODE_0, //!< use fewer block and generate 16*16/8 uchar hash value
BLOCK_MEAN_HASH_MODE_1 , //!< use block blocks(step sizes/2), generate 31*31/8 + 1 uchar hash value
}


/// BlockMeanHash is implementation of the BlockMeanHash algorithm.
class BlockMeanHash implements ImgHashBase {

BlockMeanHashMode mode = BlockMeanHashMode.BLOCK_MEAN_HASH_MODE_0;

BlockMeanHash({this.mode = BlockMeanHashMode.BLOCK_MEAN_HASH_MODE_0});

/// Compare compares the hash value between a and b using BlockMeanHash.
//
/// For further information, see:
/// https://docs.opencv.org/master/de/d29/classcv_1_1img__hash_1_1ImgHashBase.html#a444a3e9ec792cf029385809393f84ad5
@override
double compare(InputArray hashOne, InputArray hashTwo) {
return _bindings.blockMeanHashCompare(hashOne.ptr, hashTwo.ptr, mode.index);
}

/// Compute computes hash of the input image using BlockMeanHash.
//
/// For further information, see:
/// https://docs.opencv.org/master/de/d29/classcv_1_1img__hash_1_1ImgHashBase.html#ae2d9288db370089dfd8aab85d5e0b0f3
@override
void compute(InputArray inputArr, OutputArray outputArr) {
return _bindings.blockMeanHashCompute(inputArr.ptr, outputArr.ptr, mode.index);
}

// TODO: BlockMeanHash.GetMean isn't implemented, because it requires state from the last
// call to Compute, and there's no easy way to keep it.

}


/// ColorMomentHash is implementation of the ColorMomentHash algorithm.
class ColorMomentHash implements ImgHashBase {

/// Compare compares the hash value between a and b using ColorMomentHash.
//
/// For further information, see:
/// https://docs.opencv.org/master/de/d29/classcv_1_1img__hash_1_1ImgHashBase.html#a444a3e9ec792cf029385809393f84ad5
@override
double compare(InputArray hashOne, InputArray hashTwo) {
return _bindings.colorMomentHashCompare(hashOne.ptr, hashTwo.ptr);
}

/// Compute computes hash of the input image using ColorMomentHash.
//
/// For further information, see:
/// https://docs.opencv.org/master/de/d29/classcv_1_1img__hash_1_1ImgHashBase.html#ae2d9288db370089dfd8aab85d5e0b0f3
@override
void compute(InputArray inputArr, OutputArray outputArr) {
return _bindings.colorMomentHashCompute(inputArr.ptr, outputArr.ptr);
}
}


/// MarrHildrethHash is implementation of the MarrHildrethHash algorithm.
class NewMarrHildrethHash implements ImgHashBase {

double alpha = 2.0;
double scale = 1.0;

NewMarrHildrethHash({this.alpha = 2.0, this.scale = 1.0});

/// Compare compares the hash value between a and b using MarrHildrethHash.
//
/// For further information, see:
/// https://docs.opencv.org/master/de/d29/classcv_1_1img__hash_1_1ImgHashBase.html#a444a3e9ec792cf029385809393f84ad5
@override
double compare(InputArray hashOne, InputArray hashTwo) {
return _bindings.marrHildrethHashCompare(hashOne.ptr, hashTwo.ptr, alpha, scale);
}

/// Compute computes hash of the input image using MarrHildrethHash.
//
/// For further information, see:
/// https://docs.opencv.org/master/de/d29/classcv_1_1img__hash_1_1ImgHashBase.html#ae2d9288db370089dfd8aab85d5e0b0f3
@override
void compute(InputArray inputArr, OutputArray outputArr) {
return _bindings.marrHildrethHashCompute(inputArr.ptr, outputArr.ptr, alpha, scale);
}
}


/// NewRadialVarianceHash is implementation of the NewRadialVarianceHash algorithm.
class NewRadialVarianceHash implements ImgHashBase {

double sigma = 1;
int numOfAngleLine = 180;

NewRadialVarianceHash({this.sigma = 1, this.numOfAngleLine = 180});

/// Compare compares the hash value between a and b using RadialVarianceHash.
//
/// For further information, see:
/// https://docs.opencv.org/master/de/d29/classcv_1_1img__hash_1_1ImgHashBase.html#a444a3e9ec792cf029385809393f84ad5
@override
double compare(InputArray hashOne, InputArray hashTwo) {
return _bindings.radialVarianceHashCompare(hashOne.ptr, hashTwo.ptr, sigma, numOfAngleLine);
}

/// Compute computes hash of the input image using RadialVarianceHash.
//
/// For further information, see:
/// https://docs.opencv.org/master/de/d29/classcv_1_1img__hash_1_1ImgHashBase.html#ae2d9288db370089dfd8aab85d5e0b0f3
@override
void compute(InputArray inputArr, OutputArray outputArr) {
return _bindings.radialVarianceHashCompute(inputArr.ptr, outputArr.ptr, sigma, numOfAngleLine);
}
}
1 change: 1 addition & 0 deletions lib/src/opencv.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export 'constants.g.dart';

export 'contrib/aruco.dart';
export 'contrib/aruco_dict.dart';
export 'contrib/img_hash.dart';

export 'core/asyncarray.dart';
export 'core/base.dart';
Expand Down
Loading
Loading