@@ -4,15 +4,16 @@ import android.annotation.SuppressLint
44import android.graphics.BitmapFactory
55import android.os.Bundle
66import android.support.v7.app.AppCompatActivity
7- import android.util.Log
7+ import android.support.v7.widget.LinearLayoutManager
88import com.zwy.nsfw.api.NsfwHelper
99import kotlinx.android.synthetic.main.activity_main.*
1010
1111
1212class MainActivity : AppCompatActivity () {
1313 var nsfwHelper: NsfwHelper ? = null
14-
15-
14+ var mainAdapter: MainAdapter ? = null
15+ var index = 0
16+ val listData: ArrayList <MyNsfwBean > = ArrayList <MyNsfwBean >()
1617 @SuppressLint(" SetTextI18n" )
1718 override fun onCreate (savedInstanceState : Bundle ? ) {
1819 super .onCreate(savedInstanceState)
@@ -21,51 +22,24 @@ class MainActivity : AppCompatActivity() {
2122// val b = BitmapFactory.decodeStream(resources.assets.open("img/06 (1).jpg"))
2223// iv.setImageBitmap(b)
2324 nsfwHelper = NsfwHelper .getInstance(this , true , 1 )
24-
25- bt_.setOnClickListener {
26- // 同步识别
25+ mainAdapter = MainAdapter (null )
26+ rv.layoutManager = LinearLayoutManager (this )
27+ rv.adapter = mainAdapter
28+ tv_start.setOnClickListener {
2729 for (a in resources.assets.list(" img" )) {
28- val b = BitmapFactory .decodeStream(resources.assets.open(" img/${a} " ))
29- val nsfwBean = nsfwHelper?.scanBitmapSyn(b)
30- Log .d(" demo" , nsfwBean.toString() + " - ${a} " )
31- tvv.text = " 识别成功:\n\t SFW score : ${nsfwBean?.sfw} \n\t NSFW score : ${nsfwBean?.nsfw} ,- ${a} "
32- if (nsfwBean?.nsfw ? : 0f > 0.7 ) {
33- tvv.text = " ${tvv.text} \n \t - 色情图片"
34- } else {
35- tvv.text = " ${tvv.text} \n \t - 正常图片"
30+ val path = " img/${a} "
31+ val b = BitmapFactory .decodeStream(resources.assets.open(path))
32+ listData.add(MyNsfwBean (0f , 0f , path, b))
33+ nsfwHelper?.scanBitmap(b) { sfw, nsfw ->
34+ listData[index].sfw = sfw
35+ listData[index].nsfw = nsfw
36+ mainAdapter?.addData(listData[index])
37+ mainAdapter?.notifyItemInserted(index)
38+ index++
3639 }
3740 }
38- // val nsfwBean = nsfwHelper?.scanBitmapSyn(b)
39- // Log.d("demo", nsfwBean.toString())
40- // tvv.text = "识别成功:\n\tSFW score : ${nsfwBean?.sfw}\n\tNSFW score : ${nsfwBean?.nsfw}"
41- // if (nsfwBean?.nsfw ?: 0f > 0.7) {
42- // tvv.text = "${tvv.text} \n \t - 色情图片"
43- // } else {
44- // tvv.text = "${tvv.text} \n \t - 正常图片"
45- // }
46- // //异步识别,接口回调识别结果
47- // nsfwHelper?.scanBitmap(b) { sfw, nsfw ->
48- // Log.d("demo", "sfw:$sfw,nsfw:$nsfw")
49- // }
50- }
51- }
5241
53- // override fun onResume() {
54- // super.onResume()
55- // if (!OpenCVLoader.initDebug()) {
56- // OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_0_0, this, mLoaderCallback);
57- // } else {
58- // mLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS);
59- // }
60- // }
42+ }
6143
62- // internal var mLoaderCallback: LoaderCallbackInterface = object : LoaderCallbackInterface {
63- // override fun onManagerConnected(status: Int) {
64- //
65- // }
66- //
67- // override fun onPackageInstall(operation: Int, callback: InstallCallbackInterface) {
68- //
69- // }
70- // }
44+ }
7145}
0 commit comments