|
| 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 | +} |
0 commit comments