From: yeom Date: Sun, 1 Aug 2010 03:48:36 +0000 (+0000) Subject: add tracking benchmark X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=509363ab4ecdd344f28f5972f308362403afcca2;p=IRC.git add tracking benchmark --- diff --git a/Robust/src/Benchmarks/oooJava/tracking/1.bmp b/Robust/src/Benchmarks/oooJava/tracking/1.bmp new file mode 100644 index 00000000..06a8c3d9 Binary files /dev/null and b/Robust/src/Benchmarks/oooJava/tracking/1.bmp differ diff --git a/Robust/src/Benchmarks/oooJava/tracking/BlurPiece.java b/Robust/src/Benchmarks/oooJava/tracking/BlurPiece.java new file mode 100644 index 00000000..20bd359b --- /dev/null +++ b/Robust/src/Benchmarks/oooJava/tracking/BlurPiece.java @@ -0,0 +1,138 @@ +public class BlurPiece { + + /* current processing image related */ + int[] m_image; + int m_rows; + int m_cols; + + /* results related */ + float[] m_result; + int m_rows_rs; + int m_rows_re; + int m_cols_r; + + /* id indicating the piece # */ + int m_id; + int m_range; + + /* constructor */ + public BlurPiece(int id, + int range, + int[] data) { + this.m_id = id; + this.m_range = range; + this.m_image = data; + this.m_rows = data[0]; + this.m_cols = data[1]; + } + + public int getId() { + return this.m_id; + } + + public int getRows() { + return this.m_rows; + } + + public int getCols() { + return this.m_cols; + } + + public float[] getResult() { + return this.m_result; + } + + public int getRowsRS() { + return this.m_rows_rs; + } + + public int getRowsRE() { + return this.m_rows_re; + } + + public int getColsR() { + return this.m_cols_r; + } + + public void blur() { + int rows, cols; + float temp; + int[] kernel, imageIn; + int rows_k, cols_k; + int k, i, j; + int kernelSize, startCol, endCol, halfKernel, startRow, endRow, kernelSum; + int[] inputs; + float[] image; + + inputs = this.m_image; + rows = this.m_rows; + cols = this.m_cols; + this.m_rows_rs = this.m_id * this.m_range; + this.m_rows_re = (this.m_id + 1) * this.m_range; + if(rows < this.m_rows_re) { + this.m_rows_re = rows; + } + this.m_cols_r = this.m_cols; + image = this.m_result = new float[(this.m_rows_re-this.m_rows_rs)*cols]; + + kernel = new int[5]; + rows_k = 1; + cols_k = 5; + + kernel[0] = 1; + kernel[1] = 4; + kernel[2] = 6; + kernel[3] = 4; + kernel[4] = 1; + + kernelSize = 5; + kernelSum = 16; + + startCol = 2; //((kernelSize)/2); + endCol = cols - 2; //round(cols - (kernelSize/2)); + halfKernel = 2; //(kernelSize-1)/2; + + if((this.m_rows_re <= 2) || (this.m_rows_rs >= rows - 2)) { + return; + } + startRow = (2>this.m_rows_rs)?2:(this.m_rows_rs); //(kernelSize)/2; + endRow = ((rows-2)= rows - 2)) { + return; + } + startRow = (2>this.m_rows_rs)?2:(this.m_rows_rs); //(kernelSize)/2; + endRow = ((rows-2) rows - 1)) { + return; + } + startRow = (1 > this.m_rows_rs) ? 1 : (this.m_rows_rs); // (kernelSize)/2; + endRow = ((rows - 1) < this.m_rows_re) ? (rows - 1) : (this.m_rows_re); // (rows + // - + // (kernelSize)/2); + + int ii = startRow - this.m_rows_rs; + for (i = startRow; i < endRow; i++) { + for (j = startCol; j < endCol; j++) { + temp = 0; + for (k = -halfKernel; k <= halfKernel; k++) { + temp += (float) (image[i * cols + (j + k)] * (float) (kernel_2[k + halfKernel])); + } + result[ii * cols + j] = (float) (temp / kernelSum_2); + } + ii++; + } + } + + public void printResult() { + // result validation + System.printI(11111111); + for (int i = 0; i < this.m_rows_re - this.m_rows_rs; i++) { + for (int j = 0; j < this.m_cols_r; j++) { + System.printI((int) (this.m_result[i * this.m_cols_r + j] * 10)); + } + } + } +} \ No newline at end of file diff --git a/Robust/src/Benchmarks/oooJava/tracking/IXLM.java b/Robust/src/Benchmarks/oooJava/tracking/IXLM.java new file mode 100644 index 00000000..babd499a --- /dev/null +++ b/Robust/src/Benchmarks/oooJava/tracking/IXLM.java @@ -0,0 +1,143 @@ +public class IXLM { + + /* current processing image related */ + float[] m_image; + int m_rows; + int m_cols; + + /* current processing image related */ + float[] m_result; + int m_rows_r; + int m_cols_r; + + int m_counter; + + /* constructor */ + public IXLM(int counter, + float[] data, + int rows, + int cols) { + this.m_counter = counter; + this.m_rows = this.m_rows_r = rows; + this.m_cols = this.m_cols_r = cols; + this.m_image = data; + this.m_result = new float[rows * cols]; + } + + public int getRows() { + return this.m_rows; + } + + public int getCols() { + return this.m_cols; + } + + public float[] getImage() { + return this.m_image; + } + + public int getRowsR() { + return this.m_rows_r; + } + + public int getColsR() { + return this.m_cols_r; + } + + public float[] getResult() { + return this.m_result; + } + + public boolean addCalcSobelResult(IXL ixl) { + int startRow = ixl.getRowsRS(); + int endRow = ixl.getRowsRE(); + int i, j, k, cols; + float[] image, r; + + image = this.m_result; + this.m_counter--; + cols = this.m_cols_r; + + // clone data piece + r = ixl.getResult(); + k = 0; + for(i = startRow; i < endRow; i++) { + for(j = 0; j < cols; j++) { + image[i * cols + j] = r[k * cols + j]; + } + k++; + } + + return (0 == this.m_counter); + } + + public void calcSobel_dX() { + int rows_k1, cols_k1, rows_k2, cols_k2; + int[] kernel_1, kernel_2; + float temp; + int kernelSize, startCol, endCol, halfKernel, startRow, endRow; + int k, i, j, kernelSum_1, kernelSum_2; + float[] result, image; + int rows = this.m_rows_r; + int cols = this.m_cols_r; + + image = this.m_result; + + rows_k1 = 1; + cols_k1 = 3; + kernel_1 = new int[rows_k1 * cols_k1]; + rows_k2 = 1; + cols_k2 = 3; + kernel_2 = new int[rows_k2 * cols_k2]; + + kernel_1[0] = 1; + kernel_1[1] = 2; + kernel_1[2] = 1; + + kernelSize = 3; + kernelSum_1 = 4; + + kernel_2[0] = 1; + kernel_2[1] = 0; + kernel_2[2] = -1; + + kernelSum_2 = 2; + + startCol = 1; //((kernelSize)/2); + endCol = cols - 1; //(int)(cols - (kernelSize/2)); + halfKernel = 1; //(kernelSize-1)/2; + + startRow = 1; //(kernelSize)/2; + endRow = (rows-1); //(rows - (kernelSize)/2); + + for(i=startRow; i rows - 1)) { + return; + } + startRow = (1>this.m_rows_rs)?1:(this.m_rows_rs); //(kernelSize)/2; + endRow = ((rows-1) rows - 1)) { + return; + } + startRow = (1>this.m_rows_rs)?1:(this.m_rows_rs); //(kernelSize)/2; + endRow = ((rows-1) rows - 1)) { + return; + } + startRow = (1>this.m_rows_rs)?1:(this.m_rows_rs); //(kernelSize)/2; + endRow = ((rows-1) 0) { + nNumColors = nclrused; + } else { + nNumColors = (1 & 0xff) << nbitcount; + } + System.out.println("The number of Colors is" + nNumColors); + // Some bitmaps do not have the sizeimage field calculated + // Ferret out these cases and fix 'em. + if (nsizeimage == 0) { + nsizeimage = ((((nwidth * nbitcount) + 31) & 31) >> 3); + nsizeimage *= nheight; + System.out.println("nsizeimage (backup) is" + nsizeimage); + } + // Read the palatte colors. + int npalette[] = new int[nNumColors]; + byte bpalette[] = new byte[nNumColors * 4]; + // fs.read (bpalette, 0, nNumColors*4); + fs.read(bpalette); + int nindex8 = 0; + for (int n = 0; n < nNumColors; n++) { + npalette[n] = + (255 & 0xff) << 24 | (((int) bpalette[nindex8 + 2] & 0xff) << 16) + | (((int) bpalette[nindex8 + 1] & 0xff) << 8) | (int) bpalette[nindex8] & 0xff; + // System.out.println ("Palette Color "+n + // +" is:"+npalette[n]+" (res,R,G,B)= (" +((int)(bpalette[nindex8+3]) & + // 0xff)+"," +((int)(bpalette[nindex8+2]) & 0xff)+"," + // +((int)bpalette[nindex8+1]&0xff)+"," + // +((int)bpalette[nindex8]&0xff)+")"); + nindex8 += 4; + } + // Read the image data (actually indices into the palette) + // Scan lines are still padded out to even 4-byte + // boundaries. + int npad8 = (nsizeimage / nheight) - nwidth; + System.out.println("nPad is:" + npad8); +// int ndata8[] = new int[nwidth * nheight]; + ndata = new int[(nwidth * nheight)+4]; + byte bdata[] = new byte[(nwidth + npad8) * nheight]; + // fs.read (bdata, 0, (nwidth+npad8)*nheight); + fs.read(bdata); + nindex8 = 0; + for (int j8 = 0; j8 < nheight; j8++) { + for (int i8 = 0; i8 < nwidth; i8++) { + ndata[nwidth * (nheight - j8 - 1) + i8+4] = npalette[((int) bdata[nindex8] & 0xff)]; + nindex8++; + } + nindex8 += npad8; + } + // image = createImage ( new MemoryImageSource (nwidth, nheight, + // ndata8, 0, nwidth)); + } else { + System.out.println("Not a 24-bit or 8-bit Windows Bitmap, aborting..."); + // image = (Image)null; + } + fs.close(); + + ndata[0] = nheight; + ndata[1] = nwidth; + ndata[2] = nheight * nwidth; + ndata[3] = 2; + + return ndata; + + } + +} \ No newline at end of file diff --git a/Robust/src/Benchmarks/oooJava/tracking/ImageX.java b/Robust/src/Benchmarks/oooJava/tracking/ImageX.java new file mode 100644 index 00000000..07a8c337 --- /dev/null +++ b/Robust/src/Benchmarks/oooJava/tracking/ImageX.java @@ -0,0 +1,129 @@ +public class ImageX { + + /* current processing image related */ + float[] m_image; + int m_rows; + int m_cols; + + /* results related */ + float[] m_result; + int m_rows_rs; + int m_rows_re; + int m_cols_r; + + /* id indicating the piece # */ + int m_id; + int m_range; + + /* constructor */ + public ImageX(int id, + int range, + float[] data, + int rows, + int cols) { + this.m_id = id; + this.m_range = range; + this.m_image = data; + this.m_rows = rows; + this.m_cols = cols; + } + + public int getId() { + return this.m_id; + } + + public float[] getResult() { + return this.m_result; + } + + public int getRowsRS() { + return this.m_rows_rs; + } + + public int getRowsRE() { + return this.m_rows_re; + } + + public int getColsR() { + return this.m_cols_r; + } + + public int getRows() { + return this.m_rows; + } + + public int getCols() { + return this.m_cols; + } + + public void calcSobel_dX() { + int rows_k1, cols_k1, rows_k2, cols_k2; + int[] kernel_1, kernel_2; + float temp; + int kernelSize, startCol, endCol, halfKernel, startRow, endRow; + int k, i, j, kernelSum_1, kernelSum_2; + float[] result, image; + int rows = this.m_rows; + int cols = this.m_cols; + + image = this.m_image; + + this.m_rows_rs = this.m_id * this.m_range; + this.m_rows_re = (this.m_id + 1) * this.m_range; + this.m_cols_r = cols; + result=this.m_result=new float[(this.m_rows_re-this.m_rows_rs)*this.m_cols_r]; + + rows_k1 = 1; + cols_k1 = 3; + kernel_1 = new int[rows_k1 * cols_k1]; + rows_k2 = 1; + cols_k2 = 3; + kernel_2 = new int[rows_k2 * cols_k2]; + + kernel_1[0] = 1; + kernel_1[1] = 2; + kernel_1[2] = 1; + + kernelSize = 3; + kernelSum_1 = 4; + + kernel_2[0] = 1; + kernel_2[1] = 0; + kernel_2[2] = -1; + + kernelSum_2 = 2; + + startCol = 1; //((kernelSize)/2); + endCol = cols - 1; //(int)(cols - (kernelSize/2)); + halfKernel = 1; //(kernelSize-1)/2; + + if((this.m_rows_re < 1) || (this.m_rows_rs > rows - 1)) { + return; + } + startRow = (1>this.m_rows_rs)?1:(this.m_rows_rs); //(kernelSize)/2; + endRow = ((rows-1) rows - 1)) { + return; + } + startRow = (1>this.m_rows_rs)?1:(this.m_rows_rs); //(kernelSize)/2; + endRow = ((rows-1) localindex) { + k = k1; + } + if (!f_ind[k1]) { + break; + } + } + if (k == nfea) { + // System.printI(77777777); + return false; + } else if (k == rindex) { + k = k1; + } + if (f_ind[k] && (m3f[2][k] != image[localindex])) { + // System.printI(88888888); + return false; + } + // move all things after k behind + int p = k1; + for (; p > k; p--) { + m3f[2][p] = m3f[2][p - 1]; + h_ind[p] = h_ind[p - 1]; + m3f[0][p] = m3f[0][p - 1]; + m3f[1][p] = m3f[1][p - 1]; + f_ind[p] = true; + } + // insert + m3f[2][p] = image[localindex]; + h_ind[p] = localindex; + localindex++; + m3f[0][p] = Math.ceilf((float) (localindex / (float) r)); + m3f[1][p] = (float) localindex - (m3f[0][p] - 1) * (float) r * (float) 1.0; + f_ind[p] = true; + } + } + j++; + } + + this.m_num_p--; + + return (0 == this.m_num_p); + } + + public void calcFeatures() { + float[] f1, f2, f3; + int rows_f1, cols_f1, rows_f2, cols_f2, rows_f3, cols_f3; + float[] interestPnts; + int[] rows_ip, cols_ip; + int rows_ipt, cols_ipt; + rows_ip = new int[1]; + cols_ip = new int[1]; + + f1 = this.m_3f[0]; + f2 = this.m_3f[1]; + f3 = this.m_3f[2]; + rows_f1 = this.m_rows_3f; + rows_f2 = this.m_rows_3f; + rows_f3 = this.m_rows_3f; + cols_f1 = this.m_cols_3f; + cols_f2 = this.m_cols_3f; + cols_f3 = this.m_cols_3f; + + interestPnts = + this.getANMs(f1, rows_f1, cols_f1, f2, rows_f2, cols_f2, f3, rows_f3, cols_f3, rows_ip, + cols_ip); + rows_ipt = rows_ip[0]; + cols_ipt = cols_ip[0]; + rows_ip = cols_ip = null; + + // fTranspose(interestPnts) + float[] trans; + int i, j, k, rows_trans, cols_trans; + + rows_trans = cols_ipt; + cols_trans = rows_ipt; + trans = new float[rows_trans * cols_trans]; + + k = 0; + for (i = 0; i < cols_ipt; i++) { + for (j = 0; j < rows_ipt; j++) { + trans[k++] = interestPnts[j * cols_ipt + i]; + } + } + + // fDeepCopyRange(interestPnt, 0, 2, 0, cols_ip[0]) + int rows, cols; + int numberRows = 2; + int startRow = 0; + int numberCols = cols_trans; + int startCol = 0; + + rows = numberRows + startRow; + cols = numberCols + startCol; + + rows_ipt = numberRows; + cols_ipt = numberCols; + interestPnts = new float[rows_ipt * cols_ipt]; + + k = 0; + for (i = startRow; i < rows; i++) { + for (j = startCol; j < cols; j++) { + interestPnts[k++] = trans[i * cols_trans + j]; + } + } + + float[] features; + this.m_rows_f = 2; + this.m_cols_f = cols_ipt; + + features = this.m_features = new float[this.m_rows_f * this.m_cols_f]; + for (i = 0; i < 2; i++) { + for (j = 0; j < cols_ipt; j++) { + features[i * cols_ipt + j] = interestPnts[i * cols_ipt + j]; + } + } + } + + public float[] horzcat(float[] f1, int rows_f1, int cols_f1, float[] f2, int rows_f2, + int cols_f2, float[] f3, int rows_f3, int cols_f3) { + float[] out; + int rows = 0, cols = 0, i, j, k, c_1, c_2, r_3, c_3; + + c_1 = cols_f1; + cols += c_1; + + c_2 = cols_f2; + cols += c_2; + + r_3 = rows_f3; + c_3 = cols_f3; + cols += c_3; + + rows = r_3; + + out = new float[rows * cols]; + + for (i = 0; i < rows; i++) { + k = 0; + for (j = 0; j < c_1; j++) { + out[i * cols + k] = f1[i * c_1 + j]; + k++; + } + for (j = 0; j < c_2; j++) { + out[i * cols + k] = f2[i * c_2 + j]; + k++; + } + for (j = 0; j < c_3; j++) { + out[i * cols + k] = f3[i * c_3 + j]; + k++; + } + } + + return out; + } + + public int[] fSortIndices(float[] input, int rows, int cols) { + float[] in; + int i, j, k; + int[] ind; + + // fDeepCopy + in = new float[input.length]; + for (i = 0; i < input.length; i++) { + in[i] = input[i]; + } + + ind = new int[rows * cols]; + + for (k = 0; k < cols; k++) { + for (i = 0; i < rows; i++) { + float localMax = in[i * cols + k]; + int localIndex = i; + ind[i * cols + k] = i; + for (j = 0; j < rows; j++) { + if (localMax < in[j * cols + k]) { + ind[i * cols + k] = j; + localMax = in[j * cols + k]; + localIndex = j; + } + } + in[localIndex * cols + k] = 0; + } + } + + return ind; + } + + public float[] ffVertcat(float[] matrix1, int rows_m1, int cols_m1, float[] matrix2, int rows_m2, + int cols_m2) { + float[] outMatrix; + int rows_o, cols_o, i, j, k; + + rows_o = rows_m1 + rows_m2; + cols_o = cols_m1; + outMatrix = new float[rows_o * cols_o]; + + for (i = 0; i < cols_m1; i++) { + for (j = 0; j < rows_m1; j++) { + outMatrix[j * cols_m1 + i] = matrix1[j * cols_m1 + i]; + } + for (k = 0; k < rows_m2; k++) { + outMatrix[(k + rows_m1) * cols_m1 + i] = matrix2[k * cols_m2 + i]; + } + } + + return outMatrix; + + } + + public float[] getANMs(float[] f1, int rows_f1, int cols_f1, float[] f2, int rows_f2, + int cols_f2, float[] f3, int rows_f3, int cols_f3, int[] rows_ip, int[] cols_ip) { + float MAX_LIMIT = (float) 100000000; + float C_ROBUST = (float) 1.0; + float[] suppressR, points, srtdPnts, tempF, srtdV, interestPnts, temp; + int rows_sr, cols_sr, rows_p, cols_p, rows_sp, cols_sp, rows_tf, cols_tf; + int rows_sv, cols_sv, rows_tmp, cols_tmp; + int[] srtdVIdx, supId; + int rows_svi, cols_svi, rows_si, cols_si; + float t, t1, r_sq; + int n, i, j, k, validCount, cnt, end, iter, rows, cols; + int supIdPtr = 0; + + r_sq = (float) (this.SUPPRESION_RADIUS ^ 2); + points = this.horzcat(f1, rows_f1, cols_f1, f2, rows_f2, cols_f2, f3, rows_f3, cols_f3); + rows_p = rows_f3; + cols_p = cols_f1 + cols_f2 + cols_f3; + n = rows_f3; + + /** sort() arg 2 is for descend = 1, arg3 = indices. Returns sorted values **/ + + srtdVIdx = this.fSortIndices(f3, rows_f3, cols_f3); + rows_svi = rows_f3; + cols_svi = cols_f3; + + rows_sp = rows_svi; + cols_sp = cols_p; + srtdPnts = new float[rows_sp * cols_sp]; + + for (i = 0; i < rows_sp; i++) { + for (j = 0; j < cols_sp; j++) { + srtdPnts[i * cols_sp + j] = points[srtdVIdx[i] * cols_sp + j]; + } + } + + rows_tmp = 1; + cols_tmp = 3; + temp = new float[rows_tmp * cols_tmp]; + rows_sr = n; + cols_sr = 1; + suppressR = new float[rows_sr * cols_sr]; + for (i = 0; i < rows_sr; i++) { + for (j = 0; j < cols_sr; j++) { + suppressR[i * cols_sr + j] = MAX_LIMIT; + } + } + + validCount = 0; + iter = 0; + for (i = 0; i < rows_sr; i++) { + if (suppressR[i] > r_sq) { + validCount++; + } + } + + k = 0; + rows_si = validCount; + cols_si = 1; + supId = new int[rows_si * cols_si]; + for (i = 0; i < (rows_sr * cols_sr); i++) { + if (suppressR[i] > r_sq) { + supId[k++] = i; + } + } + + + while (validCount > 0) { + float[] tempp, temps; + int rows_tpp, cols_tpp, rows_tps, cols_tps; + temp[0] = srtdPnts[supId[0] * cols_sp + 0]; + temp[1] = srtdPnts[supId[0] * cols_sp + 1]; + temp[2] = srtdPnts[supId[0] * cols_sp + 2]; + + if (iter == 0) { + interestPnts = temp; + rows_ip[0] = rows_tmp; + cols_ip[0] = cols_tmp; + } else { + interestPnts = + this.ffVertcat(interestPnts, rows_ip[0], cols_ip[0], temp, rows_tmp, cols_tmp); + rows_ip[0] = rows_ip[0] + rows_tmp; + cols_ip[0] = cols_ip[0]; + } + + iter++; + + // fDeepCopy + rows_tpp = rows_sp; + cols_tpp = cols_sp; + tempp = new float[rows_tpp * cols_tpp]; + for (i = 0; i < rows_tpp * cols_tpp; i++) { + tempp[i] = srtdPnts[i]; + } + // fDeepCopy + rows_tps = rows_sr; + cols_tps = cols_sr; + temps = new float[rows_tps * cols_tps]; + for (i = 0; i < rows_tps * cols_tps; i++) { + temps[i] = suppressR[i]; + } + + rows_sp = validCount - 1; + cols_sp = 3; + srtdPnts = new float[rows_sp * cols_sp]; + rows_sr = validCount - 1; + cols_sr = 1; + suppressR = new float[rows_sr * cols_sr]; + + k = 0; + for (i = 0; i < (validCount - 1); i++) { + srtdPnts[i * cols_sp + 0] = tempp[supId[i + 1] * cols_sp + 0]; + srtdPnts[i * cols_sp + 1] = tempp[supId[i + 1] * cols_sp + 1]; + srtdPnts[i * cols_sp + 2] = tempp[supId[i + 1] * cols_sp + 2]; + suppressR[i * cols_sr + 0] = temps[supId[i + 1] * cols_sr + 0]; + } + + int rows1 = rows_ip[0] - 1; + int cols1 = cols_ip[0]; + for (i = 0; i < rows_sp; i++) { + t = (float) 0; + t1 = (float) 0; + if ((C_ROBUST * interestPnts[rows1 * cols1 + 2]) >= srtdPnts[supId[i] * cols_sp + 2]) { + t = srtdPnts[supId[i] * cols_sp + 0] - interestPnts[rows1 * cols1 + 0]; + t1 = srtdPnts[supId[i] * cols_sp + 1] - interestPnts[rows1 * cols1 + 1]; + t = t * t + t1 * t1; + t1 = (float) 0; + } + + if ((C_ROBUST * interestPnts[rows1 * cols1 + 2]) < srtdPnts[supId[i] * cols_sp + 2]) { + t1 = (float) 1 * (float) MAX_LIMIT; + } + + if (suppressR[supId[i]] > (t + t1)) { + suppressR[supId[i]] = t + t1; + } + } + + validCount = 0; + for (i = 0; i < rows_sr; i++) { + if (suppressR[i] > r_sq) { + validCount++; + } + } + + k = 0; + rows_si = validCount; + cols_si = 1; + supId = new int[rows_si * cols_si]; + + for (i = 0; i < rows_sr * cols_sr; i++) { + if (suppressR[i] > r_sq) { + supId[k++] = i; + } + } + } + + return interestPnts; + } + + public void startTrackingLoop() { + this.m_image = null; + this.m_image_resized = null; + } + + public float[] getInterpolatePatch(float[] src, int rows, int cols, float centerX, float centerY) { + float[] dst; + int rows_d, cols_d; + float a, b, a11, a12, a21, a22; + int i, j, srcIdxX, dstIdxX, srcIdy, dstIdy, dstIndex; + + a = centerX - (float) (Math.floor(centerX)); + b = centerY - (float) (Math.floor(centerY)); + + a11 = (1 - a) * (1 - b); + a12 = a * (1 - b); + a21 = (1 - a) * b; + a22 = a * b; + + rows_d = 1; + cols_d = 2 * this.WINSZ * 2 * this.WINSZ; + dst = new float[rows_d * cols_d]; + + for (i = -this.WINSZ; i <= (this.WINSZ - 1); i++) { + srcIdxX = (int) (Math.floor(centerX)) + i; + dstIdxX = i + this.WINSZ; + + for (j = -this.WINSZ; j <= (this.WINSZ - 1); j++) { + srcIdy = (int) (Math.floor(centerY)) + j; + dstIdy = j + this.WINSZ; + dstIndex = dstIdy * 2 * this.WINSZ + dstIdxX; + // printf("%f\t%f\t%d\t%d\n", centerX, centerY, srcIdxX, srcIdy); + dst[dstIndex] = + src[srcIdy * cols + srcIdxX] * a11 + src[(srcIdy + 1) * cols + srcIdxX] * a12 + + src[srcIdy * cols + (srcIdxX + 1)] * a21 + + src[(srcIdy + 1) * cols + (srcIdxX + 1)] * a22; + } + } + + return dst; + } + + public int[] calcPyrLKTrack(float[][] Ipyrs, int[] rows, int[] cols, float[] newPnt) { + float[] ip1, ip2, idxp1, idxp2, idyp1, idyp2, jp1, jp2, fPnt; + int k = 0; + + ip1 = Ipyrs[k++]; + ip2 = Ipyrs[k++]; + idxp1 = Ipyrs[k++]; + idyp1 = Ipyrs[k++]; + idxp2 = Ipyrs[k++]; + idyp2 = Ipyrs[k++]; + jp1 = this.m_image; + jp2 = this.m_image_resized; + fPnt = this.m_features; + + int idx, level, pLevel, i, winSizeSq; + int[] valid, imgDims; + int rows_v, cols_v, rows_id, cols_id; + float[] rate, iPatch, jPatch, iDxPatch, iDyPatch; + int rows_r, cols_r, rows_ip, cols_ip, rows_jp, cols_jp; + int rows_idxp, cols_idxp, rows_idyp, cols_idyp; + float x, y, dX, dY, c_xx, c_yy, c_xy, tr; + int imgSize_1, /* max_iter, */imgSize_2; + float mX, mY, dIt, eX, eY, c_det; + int nFeatures = this.m_cols_f; + + rows_id = 4; + cols_id = 1; + imgDims = new int[rows_id * cols_id]; + + imgDims[0] = rows[0]; + imgDims[1] = cols[0]; + imgDims[2] = rows[1]; + imgDims[3] = cols[1]; + + pLevel = 2; + rows_r = 1; + cols_r = 6; + rate = new float[rows_r * cols_r]; + + rate[0] = (float) 1; + rate[1] = (float) 0.5; + rate[2] = (float) 0.25; + rate[3] = (float) 0.125; + rate[4] = (float) 0.0625; + rate[5] = (float) 0.03125; + + winSizeSq = 4 * this.WINSZ * this.WINSZ; + rows_ip = 1; + cols_ip = winSizeSq; + iPatch = new float[rows_ip * cols_ip]; + rows_jp = 1; + cols_jp = winSizeSq; + jPatch = new float[rows_jp * cols_jp]; + rows_idxp = 1; + cols_idxp = winSizeSq; + iDxPatch = new float[rows_idxp * cols_idxp]; + rows_idyp = 1; + cols_idyp = winSizeSq; + iDyPatch = new float[rows_idyp * cols_idyp]; + + rows_v = 1; + cols_v = nFeatures; + valid = new int[rows_v * cols_v]; + for(int valid_idx=0;valid_idx= 0; level--) { + x = x + x; + y = y + y; + dX = dX + dX; + dY = dY + dY; + imgSize_1 = imgDims[level * 2]; + imgSize_2 = imgDims[level * 2 + 1]; + + c_xx = (float) 0; + c_xy = (float) 0; + c_yy = (float) 0; + + if ((x - (float) this.WINSZ) < (float) 0 || (y - (float) this.WINSZ) < (float) 0 + || (y + (float) this.WINSZ) >= (float) imgSize_1 + || (x + (float) this.WINSZ) >= (float) imgSize_2) { + valid[i] = 0; + break; + } + + if (level == 0) { + iPatch = getInterpolatePatch(ip1, rows[0], cols[0], x, y); + iDxPatch = getInterpolatePatch(idxp1, rows[2], cols[2], x, y); + iDyPatch = getInterpolatePatch(idyp1, rows[3], cols[3], x, y); + } + if (level == 1) { + iPatch = getInterpolatePatch(ip2, rows[1], cols[1], x, y); + iDxPatch = getInterpolatePatch(idxp2, rows[4], cols[4], x, y); + iDyPatch = getInterpolatePatch(idyp2, rows[5], cols[5], x, y); + } + rows_ip = rows_idxp = rows_idyp = 1; + cols_ip = cols_idxp = cols_idyp = 2 * this.WINSZ * 2 * this.WINSZ; + + for (idx = 0; idx < this.WINSZ; idx++) { + c_xx += iDxPatch[idx] * iDxPatch[idx]; + c_xy += iDxPatch[idx] * iDyPatch[idx]; + c_yy += iDyPatch[idx] * iDyPatch[idx]; + } + + c_det = (c_xx * c_yy - c_xy * c_xy); + tr = c_xx + c_yy; + + if (c_det == (float) 0) { + break; + } + + if ((float) (c_det / (tr + (float) 0.00001)) < (float) this.accuracy) { + valid[i] = 0; + break; + } + + c_det = (float) (1 / c_det); + for (k = 0; k < this.LK_ITER; /* max_iter; */k++) { + if ((x + dX - (float) this.WINSZ) < (float) 0 + || (y + dY - (float) this.WINSZ) < (float) 0 + || (y + dY + (float) this.WINSZ) >= (float) imgSize_1 + || (x + dX + (float) this.WINSZ) >= (float) imgSize_2) { + valid[i] = 0; + break; + } + + // printf("x and dx = %d\t%d\t%f\t%f\t%f\t%f\n", i, level, x, dX, y, + // dY); + if (level == 0) { + jPatch = getInterpolatePatch(jp1, this.m_rows, this.m_cols, x + dX, y + dY); + } + if (level == 1) { + jPatch = getInterpolatePatch(jp2, this.m_rows_r, this.m_cols_r, x + dX, y + dY); + } + rows_jp = 1; + cols_jp = 2 * this.WINSZ * 2 * this.WINSZ; + + eX = 0; + eY = 0; + for (idx = 0; idx < winSizeSq; idx++) { + dIt = iPatch[idx] - jPatch[idx]; + eX += dIt * iDxPatch[idx]; + eY += dIt * iDyPatch[idx]; + } + + mX = c_det * (eX * c_yy - eY * c_xy); + mY = c_det * (-eX * c_xy + eY * c_xx); + // printf("mx = %d\t%d\t%f\t%f\t%f\t%f\t%f\n", i, level, mX, mY, + // c_det, eX, eY); + dX = dX + mX; + dY = dY + mY; + + if ((mX * mX + mY + mY) < this.accuracy) { + break; + } + } + } + + newPnt[i] = fPnt[i * 2] + dX; + newPnt[1 * nFeatures + i] = fPnt[i * 2 + 1] + dY; + + } + + return valid; + } + + public void calcTrack(IXLM ixlm, IYLM iylm, IXLMR ixlmr, IYLMR iylmr) { + float[][] Ipyrs = new float[6][]; + int[] rows = new int[6]; + int[] cols = new int[6]; + float[] newpoints, features, np_temp; + int rows_n, cols_n, rows_np, cols_np, i, j, k, m, n, numFind; + int[] status; + int rows_s, cols_s; + + Ipyrs[0] = ixlm.getImage(); + rows[0] = ixlm.getRows(); + cols[0] = ixlm.getCols(); + Ipyrs[2] = ixlm.getResult(); + rows[2] = ixlm.getRowsR(); + cols[2] = ixlm.getColsR(); + Ipyrs[3] = iylm.getResult(); + rows[3] = iylm.getRowsR(); + cols[3] = iylm.getColsR(); + + Ipyrs[1] = ixlmr.getImage(); + rows[1] = ixlmr.getRows(); + cols[1] = ixlmr.getCols(); + Ipyrs[4] = ixlmr.getResult(); + rows[4] = ixlmr.getRowsR(); + cols[4] = ixlmr.getColsR(); + Ipyrs[5] = iylmr.getResult(); + rows[5] = iylmr.getRowsR(); + cols[5] = iylmr.getColsR(); + + features = this.m_features; + rows_n = 2; + cols_n = this.m_cols_f; + newpoints = new float[rows_n * cols_n]; + + // status_ = calcPyrLKTrack(...) + status = this.calcPyrLKTrack(Ipyrs, rows, cols, newpoints); + rows_s = 1; + cols_s = this.m_cols_f; + + // fDeepCopy + np_temp = new float[newpoints.length]; + rows_np = rows_n; + cols_np = cols_n; + for (i = 0; i < newpoints.length; i++) { + np_temp[i] = newpoints[i]; + } + if (rows_s * cols_s > 0) { + int[] findInd; + int rows_f, cols_f; + rows_f = rows_s * cols_s; + cols_f = 1; + findInd = new int[rows_f * cols_f]; + + k = 0; + m = 0; + numFind = 0; + for (i = 0; i < cols_s; i++) { + for (j = 0; j < rows_s; j++) { + if (status[j * cols_s + i] != 0) { + findInd[k] = m; + numFind++; + } else { + findInd[k] = 0; + } + + m++; + k++; + } + } + + rows_n = rows_np; + cols_n = numFind; + newpoints = new float[rows_n * cols_n]; + + k = 0; + n = 0; + for (i = 0; i < rows_np; i++) { + for (j = 0; j < cols_np; j++) { + m = findInd[j]; + if (m > 0) { + newpoints[k++] = np_temp[i * cols_np + m]; + } + } + } + } + + // features_ = fDeepCopy(newpoints_); + this.m_rows_f = rows_n; + this.m_cols_f = cols_n; + features = this.m_features = new float[newpoints.length]; + for (k = 0; k < newpoints.length; k++) { + features[k] = newpoints[k]; + } + } + + public void printImage() { + // result validation + for (int i = 0; i < this.m_rows; i++) { + for (int j = 0; j < this.m_cols; j++) { + System.printI((int) (this.m_image[i * this.m_cols + j] * 10)); + } + } + } + + public void print3f() { + // result validation + System.out.println(11111111); + for (int j = 0; j < this.N_FEA; j++) { + System.out.println((int) (this.m_3f[0][j] * 10)); + } + System.printI(22222222); + for (int j = 0; j < this.N_FEA; j++) { + System.out.println((int) (this.m_3f[1][j] * 10)); + } + System.printI(33333333); + for (int j = 0; j < this.N_FEA; j++) { + System.out.println((int) (this.m_3f[2][j] * 10)); + } + } + + public void printFeatures() { + // result validation + System.out.println("this.m_rows_f="+this.m_rows_f); + System.out.println("this.m_cols_="+this.m_cols_f); + System.out.println("m_features.length="+this.m_features.length); + for (int i = 0; i < this.m_rows_f; i++) { + for (int j = 0; j < this.m_cols_f; j++) { + System.out.println((int) (this.m_features[i * this.m_cols_f + j] * 10)); + } + } + } + + public void run() { + + + ImageReader imageReader=new ImageReader(); + +// int[] input = getInput(false); + int[] input=imageReader.readImage("1.bmp"); + + int pnum = 32; // 60; + setBPNum(pnum); + int range = (input[0]) / pnum; + for (int i = 0; i < pnum; i++) { + BlurPiece bp = new BlurPiece(i, range, input); + bp.blur(); + addBP(bp); + } + postBlur(); + + + float[] Icur = getImage(); + + pnum = 16; // 30; + range = getRows() / pnum; + int rows = getRows(); + int cols = getCols(); + + // create ImageX to calc Sobel_dX + ImageXM imageXM = new ImageXM(pnum, rows, cols); + for (int i = 0; i < pnum; i++) { + ImageX imageX = new ImageX(i, range, Icur, rows, cols); + imageX.calcSobel_dX(); + imageXM.addCalcSobelResult(imageX); + } + imageXM.calcSobel_dX(); + + + // create ImageY to calc Sobel_dY + ImageYM imageYM = new ImageYM(pnum, rows, cols); + for (int i = 0; i < pnum; i++) { + ImageY imageY = new ImageY(i, range, Icur, rows, cols); + imageY.calcSobel_dY(); + imageYM.addCalcSobelResult(imageY); + } + imageYM.calcSobel_dY(); + + + // create a Lambda to aggregate results from the ImageXs + Lambda lda = new Lambda(WINSZ, N_FEA, pnum, getNumP()); + lda.calcGoodFeature(imageXM, imageYM); +// lda.calcGoodFeature(eom_imageXM, eom_imageYM); + // validation + // lda.printImage(); + lda.reshape(); + // validation + // lda.printImage(); + + // TASK: calcInd + int r = lda.getR(); + float[] data = lda.getImage(); + int c_rows = lda.getRows(); + int c_cols = lda.getCols(); + int c_pnum = lda.getNumP(); + int c_range = c_rows / c_pnum; + + IDX IDXarray[]=new IDX[c_pnum]; + for (int i = 0; i < c_pnum; i++) { + IDX idx = new IDX(lda.N_FEA, i, c_range, data, c_rows, c_cols, r); + idx.fSortIndices(); + // validation + // idx.printInd(); + IDXarray[i]=idx; + } + + resize(); + + for (int i = 0; i < c_pnum; i++) { + addIDX(IDXarray[i]); + } + + // TASK:calcFeatures + calcFeatures(); + + // TASK:startTrackingLoop + do{ + + int pnum1 = 8; // 15; // * 2; + data = getImage(); + rows = getRows(); + cols = getCols(); + range = rows / pnum1; + + IXLM ixlm = new IXLM(pnum1, data, rows, cols); + IYLM iylm = new IYLM(pnum1, data, rows, cols); + for (int i = 0; i < pnum1; i++) { + IXL ixl = new IXL(i, range, data, rows, cols); + ixl.calcSobel_dX(); + ixlm.addCalcSobelResult(ixl); + IYL iyl = new IYL(i, range, data, rows, cols); + iyl.calcSobel_dY(); + iylm.addCalcSobelResult(iyl); + } + ixlm.calcSobel_dX(); + iylm.calcSobel_dY(); + + data = getImageR(); + rows = getRowsR(); + cols = getColsR(); + range = rows / pnum1; + IXLMR ixlmr = new IXLMR(pnum1, data, rows, cols); + IYLMR iylmr = new IYLMR(pnum1, data, rows, cols); + + for (int i = 0; i < pnum1; i++) { + IXLR ixl = new IXLR(i, range, data, rows, cols); + ixl.calcSobel_dX(); + ixlmr.addCalcSobelResult(ixl); + IYLR imy = new IYLR(i, range, data, rows, cols); + imy.calcSobel_dY(); + iylmr.addCalcSobelResult(imy); + } + ixlmr.calcSobel_dX(); + iylmr.calcSobel_dY(); + + int pnum2 = 32; // 60; // * 2; +// input = getInput(true); + input = imageReader.readImage("1.bmp"); + this.m_count++; + + +// float ip1[]=new float[getRows()*getCols()]; +// for(int ip1idx=0;ip1idx