diff --git a/.gitignore b/.gitignore index 39b6783c..9b7f1951 100644 --- a/.gitignore +++ b/.gitignore @@ -1,65 +1,15 @@ -# Built application files -*.apk -*.ap_ - -# Files for the ART/Dalvik VM -*.dex - -# Java class files -*.class - -# Generated files -bin/ -gen/ -out/ - -# Gradle files -.gradle/ -build/ - -# Local configuration file (sdk path, etc) -local.properties - -# Proguard folder generated by Eclipse -proguard/ - -# Log Files -*.log - -# Android Studio Navigation editor temp files -.navigation/ - -# Android Studio captures folder -captures/ - -# IntelliJ *.iml -.idea/workspace.xml -.idea/tasks.xml -.idea/gradle.xml -.idea/assetWizardSettings.xml -.idea/dictionaries -.idea/libraries -.idea/caches - -# Keystore files -# Uncomment the following line if you do not want to check your keystore files in. -#*.jks - -# External native build folder generated in Android Studio 2.2 and later +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures .externalNativeBuild - -# Google Services (e.g. APIs or Firebase) -google-services.json - -# Freeline -freeline.py -freeline/ -freeline_project_description.json - -# fastlane -fastlane/report.xml -fastlane/Preview.html -fastlane/screenshots -fastlane/test_output -fastlane/readme.md +/nsfw +nsfw \ No newline at end of file diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 00000000..1bec35e5 --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,10 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 00000000..79ee123c --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/dictionaries/jason.xml b/.idea/dictionaries/jason.xml new file mode 100644 index 00000000..b1fa4fce --- /dev/null +++ b/.idea/dictionaries/jason.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 00000000..15a15b21 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 00000000..b0bb1ce5 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,20 @@ + + + + + + \ No newline at end of file diff --git a/.idea/markdown-navigator.xml b/.idea/markdown-navigator.xml new file mode 100644 index 00000000..6b82ce2a --- /dev/null +++ b/.idea/markdown-navigator.xml @@ -0,0 +1,86 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/markdown-navigator/profiles_settings.xml b/.idea/markdown-navigator/profiles_settings.xml new file mode 100644 index 00000000..db062663 --- /dev/null +++ b/.idea/markdown-navigator/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 00000000..25f24431 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,42 @@ + + + + + + + + + Android + + + CorrectnessLintAndroid + + + Internationalization + + + Java + + + Java 9Java language level migration aidsJava + + + Java language level migration aidsJava + + + LintAndroid + + + PerformanceJava + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 00000000..7f68460d --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..94a25f7f --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/README.md b/README.md deleted file mode 100644 index c088bf13..00000000 --- a/README.md +++ /dev/null @@ -1,2 +0,0 @@ -# open_nsfw_android -色情图片离线识别,200ms diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 00000000..796b96d1 --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 00000000..24dab761 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,47 @@ +apply plugin: 'com.android.application' + +apply plugin: 'kotlin-android' + +apply plugin: 'kotlin-android-extensions' + +android { + compileSdkVersion 28 + defaultConfig { + applicationId "com.example.open_nsfw_android" + minSdkVersion 15 + targetSdkVersion 28 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + } + buildTypes { + release { + minifyEnabled true //开启混淆 + zipAlignEnabled true //压缩优化 + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + debug{ + minifyEnabled true //开启混淆 + zipAlignEnabled true //压缩优化 + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + + aaptOptions { + noCompress "tflite" + } +} + +dependencies { + implementation fileTree(include: ['*.jar'], dir: 'libs') + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation 'com.android.support:appcompat-v7:28.0.0' + implementation 'com.android.support.constraint:constraint-layout:1.1.3' + testImplementation 'junit:junit:4.12' + androidTestImplementation 'com.android.support.test:runner:1.0.2' + androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' + implementation files('libs/nsfw.aar') + + implementation 'org.tensorflow:tensorflow-lite:+' + implementation 'org.tensorflow:tensorflow-lite-gpu:+' +} diff --git a/app/libs/nsfw.aar b/app/libs/nsfw.aar new file mode 100644 index 00000000..d6caa9d4 Binary files /dev/null and b/app/libs/nsfw.aar differ diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 00000000..41b6943c --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,20 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. diff --git a/app/src/androidTest/java/com/example/open_nsfw_android/ExampleInstrumentedTest.kt b/app/src/androidTest/java/com/example/open_nsfw_android/ExampleInstrumentedTest.kt new file mode 100644 index 00000000..1fb2380f --- /dev/null +++ b/app/src/androidTest/java/com/example/open_nsfw_android/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package com.example.open_nsfw_android + +import android.support.test.InstrumentationRegistry +import android.support.test.runner.AndroidJUnit4 + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getTargetContext() + assertEquals("com.example.open_nsfw_android", appContext.packageName) + } +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 00000000..32d317fd --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/assets/aaa.png b/app/src/main/assets/aaa.png new file mode 100644 index 00000000..753537f5 Binary files /dev/null and b/app/src/main/assets/aaa.png differ diff --git a/app/src/main/assets/ccc.gif b/app/src/main/assets/ccc.gif new file mode 100644 index 00000000..97a277fb Binary files /dev/null and b/app/src/main/assets/ccc.gif differ diff --git a/app/src/main/assets/timg-10.jpeg b/app/src/main/assets/timg-10.jpeg new file mode 100644 index 00000000..c471c61b Binary files /dev/null and b/app/src/main/assets/timg-10.jpeg differ diff --git a/app/src/main/java/com/example/open_nsfw_android/MainActivity.kt b/app/src/main/java/com/example/open_nsfw_android/MainActivity.kt new file mode 100644 index 00000000..fe72ef48 --- /dev/null +++ b/app/src/main/java/com/example/open_nsfw_android/MainActivity.kt @@ -0,0 +1,42 @@ +package com.example.open_nsfw_android + +import android.graphics.BitmapFactory +import android.os.Bundle +import android.support.v7.app.AppCompatActivity +import android.util.Log +import com.zwy.nsfw.api.NsfwHelper +import kotlinx.android.synthetic.main.activity_main.* + + +class MainActivity : AppCompatActivity() { + var nsfwHelper: NsfwHelper? = null; + + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + //assets 目录下的timg-10.jpeg为正常静态图片 ccc.gif 为动态正常图片 可用作测试 + val b = BitmapFactory.decodeStream(getResources().getAssets().open("ccc.gif")) + iv.setImageBitmap(b) + nsfwHelper = NsfwHelper.getInstance(this, true, 1) + + + bt_.setOnClickListener { + //同步识别 + val nsfwBean = nsfwHelper?.scanBitmapSyn(b) + Log.d("demo", nsfwBean.toString()) + tvv.setText("识别成功:\n\tSFW score : ${nsfwBean?.sfw}\n\tNSFW score : ${nsfwBean?.nsfw}") + if (nsfwBean?.nsfw ?: 0f > 0.7) { + tvv.text = "${tvv.text.toString()} \n \t - 色情图片" + }else + { + tvv.text = "${tvv.text.toString()} \n \t - 正常图片" + } +// //异步识别,接口回调识别结果 +// nsfwHelper?.scanBitmap(b) { sfw, nsfw -> +// Log.d("demo", "sfw:$sfw,nsfw:$nsfw") +// } + } + } + +} diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 00000000..1f6bb290 --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 00000000..0d025f9b --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 00000000..87dbdb1b --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,27 @@ + + + +