float[] white = new float[3]; float[] black = new float[3]; Color.RGBToHSV(100, 100, 111, white); Color.RGBToHSV(0, 0, 0, black); HSV hsv1=new HSV(white); HSV hsv2=new HSV(black);//阈值设置40以下相似 Log.e("RunTest","init="+HSV.distanceOf(hsv1,hsv2)+"=");
package com.dzx.aidldemo.util; /** * * ================================================ * name: HSV * guide: * author: kimonik * version: 1.0 * date: 2019/7/30 * description: * introduce: * history: * =================================================== */ public class HSV { public float H; public float S; public float V; public HSV() { } public HSV(float[] target) { if (target.length!=3){ return; } H = target[0]; S = target[1]; V = target[2]; } //self-defined private static final double R = 100; private static final double angle = 30; private static final double h = R * Math.cos(angle / 180 * Math.PI); private static final double r = R * Math.sin(angle / 180 * Math.PI); public static double distanceOf(HSV hsv1, HSV hsv2) { double x1 = r * hsv1.V * hsv1.S * Math.cos(hsv1.H / 180 * Math.PI); double y1 = r * hsv1.V * hsv1.S * Math.sin(hsv1.H / 180 * Math.PI); double z1 = h * (1 - hsv1.V); double x2 = r * hsv2.V * hsv2.S * Math.cos(hsv2.H / 180 * Math.PI); double y2 = r * hsv2.V * hsv2.S * Math.sin(hsv2.H / 180 * Math.PI); double z2 = h * (1 - hsv2.V); double dx = x1 - x2; double dy = y1 - y2; double dz = z1 - z2; return Math.sqrt(dx * dx + dy * dy + dz * dz); } }