public ArrayList getSimpleSubtitle_old(byte[,] binDat) { int col, row, colLen, rowLen; col = 0; row = 0; // colLen = binDat.GetLength(0) - 4; rowLen = binDat.GetLength(0); int ttlCallTime = 2;// the recursive time to call the function int callTime = 0; for (int i = 0; i < ttlCallTime; i++) { m_sqrAlist.Clear(); while (true) { callTime++; colLen = binDat.GetLength(0) - 4; //if (!getSimpleSquareDat(binDat, ref col, ref colLen, false)) //{ // break; //} SquareDat squareDat = new SquareDat(); squareDat.col = col; squareDat.row = row; squareDat.rowLen = rowLen; squareDat.colLen = colLen; m_sqrAlist.Add(squareDat); col += colLen; m_ttlColLen += colLen; //if (startRow > row) startRow = row;//set the row to the minimam value m_sqrNumbers++; } if (m_sqrAlist.Capacity == 0) { break; } //if (m_sqrNumbers > 0 && m_sqrNumbers < 10000) { //colLen = m_ttlColLen / m_sqrNumbers; col = 0; } } //check if they are allmost the same size return(m_sqrAlist); }
public ArrayList getLikelySubtitleImg(byte[,] binDat) { ArrayList sqrAlist = new ArrayList(); int col, row, colLen, rowLen; col = 0; row = 0; int chHmax = 120, chHmin = 16; int chWmax = 70, chWmin = 16; colLen = chHmin; rowLen = chWmin; int ttlCallTime = 2;// the recursive time to call the function int callTime = 0; for (int i = 0; i < ttlCallTime; i++) { sqrAlist.Clear(); while (true) { callTime++; if (!getSquareDat(binDat, ref col, ref row, ref colLen, ref rowLen, false)) { break; } if (m_startRow != 0 && row != 0 && Math.Abs(m_startRow - row) > rowLen / 3) { break; } //if (i == ttlCallTime - 1) //{ // if (row - startRow >= rowLen)// to avoid searching the line below // { // col += colLen; // continue; // } //} SquareDat squareDat = new SquareDat(); //if (colLen > chWmax || colLen < chWmin || rowLen > chHmax || rowLen < chHmin) //{ // col += colLen; // continue; //} squareDat.col = col; if (m_sqrNumbers > 100) { squareDat.row = m_startRow; squareDat.rowLen = m_ttlRowLen / m_sqrNumbers; } else { squareDat.row = row; squareDat.rowLen = rowLen; } squareDat.colLen = colLen; sqrAlist.Add(squareDat); col += colLen; m_ttlRow += row; m_ttlColLen += colLen; m_ttlRowLen += rowLen; //if (startRow > row) startRow = row;//set the row to the minimam value m_sqrNumbers++; } if (sqrAlist.Capacity == 0) { break; } if (m_sqrNumbers > 0 && m_sqrNumbers < 10000) { //colLen = m_ttlColLen / m_sqrNumbers; rowLen = m_ttlRowLen / m_sqrNumbers; col = 0; m_startRow = m_ttlRow / m_sqrNumbers; //let the row be the value of the maximum group memebers , ie 1 2 2 3 , the row is 2 row = m_startRow; } } //check if they are allmost the same size return(sqrAlist); }
/// <summary> /// a simple version of get area from imgage including subtitle that is it has just the excat subtitle with fixed top and bottom /// </summary> /// <param name="binDat"></param> /// <param name="colLeft"></param> /// <param name="rowTop"></param> /// <param name="colLen"></param> /// <param name="rowLen"></param> /// <param name="bFixedRow"></param> /// <returns></returns> public ArrayList getSimpleSquareDat(byte[,] binDat, ref int colLeft, ref int colLen, double cdf_H, double cdf_L, double des_H, double des_L, bool bFixedRow) { int colPtr; int ttlCol; ttlCol = binDat.GetLength(1); int ttlRow; ttlRow = binDat.GetLength(0); bool retVal = true; //search the left column of the square colPtr = colLeft; int rowLen = ttlRow; // calculat the vertical points number for each horizontal points double[] hstGramVal = new double[ttlCol]; int affectLen = 6;// used to set the adjacent point value to 1 ,if their neighbours are not zero. int sumPtr = 0; for (int c = 0; c < ttlCol; c++) { for (int r = 0; r < ttlRow; r++) { hstGramVal[c] += binDat[r, c]; // line density } //if (c > affectLen) //{ // if (hstGramVal[c] != 0 && hstGramVal[c - affectLen] != 0) // for (int subC = c - affectLen + 1; subC < c; subC++) // { // hstGramVal[subC] = hstGramVal[subC] == 0 ? 1 : hstGramVal[subC]; // } //} hstGramVal[c] = hstGramVal[c] / 255.0 / ttlRow; if (hstGramVal[c] != 0 && sumPtr == 0) { sumPtr = c; } if (sumPtr != 0) { if (c - sumPtr >= colLen) { hstGramVal = ImgeTool.removeNoise(hstGramVal, sumPtr, c, cdf_H, cdf_L, des_H, des_L, true); sumPtr = 0; } } } // search the border from the midle part of the line... // while(true) { m_sqrAlist.Clear(); long callTimes = 0; int curPos, nextPos; int searchStep = 1;// //curPos = ttlCol / 2; curPos = 0; int searchWidth; searchWidth = rowLen; // the default search width is the same avheight int mySchWidth = (int)(0.6 * searchWidth); // seach from the 60% of the default width , for chinese charater is not the exact squre mySchWidth = 2; while (true) { callTimes++; nextPos = getBorderAtLine(hstGramVal, curPos, searchStep); if (nextPos < 0) { break; } int dist = Math.Abs(curPos - nextPos); if (dist <= 1)//|| dist > searchWidth) { curPos += 1; searchStep = 1; } else { if (dist >= 1 && dist < mySchWidth)// adjacent column { curPos += 1; searchStep = 1; goto Next; // change the curpos and begin a new search } else if (dist >= mySchWidth) // && dist <= searchWidth)// find allmost an exact border { SquareDat squareDat = new SquareDat(); // memory ....!!!!!!!!!!!!!!! squareDat.col = searchStep < 0 ? nextPos : curPos; squareDat.row = 0; squareDat.rowLen = 0;// NA squareDat.colLen = Math.Abs(curPos - nextPos); m_sqrAlist.Add(squareDat); curPos = nextPos + 1; continue; } else// dist > searchWidth, it might be encounter an block of white point or black piont { //MessageBox.Show("Wrong process!"); throw new Exception("Your process is not correct!"); } } //if (nextPos == 0 && searchDir == -1) //{ // curPos = curPos = ttlCol / 2; // searchDir = 1; // continue; //} Next: if (nextPos + searchStep >= ttlCol - 1) { // end codes.... break; } } } // exit: return(m_sqrAlist); }