|
@ -1,11 +1,10 @@ |
|
|
package com.sothr.imagetools.engine.hash |
|
|
|
|
|
|
|
|
package com.sothr.imagetools.hash |
|
|
|
|
|
|
|
|
import java.io.File |
|
|
import java.io.File |
|
|
import javax.imageio.ImageIO |
|
|
import javax.imageio.ImageIO |
|
|
|
|
|
|
|
|
import com.sothr.imagetools.engine.dto.ImageHashDTO |
|
|
|
|
|
import com.sothr.imagetools.engine.{AppConfig, BaseTest, TestParams} |
|
|
|
|
|
import net.sf.ehcache.Element |
|
|
|
|
|
|
|
|
import com.sothr.imagetools.hash.`type`.DHash |
|
|
|
|
|
import com.sothr.imagetools.hash.dto.{HashSettingDTO, ImageHashDTO} |
|
|
|
|
|
|
|
|
import scala.collection.mutable |
|
|
import scala.collection.mutable |
|
|
|
|
|
|
|
@ -18,18 +17,21 @@ class HashServiceTest extends BaseTest { |
|
|
|
|
|
|
|
|
// Define the number of runs the benchmarking tests should use |
|
|
// Define the number of runs the benchmarking tests should use |
|
|
val benchmarkRuns = 10 |
|
|
val benchmarkRuns = 10 |
|
|
|
|
|
val ahashSetting = new HashSettingDTO(true, 8, 8, 0.75f) |
|
|
|
|
|
val dhashSetting = new HashSettingDTO(true, 8, 8, 0.85f) |
|
|
|
|
|
val phashSetting = new HashSettingDTO(true, 32, 8, 1.0f) |
|
|
|
|
|
|
|
|
def dhashTestCase(filePath: String): Long = { |
|
|
def dhashTestCase(filePath: String): Long = { |
|
|
val sample = new File(filePath) |
|
|
val sample = new File(filePath) |
|
|
val image = ImageIO.read(sample) |
|
|
val image = ImageIO.read(sample) |
|
|
HashService.getDhash(image) |
|
|
|
|
|
|
|
|
HashService.getDhash(dhashSetting, image) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
test("Benchmark DHash") { |
|
|
test("Benchmark DHash") { |
|
|
info("Benchmarking DHash") |
|
|
info("Benchmarking DHash") |
|
|
info("DHash Large Image 3684x2736") |
|
|
info("DHash Large Image 3684x2736") |
|
|
val time = new mutable.MutableList[Long]() |
|
|
val time = new mutable.MutableList[Long]() |
|
|
for (runNum <- 0 until benchmarkRuns) { |
|
|
|
|
|
|
|
|
for (_ <- 0 until benchmarkRuns) { |
|
|
time += getTime { |
|
|
time += getTime { |
|
|
dhashTestCase(TestParams.LargeSampleImage1) |
|
|
dhashTestCase(TestParams.LargeSampleImage1) |
|
|
} |
|
|
} |
|
@ -38,7 +40,7 @@ class HashServiceTest extends BaseTest { |
|
|
info(s"The mean time of ${time.size} tests for large was: $largeMean ms") |
|
|
info(s"The mean time of ${time.size} tests for large was: $largeMean ms") |
|
|
time.clear() |
|
|
time.clear() |
|
|
info("DHash Medium Image 1824x1368") |
|
|
info("DHash Medium Image 1824x1368") |
|
|
for (runNum <- 0 until benchmarkRuns) { |
|
|
|
|
|
|
|
|
for (_ <- 0 until benchmarkRuns) { |
|
|
time += getTime { |
|
|
time += getTime { |
|
|
dhashTestCase(TestParams.MediumSampleImage1) |
|
|
dhashTestCase(TestParams.MediumSampleImage1) |
|
|
} |
|
|
} |
|
@ -47,7 +49,7 @@ class HashServiceTest extends BaseTest { |
|
|
info(s"The mean time of ${time.size} tests for medium was: $mediumMean ms") |
|
|
info(s"The mean time of ${time.size} tests for medium was: $mediumMean ms") |
|
|
time.clear() |
|
|
time.clear() |
|
|
info("DHash Small Image 912x684") |
|
|
info("DHash Small Image 912x684") |
|
|
for (runNum <- 0 until benchmarkRuns) { |
|
|
|
|
|
|
|
|
for (_ <- 0 until benchmarkRuns) { |
|
|
time += getTime { |
|
|
time += getTime { |
|
|
dhashTestCase(TestParams.SmallSampleImage1) |
|
|
dhashTestCase(TestParams.SmallSampleImage1) |
|
|
} |
|
|
} |
|
@ -79,7 +81,7 @@ class HashServiceTest extends BaseTest { |
|
|
debug(s"Testing File: ${sample.getAbsolutePath} exists: ${sample.exists}") |
|
|
debug(s"Testing File: ${sample.getAbsolutePath} exists: ${sample.exists}") |
|
|
val image = ImageIO.read(sample) |
|
|
val image = ImageIO.read(sample) |
|
|
debug(s"Image: width: ${image.getWidth} height: ${image.getHeight}") |
|
|
debug(s"Image: width: ${image.getWidth} height: ${image.getHeight}") |
|
|
val hash = HashService.getDhash(image) |
|
|
|
|
|
|
|
|
val hash = HashService.getDhash(dhashSetting, image) |
|
|
debug(s"Testing that $hash = 4004374827879799635L") |
|
|
debug(s"Testing that $hash = 4004374827879799635L") |
|
|
assert(hash == 4004374827879799635L) |
|
|
assert(hash == 4004374827879799635L) |
|
|
} |
|
|
} |
|
@ -90,7 +92,7 @@ class HashServiceTest extends BaseTest { |
|
|
debug(s"Testing File: ${sample.getAbsolutePath} exists: ${sample.exists}") |
|
|
debug(s"Testing File: ${sample.getAbsolutePath} exists: ${sample.exists}") |
|
|
val image = ImageIO.read(sample) |
|
|
val image = ImageIO.read(sample) |
|
|
debug(s"Image: width: ${image.getWidth} height: ${image.getHeight}") |
|
|
debug(s"Image: width: ${image.getWidth} height: ${image.getHeight}") |
|
|
val hash = HashService.getDhash(image) |
|
|
|
|
|
|
|
|
val hash = HashService.getDhash(dhashSetting, image) |
|
|
debug(s"Testing that $hash = 4004374827879799635L") |
|
|
debug(s"Testing that $hash = 4004374827879799635L") |
|
|
assert(hash == 4004374827879799635L) |
|
|
assert(hash == 4004374827879799635L) |
|
|
} |
|
|
} |
|
@ -101,7 +103,7 @@ class HashServiceTest extends BaseTest { |
|
|
debug(s"Testing File: ${sample.getAbsolutePath} exists: ${sample.exists}") |
|
|
debug(s"Testing File: ${sample.getAbsolutePath} exists: ${sample.exists}") |
|
|
val image = ImageIO.read(sample) |
|
|
val image = ImageIO.read(sample) |
|
|
debug(s"Image: width: ${image.getWidth} height: ${image.getHeight}") |
|
|
debug(s"Image: width: ${image.getWidth} height: ${image.getHeight}") |
|
|
val hash = HashService.getDhash(image) |
|
|
|
|
|
|
|
|
val hash = HashService.getDhash(dhashSetting, image) |
|
|
debug(s"Testing that $hash = 4004383623972821843L") |
|
|
debug(s"Testing that $hash = 4004383623972821843L") |
|
|
assert(hash == 4004383623972821843L) |
|
|
assert(hash == 4004383623972821843L) |
|
|
} |
|
|
} |
|
@ -110,22 +112,22 @@ class HashServiceTest extends BaseTest { |
|
|
val largeHash = dhashTestCase(TestParams.LargeSampleImage1) |
|
|
val largeHash = dhashTestCase(TestParams.LargeSampleImage1) |
|
|
val mediumHash = dhashTestCase(TestParams.MediumSampleImage1) |
|
|
val mediumHash = dhashTestCase(TestParams.MediumSampleImage1) |
|
|
val smallHash = dhashTestCase(TestParams.SmallSampleImage1) |
|
|
val smallHash = dhashTestCase(TestParams.SmallSampleImage1) |
|
|
assert(HashService.areDhashSimilar(largeHash, mediumHash)) |
|
|
|
|
|
assert(HashService.areDhashSimilar(largeHash, smallHash)) |
|
|
|
|
|
assert(HashService.areDhashSimilar(mediumHash, smallHash)) |
|
|
|
|
|
|
|
|
assert(HashService.areHashSimilar(dhashSetting, largeHash, mediumHash)) |
|
|
|
|
|
assert(HashService.areHashSimilar(dhashSetting, largeHash, smallHash)) |
|
|
|
|
|
assert(HashService.areHashSimilar(dhashSetting, mediumHash, smallHash)) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
def ahashTestCase(filePath: String): Long = { |
|
|
def ahashTestCase(filePath: String): Long = { |
|
|
val sample = new File(filePath) |
|
|
val sample = new File(filePath) |
|
|
val image = ImageIO.read(sample) |
|
|
val image = ImageIO.read(sample) |
|
|
HashService.getAhash(image) |
|
|
|
|
|
|
|
|
HashService.getAhash(ahashSetting, image) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
test("Benchmark AHash") { |
|
|
test("Benchmark AHash") { |
|
|
info("Benchmarking AHash") |
|
|
info("Benchmarking AHash") |
|
|
info("AHash Large Image 3684x2736") |
|
|
info("AHash Large Image 3684x2736") |
|
|
val time = new mutable.MutableList[Long]() |
|
|
val time = new mutable.MutableList[Long]() |
|
|
for (runNum <- 0 until benchmarkRuns) { |
|
|
|
|
|
|
|
|
for (_ <- 0 until benchmarkRuns) { |
|
|
time += getTime { |
|
|
time += getTime { |
|
|
ahashTestCase(TestParams.LargeSampleImage1) |
|
|
ahashTestCase(TestParams.LargeSampleImage1) |
|
|
} |
|
|
} |
|
@ -134,7 +136,7 @@ class HashServiceTest extends BaseTest { |
|
|
info(s"The mean time of ${time.size} tests for large was: $largeMean ms") |
|
|
info(s"The mean time of ${time.size} tests for large was: $largeMean ms") |
|
|
time.clear() |
|
|
time.clear() |
|
|
info("AHash Medium Image 1824x1368") |
|
|
info("AHash Medium Image 1824x1368") |
|
|
for (runNum <- 0 until benchmarkRuns) { |
|
|
|
|
|
|
|
|
for (_ <- 0 until benchmarkRuns) { |
|
|
time += getTime { |
|
|
time += getTime { |
|
|
ahashTestCase(TestParams.MediumSampleImage1) |
|
|
ahashTestCase(TestParams.MediumSampleImage1) |
|
|
} |
|
|
} |
|
@ -143,7 +145,7 @@ class HashServiceTest extends BaseTest { |
|
|
info(s"The mean time of ${time.size} tests for medium was: $mediumMean ms") |
|
|
info(s"The mean time of ${time.size} tests for medium was: $mediumMean ms") |
|
|
time.clear() |
|
|
time.clear() |
|
|
info("AHash Small Image 912x684") |
|
|
info("AHash Small Image 912x684") |
|
|
for (runNum <- 0 until benchmarkRuns) { |
|
|
|
|
|
|
|
|
for (_ <- 0 until benchmarkRuns) { |
|
|
time += getTime { |
|
|
time += getTime { |
|
|
ahashTestCase(TestParams.SmallSampleImage1) |
|
|
ahashTestCase(TestParams.SmallSampleImage1) |
|
|
} |
|
|
} |
|
@ -160,7 +162,7 @@ class HashServiceTest extends BaseTest { |
|
|
debug(s"Testing File: ${sample.getAbsolutePath} exists: ${sample.exists}") |
|
|
debug(s"Testing File: ${sample.getAbsolutePath} exists: ${sample.exists}") |
|
|
val image = ImageIO.read(sample) |
|
|
val image = ImageIO.read(sample) |
|
|
debug(s"Image: width: ${image.getWidth} height: ${image.getHeight}") |
|
|
debug(s"Image: width: ${image.getWidth} height: ${image.getHeight}") |
|
|
val hash = HashService.getAhash(image) |
|
|
|
|
|
|
|
|
val hash = HashService.getAhash(ahashSetting, image) |
|
|
debug(s"Testing that $hash = 36070299219713907L") |
|
|
debug(s"Testing that $hash = 36070299219713907L") |
|
|
assert(hash == 36070299219713907L) |
|
|
assert(hash == 36070299219713907L) |
|
|
} |
|
|
} |
|
@ -171,7 +173,7 @@ class HashServiceTest extends BaseTest { |
|
|
debug(s"Testing File: ${sample.getAbsolutePath} exists: ${sample.exists}") |
|
|
debug(s"Testing File: ${sample.getAbsolutePath} exists: ${sample.exists}") |
|
|
val image = ImageIO.read(sample) |
|
|
val image = ImageIO.read(sample) |
|
|
debug(s"Image: width: ${image.getWidth} height: ${image.getHeight}") |
|
|
debug(s"Image: width: ${image.getWidth} height: ${image.getHeight}") |
|
|
val hash = HashService.getAhash(image) |
|
|
|
|
|
|
|
|
val hash = HashService.getAhash(ahashSetting, image) |
|
|
debug(s"Testing that $hash = 36070299219713907L") |
|
|
debug(s"Testing that $hash = 36070299219713907L") |
|
|
assert(hash == 36070299219713907L) |
|
|
assert(hash == 36070299219713907L) |
|
|
} |
|
|
} |
|
@ -182,7 +184,7 @@ class HashServiceTest extends BaseTest { |
|
|
debug(s"Testing File: ${sample.getAbsolutePath} exists: ${sample.exists}") |
|
|
debug(s"Testing File: ${sample.getAbsolutePath} exists: ${sample.exists}") |
|
|
val image = ImageIO.read(sample) |
|
|
val image = ImageIO.read(sample) |
|
|
debug(s"Image: width: ${image.getWidth} height: ${image.getHeight}") |
|
|
debug(s"Image: width: ${image.getWidth} height: ${image.getHeight}") |
|
|
val hash = HashService.getAhash(image) |
|
|
|
|
|
|
|
|
val hash = HashService.getAhash(ahashSetting, image) |
|
|
debug(s"Testing that $hash = 36070299219713907L") |
|
|
debug(s"Testing that $hash = 36070299219713907L") |
|
|
assert(hash == 36070299219713907L) |
|
|
assert(hash == 36070299219713907L) |
|
|
} |
|
|
} |
|
@ -191,22 +193,22 @@ class HashServiceTest extends BaseTest { |
|
|
val largeHash = ahashTestCase(TestParams.LargeSampleImage1) |
|
|
val largeHash = ahashTestCase(TestParams.LargeSampleImage1) |
|
|
val mediumHash = ahashTestCase(TestParams.MediumSampleImage1) |
|
|
val mediumHash = ahashTestCase(TestParams.MediumSampleImage1) |
|
|
val smallHash = ahashTestCase(TestParams.SmallSampleImage1) |
|
|
val smallHash = ahashTestCase(TestParams.SmallSampleImage1) |
|
|
assert(HashService.areAhashSimilar(largeHash, mediumHash)) |
|
|
|
|
|
assert(HashService.areAhashSimilar(largeHash, smallHash)) |
|
|
|
|
|
assert(HashService.areAhashSimilar(mediumHash, smallHash)) |
|
|
|
|
|
|
|
|
assert(HashService.areHashSimilar(ahashSetting, largeHash, mediumHash)) |
|
|
|
|
|
assert(HashService.areHashSimilar(ahashSetting, largeHash, smallHash)) |
|
|
|
|
|
assert(HashService.areHashSimilar(ahashSetting, mediumHash, smallHash)) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
def phashTestCase(filePath: String): Long = { |
|
|
def phashTestCase(filePath: String): Long = { |
|
|
val sample = new File(filePath) |
|
|
val sample = new File(filePath) |
|
|
val image = ImageIO.read(sample) |
|
|
val image = ImageIO.read(sample) |
|
|
HashService.getPhash(image) |
|
|
|
|
|
|
|
|
HashService.getPhash(phashSetting, image) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
test("Benchmark PHash") { |
|
|
test("Benchmark PHash") { |
|
|
info("Benchmarking PHash") |
|
|
info("Benchmarking PHash") |
|
|
info("PHash Large Image 3684x2736") |
|
|
info("PHash Large Image 3684x2736") |
|
|
val time = new mutable.MutableList[Long]() |
|
|
val time = new mutable.MutableList[Long]() |
|
|
for (runNum <- 0 until benchmarkRuns) { |
|
|
|
|
|
|
|
|
for (_ <- 0 until benchmarkRuns) { |
|
|
time += getTime { |
|
|
time += getTime { |
|
|
phashTestCase(TestParams.LargeSampleImage1) |
|
|
phashTestCase(TestParams.LargeSampleImage1) |
|
|
} |
|
|
} |
|
@ -215,7 +217,7 @@ class HashServiceTest extends BaseTest { |
|
|
info(s"The mean time of ${time.size} tests for large was: $largeMean ms") |
|
|
info(s"The mean time of ${time.size} tests for large was: $largeMean ms") |
|
|
time.clear() |
|
|
time.clear() |
|
|
info("PHash Medium Image 1824x1368") |
|
|
info("PHash Medium Image 1824x1368") |
|
|
for (runNum <- 0 until benchmarkRuns) { |
|
|
|
|
|
|
|
|
for (_ <- 0 until benchmarkRuns) { |
|
|
time += getTime { |
|
|
time += getTime { |
|
|
phashTestCase(TestParams.MediumSampleImage1) |
|
|
phashTestCase(TestParams.MediumSampleImage1) |
|
|
} |
|
|
} |
|
@ -224,7 +226,7 @@ class HashServiceTest extends BaseTest { |
|
|
info(s"The mean time of ${time.size} tests for medium was: $mediumMean ms") |
|
|
info(s"The mean time of ${time.size} tests for medium was: $mediumMean ms") |
|
|
time.clear() |
|
|
time.clear() |
|
|
info("PHash Small Image 912x684") |
|
|
info("PHash Small Image 912x684") |
|
|
for (runNum <- 0 until benchmarkRuns) { |
|
|
|
|
|
|
|
|
for (_ <- 0 until benchmarkRuns) { |
|
|
time += getTime { |
|
|
time += getTime { |
|
|
phashTestCase(TestParams.SmallSampleImage1) |
|
|
phashTestCase(TestParams.SmallSampleImage1) |
|
|
} |
|
|
} |
|
@ -241,7 +243,7 @@ class HashServiceTest extends BaseTest { |
|
|
debug(s"Testing File: ${sample.getAbsolutePath} exists: ${sample.exists}") |
|
|
debug(s"Testing File: ${sample.getAbsolutePath} exists: ${sample.exists}") |
|
|
val image = ImageIO.read(sample) |
|
|
val image = ImageIO.read(sample) |
|
|
debug(s"Image: width: ${image.getWidth} height: ${image.getHeight}") |
|
|
debug(s"Image: width: ${image.getWidth} height: ${image.getHeight}") |
|
|
val hash = HashService.getPhash(image) |
|
|
|
|
|
|
|
|
val hash = HashService.getPhash(phashSetting, image) |
|
|
debug(s"Testing that $hash = -9154554603604154117L") |
|
|
debug(s"Testing that $hash = -9154554603604154117L") |
|
|
assert(hash == -9154554603604154117L) |
|
|
assert(hash == -9154554603604154117L) |
|
|
} |
|
|
} |
|
@ -252,7 +254,7 @@ class HashServiceTest extends BaseTest { |
|
|
debug(s"Testing File: ${sample.getAbsolutePath} exists: ${sample.exists}") |
|
|
debug(s"Testing File: ${sample.getAbsolutePath} exists: ${sample.exists}") |
|
|
val image = ImageIO.read(sample) |
|
|
val image = ImageIO.read(sample) |
|
|
debug(s"Image: width: ${image.getWidth} height: ${image.getHeight}") |
|
|
debug(s"Image: width: ${image.getWidth} height: ${image.getHeight}") |
|
|
val hash = HashService.getPhash(image) |
|
|
|
|
|
|
|
|
val hash = HashService.getPhash(phashSetting, image) |
|
|
debug(s"Testing that $hash = -9154589787976242949L") |
|
|
debug(s"Testing that $hash = -9154589787976242949L") |
|
|
assert(hash == -9154589787976242949L) |
|
|
assert(hash == -9154589787976242949L) |
|
|
} |
|
|
} |
|
@ -263,7 +265,7 @@ class HashServiceTest extends BaseTest { |
|
|
debug(s"Testing File: ${sample.getAbsolutePath} exists: ${sample.exists}") |
|
|
debug(s"Testing File: ${sample.getAbsolutePath} exists: ${sample.exists}") |
|
|
val image = ImageIO.read(sample) |
|
|
val image = ImageIO.read(sample) |
|
|
debug(s"Image: width: ${image.getWidth} height: ${image.getHeight}") |
|
|
debug(s"Image: width: ${image.getWidth} height: ${image.getHeight}") |
|
|
val hash = HashService.getPhash(image) |
|
|
|
|
|
|
|
|
val hash = HashService.getPhash(phashSetting, image) |
|
|
debug(s"Testing that $hash = -9154589787976242949L") |
|
|
debug(s"Testing that $hash = -9154589787976242949L") |
|
|
assert(hash == -9154589787976242949L) |
|
|
assert(hash == -9154589787976242949L) |
|
|
} |
|
|
} |
|
@ -272,9 +274,9 @@ class HashServiceTest extends BaseTest { |
|
|
val largeHash = phashTestCase(TestParams.LargeSampleImage1) |
|
|
val largeHash = phashTestCase(TestParams.LargeSampleImage1) |
|
|
val mediumHash = phashTestCase(TestParams.MediumSampleImage1) |
|
|
val mediumHash = phashTestCase(TestParams.MediumSampleImage1) |
|
|
val smallHash = phashTestCase(TestParams.SmallSampleImage1) |
|
|
val smallHash = phashTestCase(TestParams.SmallSampleImage1) |
|
|
assert(HashService.arePhashSimilar(largeHash, mediumHash)) |
|
|
|
|
|
assert(HashService.arePhashSimilar(largeHash, smallHash)) |
|
|
|
|
|
assert(HashService.arePhashSimilar(mediumHash, smallHash)) |
|
|
|
|
|
|
|
|
assert(HashService.areHashSimilar(phashSetting, largeHash, mediumHash)) |
|
|
|
|
|
assert(HashService.areHashSimilar(phashSetting, largeHash, smallHash)) |
|
|
|
|
|
assert(HashService.areHashSimilar(phashSetting, mediumHash, smallHash)) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
def md5TestCase(filePath: String): String = { |
|
|
def md5TestCase(filePath: String): String = { |
|
@ -285,7 +287,7 @@ class HashServiceTest extends BaseTest { |
|
|
info("Benchmarking MD5") |
|
|
info("Benchmarking MD5") |
|
|
info("MD5 Large Image 3684x2736") |
|
|
info("MD5 Large Image 3684x2736") |
|
|
val time = new mutable.MutableList[Long]() |
|
|
val time = new mutable.MutableList[Long]() |
|
|
for (runNum <- 0 until benchmarkRuns) { |
|
|
|
|
|
|
|
|
for (_ <- 0 until benchmarkRuns) { |
|
|
time += getTime { |
|
|
time += getTime { |
|
|
md5TestCase(TestParams.LargeSampleImage1) |
|
|
md5TestCase(TestParams.LargeSampleImage1) |
|
|
} |
|
|
} |
|
@ -294,7 +296,7 @@ class HashServiceTest extends BaseTest { |
|
|
info(s"The mean time of ${time.size} tests for large was: $largeMean ms") |
|
|
info(s"The mean time of ${time.size} tests for large was: $largeMean ms") |
|
|
time.clear() |
|
|
time.clear() |
|
|
info("MD5 Medium Image 1824x1368") |
|
|
info("MD5 Medium Image 1824x1368") |
|
|
for (runNum <- 0 until benchmarkRuns) { |
|
|
|
|
|
|
|
|
for (_ <- 0 until benchmarkRuns) { |
|
|
time += getTime { |
|
|
time += getTime { |
|
|
md5TestCase(TestParams.MediumSampleImage1) |
|
|
md5TestCase(TestParams.MediumSampleImage1) |
|
|
} |
|
|
} |
|
@ -303,7 +305,7 @@ class HashServiceTest extends BaseTest { |
|
|
info(s"The mean time of ${time.size} tests for medium was: $mediumMean ms") |
|
|
info(s"The mean time of ${time.size} tests for medium was: $mediumMean ms") |
|
|
time.clear() |
|
|
time.clear() |
|
|
info("MD5 Small Image 912x684") |
|
|
info("MD5 Small Image 912x684") |
|
|
for (runNum <- 0 until benchmarkRuns) { |
|
|
|
|
|
|
|
|
for (_ <- 0 until benchmarkRuns) { |
|
|
time += getTime { |
|
|
time += getTime { |
|
|
md5TestCase(TestParams.SmallSampleImage1) |
|
|
md5TestCase(TestParams.SmallSampleImage1) |
|
|
} |
|
|
} |
|
@ -343,7 +345,7 @@ class HashServiceTest extends BaseTest { |
|
|
info("Benchmarking SHA1") |
|
|
info("Benchmarking SHA1") |
|
|
info("SHA1 Large Image 3684x2736") |
|
|
info("SHA1 Large Image 3684x2736") |
|
|
val time = new mutable.MutableList[Long]() |
|
|
val time = new mutable.MutableList[Long]() |
|
|
for (runNum <- 0 until benchmarkRuns) { |
|
|
|
|
|
|
|
|
for (_ <- 0 until benchmarkRuns) { |
|
|
time += getTime { |
|
|
time += getTime { |
|
|
sha1TestCase(TestParams.LargeSampleImage1) |
|
|
sha1TestCase(TestParams.LargeSampleImage1) |
|
|
} |
|
|
} |
|
@ -352,7 +354,7 @@ class HashServiceTest extends BaseTest { |
|
|
info(s"The mean time of ${time.size} tests for large was: $largeMean ms") |
|
|
info(s"The mean time of ${time.size} tests for large was: $largeMean ms") |
|
|
time.clear() |
|
|
time.clear() |
|
|
info("SHA1 Medium Image 1824x1368") |
|
|
info("SHA1 Medium Image 1824x1368") |
|
|
for (runNum <- 0 until benchmarkRuns) { |
|
|
|
|
|
|
|
|
for (_ <- 0 until benchmarkRuns) { |
|
|
time += getTime { |
|
|
time += getTime { |
|
|
sha1TestCase(TestParams.MediumSampleImage1) |
|
|
sha1TestCase(TestParams.MediumSampleImage1) |
|
|
} |
|
|
} |
|
@ -361,7 +363,7 @@ class HashServiceTest extends BaseTest { |
|
|
info(s"The mean time of ${time.size} tests for medium was: $mediumMean ms") |
|
|
info(s"The mean time of ${time.size} tests for medium was: $mediumMean ms") |
|
|
time.clear() |
|
|
time.clear() |
|
|
info("SHA1 Small Image 912x684") |
|
|
info("SHA1 Small Image 912x684") |
|
|
for (runNum <- 0 until benchmarkRuns) { |
|
|
|
|
|
|
|
|
for (_ <- 0 until benchmarkRuns) { |
|
|
time += getTime { |
|
|
time += getTime { |
|
|
sha1TestCase(TestParams.SmallSampleImage1) |
|
|
sha1TestCase(TestParams.SmallSampleImage1) |
|
|
} |
|
|
} |
|
@ -393,53 +395,8 @@ class HashServiceTest extends BaseTest { |
|
|
assert(hash == "1a91d2b5327f0aad258419f76b87d4c0bc343443") |
|
|
assert(hash == "1a91d2b5327f0aad258419f76b87d4c0bc343443") |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
def imageHashTestWithCacheCase(filePath: String): ImageHashDTO = { |
|
|
|
|
|
val cache = AppConfig.cacheManager.getCache("images") |
|
|
|
|
|
var result: ImageHashDTO = null |
|
|
|
|
|
if (cache.get(filePath) != null) { |
|
|
|
|
|
result = cache.get(filePath).getObjectValue.asInstanceOf[ImageHashDTO] |
|
|
|
|
|
} else { |
|
|
|
|
|
result = imageHashTestCase(filePath) |
|
|
|
|
|
cache.put(new Element(filePath, result)) |
|
|
|
|
|
} |
|
|
|
|
|
result |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
def imageHashTestCase(filePath: String): ImageHashDTO = { |
|
|
def imageHashTestCase(filePath: String): ImageHashDTO = { |
|
|
HashService.getImageHashes(filePath) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
test("Benchmark getImageHashes with cache") { |
|
|
|
|
|
info("Benchmarking getImageHashes with cache") |
|
|
|
|
|
info("getImageHashes with cache Large Image 3684x2736") |
|
|
|
|
|
val time = new mutable.MutableList[Long]() |
|
|
|
|
|
for (runNum <- 0 until benchmarkRuns) { |
|
|
|
|
|
time += getTime { |
|
|
|
|
|
imageHashTestWithCacheCase(TestParams.LargeSampleImage1) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
val largeMean = getMean(time.toArray[Long]) |
|
|
|
|
|
info(s"The mean time of ${time.size} tests for large was: $largeMean ms") |
|
|
|
|
|
time.clear() |
|
|
|
|
|
info("getImageHashes with cache Medium Image 1824x1368") |
|
|
|
|
|
for (runNum <- 0 until benchmarkRuns) { |
|
|
|
|
|
time += getTime { |
|
|
|
|
|
imageHashTestWithCacheCase(TestParams.MediumSampleImage1) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
val mediumMean = getMean(time.toArray[Long]) |
|
|
|
|
|
info(s"The mean time of ${time.size} tests for medium was: $mediumMean ms") |
|
|
|
|
|
time.clear() |
|
|
|
|
|
info("getImageHashes with cache Small Image 912x684") |
|
|
|
|
|
for (runNum <- 0 until benchmarkRuns) { |
|
|
|
|
|
time += getTime { |
|
|
|
|
|
imageHashTestWithCacheCase(TestParams.SmallSampleImage1) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
val smallMean = getMean(time.toArray[Long]) |
|
|
|
|
|
info(s"The mean time of ${time.size} tests for small was: $smallMean ms") |
|
|
|
|
|
time.clear() |
|
|
|
|
|
assert(true) |
|
|
|
|
|
|
|
|
HashService.getImageHashes(ahashSetting, dhashSetting, phashSetting, filePath) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
test("Benchmark getImageHashes") { |
|
|
test("Benchmark getImageHashes") { |
|
@ -479,28 +436,28 @@ class HashServiceTest extends BaseTest { |
|
|
val largeHash = imageHashTestCase(TestParams.LargeSampleImage1) |
|
|
val largeHash = imageHashTestCase(TestParams.LargeSampleImage1) |
|
|
val mediumHash = imageHashTestCase(TestParams.MediumSampleImage1) |
|
|
val mediumHash = imageHashTestCase(TestParams.MediumSampleImage1) |
|
|
val smallHash = imageHashTestCase(TestParams.SmallSampleImage1) |
|
|
val smallHash = imageHashTestCase(TestParams.SmallSampleImage1) |
|
|
assert(HashService.areImageHashesSimilar(largeHash, mediumHash)) |
|
|
|
|
|
assert(HashService.areImageHashesSimilar(largeHash, smallHash)) |
|
|
|
|
|
assert(HashService.areImageHashesSimilar(mediumHash, smallHash)) |
|
|
|
|
|
|
|
|
assert(HashService.areImageHashesSimilar(ahashSetting, dhashSetting, phashSetting, largeHash, mediumHash)) |
|
|
|
|
|
assert(HashService.areImageHashesSimilar(ahashSetting, dhashSetting, phashSetting, largeHash, smallHash)) |
|
|
|
|
|
assert(HashService.areImageHashesSimilar(ahashSetting, dhashSetting, phashSetting, mediumHash, smallHash)) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
test("Calculate ImageHash Large Sample Image 1") { |
|
|
test("Calculate ImageHash Large Sample Image 1") { |
|
|
debug("Starting 'Calculate ImageHash Large Sample Image 1' test") |
|
|
debug("Starting 'Calculate ImageHash Large Sample Image 1' test") |
|
|
val hash = HashService.getImageHashes(TestParams.LargeSampleImage1) |
|
|
|
|
|
|
|
|
val hash = HashService.getImageHashes(ahashSetting, dhashSetting, phashSetting, TestParams.LargeSampleImage1) |
|
|
debug(s"Testing that ${hash.hashCode()} = -812844858") |
|
|
debug(s"Testing that ${hash.hashCode()} = -812844858") |
|
|
assert(hash.hashCode == -812844858) |
|
|
assert(hash.hashCode == -812844858) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
test("Calculate ImageHash Medium Sample Image 1") { |
|
|
test("Calculate ImageHash Medium Sample Image 1") { |
|
|
debug("Starting 'Calculate ImageHash Medium Sample Image 1' test") |
|
|
debug("Starting 'Calculate ImageHash Medium Sample Image 1' test") |
|
|
val hash = HashService.getImageHashes(TestParams.MediumSampleImage1) |
|
|
|
|
|
|
|
|
val hash = HashService.getImageHashes(ahashSetting, dhashSetting, phashSetting, TestParams.MediumSampleImage1) |
|
|
debug(s"Testing that ${hash.hashCode()} = -812836666") |
|
|
debug(s"Testing that ${hash.hashCode()} = -812836666") |
|
|
assert(hash.hashCode == -812836666) |
|
|
assert(hash.hashCode == -812836666) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
test("Calculate ImageHash Small Sample Image 1") { |
|
|
test("Calculate ImageHash Small Sample Image 1") { |
|
|
debug("Starting 'Calculate ImageHash Small Sample Image 1' test") |
|
|
debug("Starting 'Calculate ImageHash Small Sample Image 1' test") |
|
|
val hash = HashService.getImageHashes(TestParams.SmallSampleImage1) |
|
|
|
|
|
|
|
|
val hash = HashService.getImageHashes(ahashSetting, dhashSetting, phashSetting, TestParams.SmallSampleImage1) |
|
|
debug(s"Testing that ${hash.hashCode()} = -812840762") |
|
|
debug(s"Testing that ${hash.hashCode()} = -812840762") |
|
|
assert(hash.hashCode == -812840762) |
|
|
assert(hash.hashCode == -812840762) |
|
|
} |
|
|
} |