public bool check(int index) { if (encode[index] == null) { return(true); } if (DTW.encFit(encode[index], vencode) != -1) { return(true); } return(false); }
public void zNorm() { int iprev = 0; for (int i = 1; i < vencode.Count; i++) { if (vencode[i].X == 0x7fff) { DTW.zNorm(vencode, iprev, i); iprev = i; } } DTW.zNorm(vencode, iprev, vencode.Count); }
public static int encFit(List <sPoint> encodeA, List <sPoint> encodeB) { if (encodeA == null || encodeB == null || encodeA.Count == 0 || encodeB.Count == 0) { return(-1); } List <int> pA = new List <int>(), pB = new List <int>(); for (int i = 0; i < encodeA.Count; i++) { if (encodeA[i].X == 0x7fff) { pA.Add(i); } } for (int i = 0; i < encodeB.Count; i++) { if (encodeB[i].X == 0x7fff) { pB.Add(i); } } if (pA.Count != pB.Count) { //MessageBox.Show("Number of parts not match. " + pA.Count.ToString() + " , " + pB.Count.ToString()); return(-1); //------------------------------------------- return } pA.Add(encodeA.Count); pB.Add(encodeB.Count); int err, errt = 0; short xAmax, xAmin, yAmax, yAmin, xBmax, xBmin, yBmax, yBmin, dAx, dAy, dBx, dBy; err = 0; for (int i = 1; i < pA.Count; i++) { xAmax = encodeA[pA[i - 1] + 1].X; xAmin = xAmax; yAmax = encodeA[pA[i - 1] + 1].Y; yAmin = yAmax; xBmax = encodeB[pB[i - 1] + 1].X; xBmin = xBmax; yBmax = encodeB[pB[i - 1] + 1].Y; yBmin = yBmax; dAx = 0; dAy = 0; dBx = 0; dBy = 0; for (int j = pA[i - 1] + 1; j < pA[i]; j++) { if (encodeA[j].X > xAmax) { xAmax = encodeA[j].X; } if (encodeA[j].X < xAmin) { xAmin = encodeA[j].X; } if (encodeA[j].Y > yAmax) { yAmax = encodeA[j].Y; } if (encodeA[j].Y < yAmin) { yAmin = encodeA[j].Y; } dAx = (short)(xAmax - xAmin); dAy = (short)(yAmax - yAmin); } for (int j = pB[i - 1] + 1; j < pB[i]; j++) { if (encodeB[j].X > xBmax) { xBmax = encodeB[j].X; } if (encodeB[j].X < xBmin) { xBmin = encodeB[j].X; } if (encodeB[j].Y > yBmax) { yBmax = encodeB[j].Y; } if (encodeB[j].Y < yBmin) { yBmin = encodeB[j].Y; } dBx = (short)(xBmax - xBmin); dBy = (short)(yBmax - yBmin); } errt = DTW.dtw(encodeA, pA[i - 1] + 1, pA[i], encodeB, pB[i - 1] + 1, pB[i], (int)(Acc * dAx), (int)(Acc * dAy)); if (errt == -1) { break; } err += errt; } //MessageBox.Show(errt != -1 ? "ยืนยันตัวตนสำเร็จ : " + err.ToString() : "! ไม่ถูกต้อง : " + err.ToString()); return(errt != -1 ? err : -1); }
public bool update() { encode[10] = vencode; byte[] match = new byte[NUMOFENCODE + 1]; int[] err = new int[NUMOFENCODE + 1]; int errt, errminmax, min, max, imin = 0, imax = NUMOFENCODE, minmax; err[0] = 0; for (int i = 1; i < NUMOFENCODE + 1; i++) { err[i] = 0; for (int j = 0; j < i; j++) { errt = DTW.encFit(encode[j], encode[i]); if (errt == -1) { errt = DTW.encFit(encode[i], encode[j]); } if (errt == -1) { match[i]++; match[j]++; } else { err[i] += errt; err[j] += errt; } } } minmax = 12; errminmax = 1000000000; for (int i = 0; i < err.Length; i++) { if (match[i] < minmax) { minmax = match[i]; } } for (int i = 0; i < err.Length; i++) { if (match[i] == minmax && err[i] < errminmax) { errminmax = err[i]; imin = i; } } minmax = 0; errminmax = 0; for (int i = 0; i < err.Length; i++) { if (match[i] > minmax) { minmax = match[i]; } } for (int i = 0; i < err.Length; i++) { if (match[i] == minmax && err[i] > errminmax) { errminmax = err[i]; imax = i; } } List <sPoint> tencode; tencode = encode[0]; encode[0] = encode[imin]; encode[imin] = tencode; tencode = encode[NUMOFENCODE]; //for create only update change to 10 encode[NUMOFENCODE] = encode[imax == 0 ? imin : imax]; //for create only update change to 10 encode[imax == 0 ? imin : imax] = tencode; return(true); }