bool findY(int u) { for (int v = 0; v < ny; v++) { if (v != delY && !used[v] && g[u][v]) {//notice it's g[u][v] used[v] = 1; if (my[v] == -1 || findY(my[v])) return 1; } } return 0; }
/// <summary> /// Finds bounding-box of the data present in given image. /// </summary> /// <params name="imsSrc"> /// Source image for which bouding box has to be found. /// </params> /// <returns> Bounding box as CvRect. </returns> CvRect OCR::findBB(IplImage* imgSrc) { CvRect aux; int xmin, xmax, ymin, ymax; xmin=xmax=ymin=ymax=0; findX(imgSrc, &xmin, &xmax); findY(imgSrc, &ymin, &ymax); aux=cvRect(xmin, ymin, xmax-xmin, ymax-ymin); return aux; }
line intervalRange(line I, vector a, vector b, line e) { point i1a = intersection(I.pt1, a, e); point i1b = intersection(I.pt1, b, e); point i2a = intersection(I.pt2, a, e); point i2b = intersection(I.pt2, b, e); double xmin = min(i1a.x, i1b.x, i2a.x, i2b.x); double ymin = min(i1a.y, i1b.y, i2a.y, i2b.y); if (i1a.x == INFINITY) { i1a.x = -INFINITY; i1a.y = -INFINITY; } if (i1b.x == INFINITY) { i1b.x = -INFINITY; i1b.y = -INFINITY; } if (i2a.x == INFINITY) { i2a.x = -INFINITY; i2a.y = -INFINITY; } if (i2b.x == INFINITY) { i2b.x = -INFINITY; i2b.y = -INFINITY; } double xmax = max(i1a.x, i1b.x, i2a.x, i2b.x); double ymax = max(i1a.y, i1b.y, i2a.y, i2b.y); line l; if (xmin < xmax) { l.pt1.x = xmin; l.pt1.y = findY(xmin, e); l.pt2.x = xmax; l.pt2.y = findY(xmax, e); return l; } l.pt1.x = findX(ymin, e); l.pt1.y = ymin; l.pt2.x = findX(ymax, e); l.pt2.y = ymax; return l; }
CvRect findBB(IplImage* imgSrc) { CvRect aux; int xmin, xmax, ymin, ymax; xmin=xmax=ymin=ymax=0; findX(imgSrc, &xmin, &xmax); findY(imgSrc, &ymin, &ymax); aux=cvRect(xmin, ymin, xmax-xmin, ymax-ymin); //printf("BB: %d,%d - %d,%d\n", aux.x, aux.y, aux.width, aux.height); return aux; }
//X[i]=1 or Y[i]=1 means it's not a key vertex!!! void solve() { memset(X, 0, sizeof(X)); memset(Y, 0, sizeof(Y)); for (int i = 0; i < nx; i++) { if (mx[i] == -1) { X[i] = 1; } else { delY = mx[i]; memset(used, 0, sizeof(used)); if (findY(i)) Y[delY] = 1; } } for (int j = 0; j < ny; j++) { if (my[j] == -1) { Y[j] = 1; } else { delX = my[j]; memset(used, 0, sizeof(used)); if (findX(j)) X[delX] = 1; } } }
void mdFindFrustum( double* topLeftX, double* bottomLeftX, double* topLeftY, double* bottomLeftY) { float proj[16]; float modl[16]; float clip[16]; float t; /* Get the current PROJECTION matrix from OpenGL */ glGetFloatv( GL_PROJECTION_MATRIX, proj ); /* Get the current MODELVIEW matrix from OpenGL */ glGetFloatv( GL_MODELVIEW_MATRIX, modl ); /* Combine the two matrices (multiply projection by modelview) */ clip[ 0] = modl[ 0] * proj[ 0] + modl[ 1] * proj[ 4] + modl[ 2] * proj[ 8] + modl[ 3] * proj[12]; clip[ 1] = modl[ 0] * proj[ 1] + modl[ 1] * proj[ 5] + modl[ 2] * proj[ 9] + modl[ 3] * proj[13]; clip[ 2] = modl[ 0] * proj[ 2] + modl[ 1] * proj[ 6] + modl[ 2] * proj[10] + modl[ 3] * proj[14]; clip[ 3] = modl[ 0] * proj[ 3] + modl[ 1] * proj[ 7] + modl[ 2] * proj[11] + modl[ 3] * proj[15]; clip[ 4] = modl[ 4] * proj[ 0] + modl[ 5] * proj[ 4] + modl[ 6] * proj[ 8] + modl[ 7] * proj[12]; clip[ 5] = modl[ 4] * proj[ 1] + modl[ 5] * proj[ 5] + modl[ 6] * proj[ 9] + modl[ 7] * proj[13]; clip[ 6] = modl[ 4] * proj[ 2] + modl[ 5] * proj[ 6] + modl[ 6] * proj[10] + modl[ 7] * proj[14]; clip[ 7] = modl[ 4] * proj[ 3] + modl[ 5] * proj[ 7] + modl[ 6] * proj[11] + modl[ 7] * proj[15]; clip[ 8] = modl[ 8] * proj[ 0] + modl[ 9] * proj[ 4] + modl[10] * proj[ 8] + modl[11] * proj[12]; clip[ 9] = modl[ 8] * proj[ 1] + modl[ 9] * proj[ 5] + modl[10] * proj[ 9] + modl[11] * proj[13]; clip[10] = modl[ 8] * proj[ 2] + modl[ 9] * proj[ 6] + modl[10] * proj[10] + modl[11] * proj[14]; clip[11] = modl[ 8] * proj[ 3] + modl[ 9] * proj[ 7] + modl[10] * proj[11] + modl[11] * proj[15]; clip[12] = modl[12] * proj[ 0] + modl[13] * proj[ 4] + modl[14] * proj[ 8] + modl[15] * proj[12]; clip[13] = modl[12] * proj[ 1] + modl[13] * proj[ 5] + modl[14] * proj[ 9] + modl[15] * proj[13]; clip[14] = modl[12] * proj[ 2] + modl[13] * proj[ 6] + modl[14] * proj[10] + modl[15] * proj[14]; clip[15] = modl[12] * proj[ 3] + modl[13] * proj[ 7] + modl[14] * proj[11] + modl[15] * proj[15]; /* Extract the numbers for the RIGHT plane */ frustum[0][0] = clip[ 3] - clip[ 0]; frustum[0][1] = clip[ 7] - clip[ 4]; frustum[0][2] = clip[11] - clip[ 8]; frustum[0][3] = clip[15] - clip[12]; /* Normalize the result */ t = sqrt( frustum[0][0] * frustum[0][0] + frustum[0][1] * frustum[0][1] + frustum[0][2] * frustum[0][2] ); frustum[0][0] /= t; frustum[0][1] /= t; frustum[0][2] /= t; frustum[0][3] /= t; /* Extract the numbers for the LEFT plane */ frustum[1][0] = clip[ 3] + clip[ 0]; frustum[1][1] = clip[ 7] + clip[ 4]; frustum[1][2] = clip[11] + clip[ 8]; frustum[1][3] = clip[15] + clip[12]; /* Normalize the result */ t = sqrt( frustum[1][0] * frustum[1][0] + frustum[1][1] * frustum[1][1] + frustum[1][2] * frustum[1][2] ); frustum[1][0] /= t; frustum[1][1] /= t; frustum[1][2] /= t; frustum[1][3] /= t; /* Extract the BOTTOM plane */ frustum[2][0] = clip[ 3] + clip[ 1]; frustum[2][1] = clip[ 7] + clip[ 5]; frustum[2][2] = clip[11] + clip[ 9]; frustum[2][3] = clip[15] + clip[13]; /* Normalize the result */ t = sqrt( frustum[2][0] * frustum[2][0] + frustum[2][1] * frustum[2][1] + frustum[2][2] * frustum[2][2] ); frustum[2][0] /= t; frustum[2][1] /= t; frustum[2][2] /= t; frustum[2][3] /= t; /* Extract the TOP plane */ frustum[3][0] = clip[ 3] - clip[ 1]; frustum[3][1] = clip[ 7] - clip[ 5]; frustum[3][2] = clip[11] - clip[ 9]; frustum[3][3] = clip[15] - clip[13]; /* Normalize the result */ t = sqrt( frustum[3][0] * frustum[3][0] + frustum[3][1] * frustum[3][1] + frustum[3][2] * frustum[3][2] ); frustum[3][0] /= t; frustum[3][1] /= t; frustum[3][2] /= t; frustum[3][3] /= t; /* Extract the FAR plane */ frustum[4][0] = clip[ 3] - clip[ 2]; frustum[4][1] = clip[ 7] - clip[ 6]; frustum[4][2] = clip[11] - clip[10]; frustum[4][3] = clip[15] - clip[14]; /* Normalize the result */ t = sqrt( frustum[4][0] * frustum[4][0] + frustum[4][1] * frustum[4][1] + frustum[4][2] * frustum[4][2] ); frustum[4][0] /= t; frustum[4][1] /= t; frustum[4][2] /= t; frustum[4][3] /= t; /* Extract the NEAR plane */ frustum[5][0] = clip[ 3] + clip[ 2]; frustum[5][1] = clip[ 7] + clip[ 6]; frustum[5][2] = clip[11] + clip[10]; frustum[5][3] = clip[15] + clip[14]; /* Normalize the result */ t = sqrt( frustum[5][0] * frustum[5][0] + frustum[5][1] * frustum[5][1] + frustum[5][2] * frustum[5][2] ); frustum[5][0] /= t; frustum[5][1] /= t; frustum[5][2] /= t; frustum[5][3] /= t; //Top X and Y: intersect LEFT and TOP *topLeftX = findX(frustum[1],frustum[3]); *topLeftY = findY(frustum[1],frustum[3]); //Bottom X and Y: intersect LEFT and BOTTOM *bottomLeftX = findX(frustum[1],frustum[2]); *bottomLeftY = findY(frustum[1],frustum[2]); }