Ejemplo n.º 1
0
 // Constructor
 public UnfoldedBindingComparisonPair(int _threshold, ImageSourceBinding _binding0, ImageSourceBinding _binding1,
                                      ImageSource _src0, ImageSource _src1, ComparativeData _radish,
                                      ComparativeData _dct, ComparativeData _wavelet, ComparativeData _bmb)
 {
     // Copy
     m_threshold       = _threshold;
     m_binding0        = _binding0;
     m_binding1        = _binding1;
     m_sourceBinding0  = _src0;
     m_sourceBinding1  = _src1;
     m_compDataRADISH  = _radish;
     m_compDataDCT     = _dct;
     m_compDataWavelet = _wavelet;
     m_compDataBMB     = _bmb;
 }
Ejemplo n.º 2
0
        // Override: HashData::compareHashData
        public override ComparativeData compareHashData(HashData _data0, HashData _data1)
        {
            // Local variables
            ComparativeData data = null;

            // Check parameter
            if (_data0 == null || _data1 == null)
            {
                return(null);
            }
            if (_data0.getDataType() != getHashDataType() || _data1.getDataType() != getHashDataType())
            {
                return(null);
            }

            // Compare hash data
            data = m_funcComp(this, (HashData <_HR>)_data0, (HashData <_HR>)_data1);

            return(data);
        }
Ejemplo n.º 3
0
        // Override: HashData::containsComparativeDataDefaultValue
        public override bool containsComparativeDataDefaultValue(ComparativeData _data)
        {
            // Local variables
            ComparativeData <_CR> typedData = null;

            // Check parameter
            if (_data == null || _data.getDataType() != getComparatorDataType())
            {
                return(false);
            }
            typedData = (ComparativeData <_CR>)_data;

            // The default value?
            if (EqualityComparer <_CR> .Default.Equals(typedData.Data, default(_CR)))
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 4
0
        // Event: Button::Click: Compute
        private void onButtonComputeClicked(object _sender, EventArgs _e)
        {
            // Local variables
            Job <ComparativeData> jg = null;

            // Validate
            if (m_controlImageSourceSelection0.Source == null || m_controlImageSourceSelection1.Source == null)
            {
                MessageBox.Show(MSG_ERROR_IMAGES_NOT_SET, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // Prepare
            m_controlButtonCompute.Enabled = false;
            lockTechniqueSelection();
            m_controlImageSourceSelection0.lockImageSourceSelection();
            m_controlImageSourceSelection1.lockImageSourceSelection();
            m_controlProgressBar.Visible = m_controlProgressBar.Enabled = true;

            // Set states: computing
            m_controlImageSourceSelection0.setInstructionText(STATE_COMPUTING_HASH);
            m_controlImageSourceSelection1.setInstructionText(STATE_COMPUTING_HASH);

            // Create job
            jg = new Job <ComparativeData>((JobParameter <ComparativeData> _params) =>
            {
                // Local variables
                ComparativeData result = null;
                Job <HashData> j0      = null, j1 = null;

                // Create jobs: computing hashes
                j0 = Job <HashData> .createJobComputeHash(m_controlImageSourceSelection0.Source, SingleModeTechnique,
                                                          (JobParameter <HashData> _r) =>
                {
                    // Display hash
                    m_controlImageSourceSelection0.setInstructionText(_r.Result.convertToString());
                },
                                                          false);
                j1 = Job <HashData> .createJobComputeHash(m_controlImageSourceSelection1.Source, SingleModeTechnique,
                                                          (JobParameter <HashData> _r) =>
                {
                    // Display hash
                    m_controlImageSourceSelection1.setInstructionText(_r.Result.convertToString());
                },
                                                          false);

                // Start jobs
                Job <HashData> .enqueue(j0);
                Job <HashData> .enqueue(j1);

                // Wait for jobs
                j0.waitForDone();
                j1.waitForDone();

                // Compare hashes
                result = SingleModeTechnique.compareHashData(m_controlImageSourceSelection0.Source, m_controlImageSourceSelection1.Source);

                return(result);
            },
                                           (JobParameter <ComparativeData> _r) =>
            {
                // Run in GUI thread
                Utility.invokeInGuiThread(m_tabPage, delegate
                {
                    // Set result or error
                    if (_r.Error != null)
                    {
                        m_controlLabelResult.Text = _r.Error.Message;
                    }
                    else if (_r == null || _r.Result == null)
                    {
                        m_controlLabelResult.Text = MSG_ERROR_COMPUTATION;
                    }
                    else
                    {
                        m_controlLabelResult.Text = _r.Result.convertToString();
                    }

                    // Accepted?
                    if (_r != null && _r.Result != null)
                    {
                        if (_r.Result.isAccepted() == true)
                        {
                            m_controlLabelResult.ForeColor = System.Drawing.Color.DarkGreen;
                        }
                        else
                        {
                            m_controlLabelResult.ForeColor = System.Drawing.Color.DarkRed;
                        }
                    }

                    // Undo the preparations
                    m_controlButtonCompute.Enabled = true;
                    unlockTechniqueSelection();
                    m_controlImageSourceSelection0.unlockImageSourceSelection();
                    m_controlImageSourceSelection1.unlockImageSourceSelection();
                    m_controlProgressBar.Visible = m_controlProgressBar.Enabled = false;
                });
            });
        }
Ejemplo n.º 5
0
        // Create the default technique instance for the algorithm: BMB
        public static Technique <BMBHash, double> createTechniqueBMB()
        {
            // Local variables
            Technique <BMBHash, double> t = null;

            // Create technique
            t = new Technique <BMBHash, double>(TechniqueID.BMB,
                                                (Technique _t, ImageSource _image, string[] _dumpToDiskPathes) =>
            {
                // Local variables
                BMBHash hash                   = new BMBHash();
                IntPtr hashUnmanaged           = IntPtr.Zero;
                HashComputationTimings timings = new HashComputationTimings();
                HashData <BMBHash> result      = null;
                int attMethod                  = 1;

                // Extract attributes
                if (_t.isAttributeAvailable(Technique.ATT_BMB_METHOD) == true)
                {
                    _t.getAttribute <int>(Technique.ATT_BMB_METHOD, out attMethod);
                }

                // Dump to disk?
                if (_dumpToDiskPathes != null && _dumpToDiskPathes.Length == DumpTechniqueStepsToDisk.BMB_PATH_COUNT)
                {
                    if (PHash.dumpBMBHashToDisk(_image.FilePath, attMethod, _dumpToDiskPathes[0], _dumpToDiskPathes[1], _dumpToDiskPathes[2]) != 0)
                    {
                        return(null);
                    }
                    return(new HashData <BMBHash>(null));
                }
                else
                {
                    // Comnpute hash
                    if (PHash.computeBMBHash(_image.FilePath, attMethod, out hashUnmanaged, timings) == -1)
                    {
                        return(null);
                    }

                    // Convert unmanaged to managed
                    Utility.convertUnmanagedPtrToSimpleStructure <BMBHash>(hashUnmanaged, ref hash, false);

                    // Store result
                    result = new HashData <BMBHash>(hash, (BMBHash _data) =>
                    {
                        return(Utility.toHexString(_data.m_data, _data.m_dataLength));
                    },
                                                    new HashDataTimings(timings.m_imageLoadingTimeMS, timings.m_hashComputationTimeMS));

                    return(result);
                }
            },
                                                (Technique _t, HashData <BMBHash> _h0, HashData <BMBHash> _h1) =>
            {
                // Local variables
                double dis        = 0;
                decimal threshold = 90m;
                bool isSame       = false;
                ComparativeData <double> result = null;

                // Extract attributes
                if (_t.isAttributeAvailable(Technique.ATT_GENERAL_THRESHOLD) == true)
                {
                    _t.getAttribute <decimal>(Technique.ATT_GENERAL_THRESHOLD, out threshold);
                }

                // Compute distance
                dis = PHash.computeHammingDistance(_h0.Data.m_data, _h0.Data.m_dataLength, _h1.Data.m_data, _h1.Data.m_dataLength);

                // Is accepted?
                isSame = (1.0 - dis) >= Convert.ToSingle(threshold) / 100.0;

                // Store result
                result = new ComparativeData <double>(dis, isSame, (double _d) =>
                {
                    return("Match rate: " + (1.0 - _d).ToString("#0.0000"));
                },
                                                      (double _d) =>
                {
                    return(1.0 - _d);
                });

                return(result);
            }
                                                );

            return(t);
        }
Ejemplo n.º 6
0
        // Create the default technique instance for the algorithm: wavelet
        public static Technique <WaveletHash, double> createTechniqueWavelet()
        {
            // Local variables
            Technique <WaveletHash, double> t = null;

            // Create technique
            t = new Technique <WaveletHash, double>(TechniqueID.WAVELET,
                                                    (Technique _t, ImageSource _image, string[] _dumpToDiskPathes) =>
            {
                // Local variables
                int len = 0;
                IntPtr hash;
                WaveletHash data = new WaveletHash();
                HashData <WaveletHash> result  = null;
                HashComputationTimings timings = new HashComputationTimings();
                decimal attAlpha = 2m;
                decimal attLevel = 1m;

                // Extract attributes
                if (_t.isAttributeAvailable(Technique.ATT_WAVELET_ALPHA) == true)
                {
                    _t.getAttribute <decimal>(Technique.ATT_WAVELET_ALPHA, out attAlpha);
                }
                if (_t.isAttributeAvailable(Technique.ATT_WAVELET_LEVEL) == true)
                {
                    _t.getAttribute <decimal>(Technique.ATT_WAVELET_LEVEL, out attLevel);
                }

                // Dump to disk?
                if (_dumpToDiskPathes != null && _dumpToDiskPathes.Length == DumpTechniqueStepsToDisk.WAVELET_PATH_COUNT)
                {
                    if (PHash.dumpWaveletHashToDisk(_image.FilePath, Convert.ToSingle(attAlpha), Convert.ToSingle(attLevel),
                                                    _dumpToDiskPathes[0], _dumpToDiskPathes[1], _dumpToDiskPathes[2],
                                                    _dumpToDiskPathes[3]) != 0)
                    {
                        return(null);
                    }
                    return(new HashData <WaveletHash>(null));
                }
                else
                {
                    // Compute hast
                    hash = PHash.computeWaveletHash(_image.FilePath, ref len, timings, Convert.ToSingle(attAlpha), Convert.ToSingle(attLevel));

                    // Store result
                    data.m_data       = hash;
                    data.m_dataLength = len;
                    result            = new HashData <WaveletHash>(data, (WaveletHash _data) =>
                    {
                        return(Utility.toHexString(_data.m_data, _data.m_dataLength));
                    },
                                                                   new HashDataTimings(timings.m_imageLoadingTimeMS, timings.m_hashComputationTimeMS));
                    return(result);
                }
            },
                                                    (Technique _t, HashData <WaveletHash> _h0, HashData <WaveletHash> _h1) =>
            {
                // Local variables
                double dis        = 0;
                decimal threshold = 90m;
                bool isSame       = false;
                ComparativeData <double> result = null;

                // Extract attributes
                if (_t.isAttributeAvailable(Technique.ATT_GENERAL_THRESHOLD) == true)
                {
                    _t.getAttribute <decimal>(Technique.ATT_GENERAL_THRESHOLD, out threshold);
                }

                // Compute distance
                dis = PHash.computeHammingDistance(_h0.Data.m_data, _h0.Data.m_dataLength, _h1.Data.m_data, _h1.Data.m_dataLength);

                // Is accepted?
                isSame = (1.0 - dis) >= Convert.ToSingle(threshold) / 100.0;

                // Store result
                result = new ComparativeData <double>(dis, isSame, (double _d) =>
                {
                    return("Match rate: " + (1.0 - _d).ToString("#0.0000"));
                },
                                                      (double _d) =>
                {
                    return(1.0 - _d);
                });
                return(result);
            }
                                                    );

            return(t);
        }
Ejemplo n.º 7
0
        // Create the default technique instance for the algorithm: DCT
        public static Technique <UInt64, double> createTechniqueDCT()
        {
            // Local variables
            Technique <UInt64, double> t = null;

            // Create technique
            t = new Technique <UInt64, double>(TechniqueID.DCT,
                                               (Technique _t, ImageSource _image, string[] _dumpToDiskPathes) =>
            {
                // Local variables
                UInt64 hash = 0;
                HashData <UInt64> result       = null;
                HashComputationTimings timings = new HashComputationTimings();

                // Dump to disk?
                if (_dumpToDiskPathes != null && _dumpToDiskPathes.Length == DumpTechniqueStepsToDisk.DCT_PATH_COUNT)
                {
                    if (PHash.dumpDCTHashToDisk(_image.FilePath, _dumpToDiskPathes[0], _dumpToDiskPathes[1], _dumpToDiskPathes[2],
                                                _dumpToDiskPathes[3], _dumpToDiskPathes[4], _dumpToDiskPathes[5]) != 0)
                    {
                        return(null);
                    }
                    return(new HashData <ulong>(0));
                }
                else
                {
                    // Compute hast
                    PHash.computeDCTHash(_image.FilePath, ref hash, timings);

                    // Store result
                    result = new HashData <UInt64>(hash, null, new HashDataTimings(timings.m_imageLoadingTimeMS, timings.m_hashComputationTimeMS));
                    return(result);
                }
            },
                                               (Technique _t, HashData <UInt64> _h0, HashData <UInt64> _h1) =>
            {
                // Local variables
                double dis        = 0;
                bool isSame       = false;
                decimal threshold = 90m;
                ComparativeData <double> result = null;

                // Extract attributes
                if (_t.isAttributeAvailable(Technique.ATT_GENERAL_THRESHOLD) == true)
                {
                    _t.getAttribute <decimal>(Technique.ATT_GENERAL_THRESHOLD, out threshold);
                }

                // Compute distance and normalize it
                dis  = PHash.computeHammingDistance(_h0.Data, _h1.Data);
                dis /= 64;

                // Is accepted?
                isSame = (1.0 - dis) >= Convert.ToSingle(threshold) / 100.0;

                // Store result
                result = new ComparativeData <double>(dis, isSame, (double _d) =>
                {
                    return("Match rate: " + (1.0 - _d).ToString("#0.0000"));
                },
                                                      (double _d) =>
                {
                    return(1.0f - _d);
                });
                return(result);
            }
                                               );

            return(t);
        }
Ejemplo n.º 8
0
 // Checks whether the comparative data contains the default value for its internal type
 public abstract bool containsComparativeDataDefaultValue(ComparativeData _data);
Ejemplo n.º 9
0
 // Adds the comparison data for a certain technique
 public void setComparisonDataFor(TechniqueID _id, ComparativeData _data)
 {
     m_comparisonData.Add(_id, _data);
 }