parent
2f5053f380
commit
2d2fd8bd9b
@ -1 +0,0 @@ |
||||
[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":1,"versionName":"1.0","enabled":true,"outputFile":"app-debug.apk","fullName":"debug","baseName":"debug"},"path":"app-debug.apk","properties":{}}] |
@ -1,45 +1,120 @@ |
||||
package com.example.open_nsfw_android |
||||
|
||||
import android.annotation.SuppressLint |
||||
import android.content.Intent |
||||
import android.graphics.BitmapFactory |
||||
import android.os.Bundle |
||||
import android.support.v7.app.AppCompatActivity |
||||
import android.support.v7.widget.LinearLayoutManager |
||||
import android.view.View |
||||
import com.luck.picture.lib.PictureSelector |
||||
import com.luck.picture.lib.config.PictureConfig |
||||
import com.luck.picture.lib.config.PictureMimeType |
||||
import com.luck.picture.lib.entity.LocalMedia |
||||
import com.zwy.nsfw.api.NsfwHelper |
||||
import kotlinx.android.synthetic.main.activity_main.* |
||||
|
||||
|
||||
class MainActivity : AppCompatActivity() { |
||||
class MainActivity : AppCompatActivity(), View.OnClickListener { |
||||
|
||||
var nsfwHelper: NsfwHelper? = null |
||||
var mainAdapter: MainAdapter? = null |
||||
var index = 0 |
||||
val listData: ArrayList<MyNsfwBean> = ArrayList<MyNsfwBean>() |
||||
@SuppressLint("SetTextI18n") |
||||
var listData: ArrayList<MyNsfwBean> = ArrayList<MyNsfwBean>() |
||||
var selectList: List<LocalMedia>? = null |
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) { |
||||
super.onCreate(savedInstanceState) |
||||
setContentView(R.layout.activity_main) |
||||
//assets 目录下的timg-10.jpeg为正常静态图片 ccc.gif 为动态正常图片 可用作测试 |
||||
// val b = BitmapFactory.decodeStream(resources.assets.open("img/06 (1).jpg")) |
||||
// iv.setImageBitmap(b) |
||||
nsfwHelper = NsfwHelper.getInstance(this, true, 1) |
||||
initNsfwHelper() |
||||
initAdapter() |
||||
initClickListener() |
||||
} |
||||
|
||||
override fun onClick(v: View) { |
||||
when (v.id) { |
||||
R.id.bt_sc_assets -> { |
||||
reScAssetsImgs() |
||||
} |
||||
R.id.bt_sc_from_other -> { |
||||
PictureSelector.create(this) |
||||
.openGallery(PictureMimeType.ofImage())//全部.ofAll()、图片.、视频.ofVideo()、音频.ofAudio() |
||||
.maxSelectNum(20)// 最大图片选择数量 int |
||||
.minSelectNum(1)// 最小选择数量 int |
||||
.imageSpanCount(3)// 每行显示个数 int |
||||
.selectionMode(PictureConfig.MULTIPLE)// 多选 or 单选 or PictureConfig.SINGLE |
||||
.previewImage(true)// 是否可预览图片 true or false |
||||
.isCamera(false)// 是否显示拍照按钮 true or false |
||||
.isZoomAnim(true)// 图片列表点击 缩放效果 默认true |
||||
.selectionMedia(selectList) |
||||
.sizeMultiplier(0.5f)// glide 加载图片大小 0~1之间 如设置 .glideOverride()无效 |
||||
.previewEggs(true)// 预览图片时 是否增强左右滑动图片体验(图片滑动一半即可看到上一张是否选中) true or false |
||||
.forResult(0x01);//结果回调onActivityResult code |
||||
} |
||||
} |
||||
} |
||||
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { |
||||
super.onActivityResult(requestCode, resultCode, data) |
||||
if (requestCode == 0x01 && resultCode == RESULT_OK) { |
||||
selectList = PictureSelector.obtainMultipleResult(data) |
||||
if (selectList != null && selectList?.size ?: 0 > 0) |
||||
reScFromImgs(selectList!!) |
||||
} |
||||
} |
||||
|
||||
|
||||
private fun initClickListener() { |
||||
bt_sc_assets.setOnClickListener(this) |
||||
bt_sc_from_other.setOnClickListener(this) |
||||
} |
||||
|
||||
private fun initAdapter() { |
||||
mainAdapter = MainAdapter(null) |
||||
rv.layoutManager = LinearLayoutManager(this) |
||||
rv.adapter = mainAdapter |
||||
tv_start.setOnClickListener { |
||||
for (a in resources.assets.list("img")) { |
||||
val path = "img/${a}" |
||||
val b = BitmapFactory.decodeStream(resources.assets.open(path)) |
||||
listData.add(MyNsfwBean(0f, 0f, path, b)) |
||||
nsfwHelper?.scanBitmap(b) { sfw, nsfw -> |
||||
} |
||||
|
||||
private fun initNsfwHelper() { |
||||
nsfwHelper = NsfwHelper.getInstance(this, false, 1) |
||||
} |
||||
|
||||
private fun reScFromImgs(list: List<LocalMedia>) { |
||||
index = 0 |
||||
mainAdapter?.setNewData(null) |
||||
listData = ArrayList<MyNsfwBean>() |
||||
Thread(Runnable { |
||||
for (lm in list) { |
||||
val bitmap = BitmapFactory.decodeFile(lm.path) |
||||
listData.add(MyNsfwBean(0.0f, 0.0f, lm.path, bitmap)) |
||||
nsfwHelper?.scanBitmap(bitmap) { sfw, nsfw -> |
||||
listData[index].sfw = sfw |
||||
listData[index].nsfw = nsfw |
||||
mainAdapter?.addData(listData[index]) |
||||
mainAdapter?.notifyItemInserted(index) |
||||
rv.scrollToPosition(index) |
||||
index++ |
||||
} |
||||
} |
||||
}).start() |
||||
} |
||||
|
||||
private fun reScAssetsImgs() { |
||||
index = 0 |
||||
mainAdapter?.setNewData(null) |
||||
listData = ArrayList<MyNsfwBean>() |
||||
for (a in resources.assets.list("img")) { |
||||
val path = "img/${a}" |
||||
val b = BitmapFactory.decodeStream(resources.assets.open(path)) |
||||
listData.add(MyNsfwBean(0f, 0f, path, b)) |
||||
nsfwHelper?.scanBitmap(b) { sfw, nsfw -> |
||||
listData[index].sfw = sfw |
||||
listData[index].nsfw = nsfw |
||||
mainAdapter?.addData(listData[index]) |
||||
mainAdapter?.notifyItemInserted(index) |
||||
rv.scrollToPosition(index) |
||||
index++ |
||||
} |
||||
} |
||||
|
||||
} |
||||
} |
||||
|
@ -1,3 +1,4 @@ |
||||
<resources> |
||||
<string name="app_name">离线鉴黄</string> |
||||
<string name="str_bt1">识别Assets下图片</string> |
||||
</resources> |
||||
|
@ -1,4 +1,2 @@ |
||||
<manifest package="com.zwy.nsfw" xmlns:android="http://schemas.android.com/apk/res/android"> |
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> |
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> |
||||
</manifest> |
||||
|
@ -1,53 +0,0 @@ |
||||
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. |
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); |
||||
you may not use this file except in compliance with the License. |
||||
You may obtain a copy of the License at |
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software |
||||
distributed under the License is distributed on an "AS IS" BASIS, |
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
See the License for the specific language governing permissions and |
||||
limitations under the License. |
||||
==============================================================================*/ |
||||
|
||||
package com.zwy.nsfw; |
||||
|
||||
import android.app.Activity; |
||||
|
||||
import java.io.IOException; |
||||
|
||||
/** |
||||
* This TensorFlowLite classifier works with the float MobileNet model. |
||||
*/ |
||||
public class ClassifierFloatMobileNet extends Classifier { |
||||
|
||||
|
||||
public ClassifierFloatMobileNet(Activity activity, Boolean isAddGpuDelegate, int numThreads) |
||||
throws IOException { |
||||
super(activity, isAddGpuDelegate, numThreads); |
||||
} |
||||
|
||||
@Override |
||||
public int getImageSizeX() { |
||||
return 224; |
||||
} |
||||
|
||||
@Override |
||||
public int getImageSizeY() { |
||||
return 224; |
||||
} |
||||
|
||||
@Override |
||||
protected String getModelPath() { |
||||
return "nsfw.tflite"; |
||||
} |
||||
|
||||
@Override |
||||
protected int getNumBytesPerChannel() { |
||||
return 4; |
||||
} |
||||
|
||||
} |
@ -1 +0,0 @@ |
||||
{} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,2 +0,0 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<merger version="3"><dataSet config="main" ignore_pattern="!.svn:!.git:!.ds_store:!*.scc:.*:<dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~"><source path="/Users/jason/AndroidStudioProjects/open_nsfw_android/openCVLibrary340/src/main/jniLibs"/></dataSet><dataSet config="debug" ignore_pattern="!.svn:!.git:!.ds_store:!*.scc:.*:<dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~"><source path="/Users/jason/AndroidStudioProjects/open_nsfw_android/openCVLibrary340/src/debug/jniLibs"/></dataSet></merger> |
@ -1,2 +0,0 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<merger version="3"><dataSet config="main" ignore_pattern="!.svn:!.git:!.ds_store:!*.scc:.*:<dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~"><source path="/Users/jason/AndroidStudioProjects/open_nsfw_android/openCVLibrary340/src/main/shaders"/></dataSet><dataSet config="debug" ignore_pattern="!.svn:!.git:!.ds_store:!*.scc:.*:<dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~"><source path="/Users/jason/AndroidStudioProjects/open_nsfw_android/openCVLibrary340/src/debug/shaders"/></dataSet></merger> |
@ -1,2 +0,0 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<merger version="3"><dataSet config="main" ignore_pattern="!.svn:!.git:!.ds_store:!*.scc:.*:<dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~"><source path="/Users/jason/AndroidStudioProjects/open_nsfw_android/openCVLibrary340/src/main/assets"/><source path="/Users/jason/AndroidStudioProjects/open_nsfw_android/openCVLibrary340/build/intermediates/shader_assets/debug/compileDebugShaders/out"/></dataSet><dataSet config="debug" ignore_pattern="!.svn:!.git:!.ds_store:!*.scc:.*:<dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~"><source path="/Users/jason/AndroidStudioProjects/open_nsfw_android/openCVLibrary340/src/debug/assets"/></dataSet></merger> |
@ -1 +0,0 @@ |
||||
#Mon May 20 15:37:48 CST 2019 |
@ -1,11 +0,0 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<resources> |
||||
<declare-styleable name="CameraBridgeViewBase"> |
||||
<attr format="boolean" name="show_fps"/> |
||||
<attr format="integer" name="camera_id"> |
||||
<enum name="any" value="-1"/> |
||||
<enum name="back" value="99"/> |
||||
<enum name="front" value="98"/> |
||||
</attr> |
||||
</declare-styleable> |
||||
</resources> |
@ -1,16 +0,0 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<merger version="3"><dataSet aapt-namespace="http://schemas.android.com/apk/res-auto" config="main$Generated" generated="true" ignore_pattern="!.svn:!.git:!.ds_store:!*.scc:.*:<dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~"><source path="/Users/jason/AndroidStudioProjects/open_nsfw_android/openCVLibrary340/src/main/res"/><source path="/Users/jason/AndroidStudioProjects/open_nsfw_android/openCVLibrary340/build/generated/res/rs/debug"/><source path="/Users/jason/AndroidStudioProjects/open_nsfw_android/openCVLibrary340/build/generated/res/resValues/debug"/></dataSet><dataSet aapt-namespace="http://schemas.android.com/apk/res-auto" config="main" generated-set="main$Generated" ignore_pattern="!.svn:!.git:!.ds_store:!*.scc:.*:<dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~"><source path="/Users/jason/AndroidStudioProjects/open_nsfw_android/openCVLibrary340/src/main/res"><file path="/Users/jason/AndroidStudioProjects/open_nsfw_android/openCVLibrary340/src/main/res/values/attrs.xml" qualifiers=""><declare-styleable name="CameraBridgeViewBase"> |
||||
<attr format="boolean" name="show_fps"/> |
||||
<attr format="integer" name="camera_id"> |
||||
<enum name="any" value="-1"/> |
||||
<enum name="back" value="99"/> |
||||
<enum name="front" value="98"/> |
||||
</attr> |
||||
</declare-styleable></file></source><source path="/Users/jason/AndroidStudioProjects/open_nsfw_android/openCVLibrary340/build/generated/res/rs/debug"/><source path="/Users/jason/AndroidStudioProjects/open_nsfw_android/openCVLibrary340/build/generated/res/resValues/debug"/></dataSet><dataSet aapt-namespace="http://schemas.android.com/apk/res-auto" config="debug$Generated" generated="true" ignore_pattern="!.svn:!.git:!.ds_store:!*.scc:.*:<dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~"><source path="/Users/jason/AndroidStudioProjects/open_nsfw_android/openCVLibrary340/src/debug/res"/></dataSet><dataSet aapt-namespace="http://schemas.android.com/apk/res-auto" config="debug" generated-set="debug$Generated" ignore_pattern="!.svn:!.git:!.ds_store:!*.scc:.*:<dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~"><source path="/Users/jason/AndroidStudioProjects/open_nsfw_android/openCVLibrary340/src/debug/res"/></dataSet><mergedItems><configuration qualifiers=""><declare-styleable name="CameraBridgeViewBase"> |
||||
<attr format="boolean" name="show_fps"/> |
||||
<attr format="integer" name="camera_id"> |
||||
<enum name="any" value="-1"/> |
||||
<enum name="back" value="99"/> |
||||
<enum name="front" value="98"/> |
||||
</attr> |
||||
</declare-styleable></configuration></mergedItems></merger> |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue