1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| val bitmapQQ = BitmapFactory.decodeResource(resources, R.mipmap.eeee) val matQQ = Mat() Utils.bitmapToMat(bitmapQQ, matQQ)
val bitmapFriend = BitmapFactory.decodeResource(resources, R.mipmap.ffff) val matFriend = Mat() Utils.bitmapToMat(bitmapFriend, matFriend)
val mat1 = Mat() Imgproc.cvtColor(matQQ, mat1, Imgproc.COLOR_BGR2HSV) val mat2 = Mat() Imgproc.cvtColor(matFriend, mat2, Imgproc.COLOR_BGR2HSV)
val hist1 = Mat() val hist2 = Mat()
Imgproc.calcHist(Stream.of(mat1).collect(Collectors.toList()), MatOfInt(0), Mat(), hist1, MatOfInt(255), MatOfFloat(0F, 256F)) Imgproc.calcHist(Stream.of(mat2).collect(Collectors.toList()), MatOfInt(0), Mat(), hist2, MatOfInt(255), MatOfFloat(0F, 256F))
Core.normalize(hist1, hist1, 1.0, hist1.rows().toDouble(), Core.NORM_MINMAX, -1, Mat()) Core.normalize(hist2, hist2, 1.0, hist2.rows().toDouble(), Core.NORM_MINMAX, -1, Mat())
val a = Imgproc.compareHist(hist1, hist1, Imgproc.CV_COMP_CORREL) val b = Imgproc.compareHist(hist1, hist2, Imgproc.CV_COMP_CORREL)
Log.e("xiaoxige", "相同图片对比: $a") Log.e("xiaoxige", "不相同图片对比: $b")
|