Commit 4e7f8c4d authored by wanglei's avatar wanglei

...

parent b2bd8bb9
......@@ -82,7 +82,6 @@ dependencies {
//图片处理
implementation 'org.opencv:opencv:4.10.0'
implementation("org.opencv:opencv:4.10.0")
//网络
implementation group: 'com.google.code.gson', name: 'gson', version: '2.10.1'
......
......@@ -36,8 +36,9 @@ object SimilarHelper {
// LogEx.logDebug(TAG, "compareItem=$compareItem")
if (item.path != compareItem.path) {
val percent = opencvCompareSimilar(item.path, compareItem.path)
if (percent > 98.5) {
// val percent = opencvCompareSimilar(item.path, compareItem.path)
val percent = similarPercent(File(item.path), File(compareItem.path))
if (percent > 60) {
if (result[item.path] == null) {
LogEx.logDebug(TAG, "item=$item")
result[item.path] = arrayListOf()
......@@ -62,37 +63,71 @@ object SimilarHelper {
}
// private fun similarPercent(srcFile: File, compareFile: File): Int {
// var similarityScore: Double = 0.00
// try {
// val bitmap1 = BitmapFactory.decodeFile(srcFile.absolutePath)
// val bitmap2 = BitmapFactory.decodeFile(compareFile.absolutePath)
//
// if (bitmap1.width != bitmap2.width || bitmap1.height != bitmap2.height) {
// return 0 // 如果尺寸不同,则直接返回0
// }
//
// var totalDifference = 0L
// for (x in 0 until bitmap1.width) {
// for (y in 0 until bitmap1.height) {
// val pixel1 = bitmap1.getPixel(x, y)
// val pixel2 = bitmap2.getPixel(x, y)
// val redDifference = (pixel1 shr 16 and 0xff) - (pixel2 shr 16 and 0xff)
// val greenDifference = (pixel1 shr 8 and 0xff) - (pixel2 shr 8 and 0xff)
// val blueDifference = (pixel1 and 0xff) - (pixel2 and 0xff)
// totalDifference += (redDifference * redDifference + greenDifference * greenDifference + blueDifference * blueDifference)
// }
// }
//
// // 计算相似度得分
// val maxDifference = bitmap1.width * bitmap1.height * 3 * 255 * 255
// similarityScore = (1 - totalDifference.toDouble() / maxDifference) * 100
//
// } catch (e: Exception) {
// e.printStackTrace()
// }
//
// // 将相似度得分四舍五入到整数
// return similarityScore.toInt().coerceIn(0, 100)
// }
private fun similarPercent(srcFile: File, compareFile: File): Int {
var similarityScore: Double = 0.00
try {
val bitmap1 = BitmapFactory.decodeFile(srcFile.absolutePath)
val bitmap2 = BitmapFactory.decodeFile(compareFile.absolutePath)
if (bitmap1.width != bitmap2.width || bitmap1.height != bitmap2.height) {
return 0 // 如果尺寸不同,则直接返回0
}
val width = bitmap1.width
val height = bitmap1.height
val maxDifference = width * height * 3 * 255 * 255
var totalDifference = 0L
for (x in 0 until bitmap1.width) {
for (y in 0 until bitmap1.height) {
val pixel1 = bitmap1.getPixel(x, y)
val pixel2 = bitmap2.getPixel(x, y)
val redDifference = (pixel1 shr 16 and 0xff) - (pixel2 shr 16 and 0xff)
val greenDifference = (pixel1 shr 8 and 0xff) - (pixel2 shr 8 and 0xff)
val blueDifference = (pixel1 and 0xff) - (pixel2 and 0xff)
totalDifference += (redDifference * redDifference + greenDifference * greenDifference + blueDifference * blueDifference)
}
val pixel1 = IntArray(1)
val pixel2 = IntArray(1)
for (x in 0 until width) {
for (y in 0 until height) {
bitmap1.getPixel(x, y)
bitmap2.getPixel(x, y)
val red1 = pixel1[0] shr 16 and 0xff
val green1 = pixel1[0] shr 8 and 0xff
val blue1 = pixel1[0] and 0xff
val red2 = pixel2[0] shr 16 and 0xff
val green2 = pixel2[0] shr 8 and 0xff
val blue2 = pixel2[0] and 0xff
val redDiff = (red1 - red2) * (red1 - red2)
val greenDiff = (green1 - green2) * (green1 - green2)
val blueDiff = (blue1 - blue2) * (blue1 - blue2)
totalDifference += (redDiff + greenDiff + blueDiff)
}
// 计算相似度得分
val maxDifference = bitmap1.width * bitmap1.height * 3 * 255 * 255
similarityScore = (1 - totalDifference.toDouble() / maxDifference) * 100
} catch (e: Exception) {
e.printStackTrace()
}
// 将相似度得分四舍五入到整数
val similarityScore = (1 - totalDifference.toDouble() / maxDifference) * 100
return similarityScore.toInt().coerceIn(0, 100)
}
......
{
"project_info": {
"project_number": "944507974954",
"project_id": "dumpster-photo-recovery",
"storage_bucket": "dumpster-photo-recovery.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:944507974954:android:1309986ccc55e242589a53",
"android_client_info": {
"package_name": "com.baloota.photorecyclebin.awm.sp"
}
},
"oauth_client": [],
"api_key": [
{
"current_key": "AIzaSyDBejd5HFvww_CVve-aFYRBjR-d6XwIBFA"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": []
}
}
}
],
"configuration_version": "1"
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment