github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/libraries/gopha/gopha_test.go (about) 1 // Copyright 2013 Unknown 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"): you may 4 // not use this file except in compliance with the License. You may obtain 5 // a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 // License for the specific language governing permissions and limitations 13 // under the License. 14 15 // Package gopha is an implementation of Perceptual Hash Algorithm in Go programming language. 16 package gopha 17 18 import ( 19 "fmt" 20 "image" 21 _ "image/gif" 22 _ "image/jpeg" 23 _ "image/png" 24 "os" 25 "testing" 26 ) 27 28 func TestPHA(t *testing.T) { 29 // Load picture from file. 30 infile, err := os.Open("./testdata/pic_output.png") 31 if err != nil { 32 t.Errorf("Load picture: %s.", err) 33 } 34 35 // Decode picture. 36 srcImg, _, err := image.Decode(infile) 37 infile.Close() 38 if err != nil { 39 t.Errorf("Decode picture: %s.", err) 40 } 41 42 fg := PHA(srcImg) 43 fmt.Println("Fingerprint:", fg) 44 45 // Load picture2 from file. 46 infile, err = os.Open("./testdata/pic_output2.jpg") 47 if err != nil { 48 t.Errorf("Load picture2: %s.", err) 49 } 50 51 // Decode picture. 52 srcImg, _, err = image.Decode(infile) 53 infile.Close() 54 if err != nil { 55 t.Errorf("Decode picture2: %s.", err) 56 } 57 58 fg2 := PHA(srcImg) 59 fmt.Println("Fingerprint:", fg2) 60 61 fmt.Println("Diff num:", CompareDiff(fg, fg2)) 62 }