/* * Page orientation detection (four 90 degree angles) Rasterop implementation */ void MainWindow::on_actionDetectOrientation_triggered() { l_int32 orient, alt_rot; l_float32 upconf1, leftconf1; PIX *fpixs; fpixs = pixConvertTo1(pixs, 130); pixOrientDetect(fpixs, &upconf1, &leftconf1, 0, 0); makeOrientDecision(upconf1, leftconf1, 0, 0, &orient, 1); if ((upconf1 > 1) && abs(upconf1) > abs(leftconf1)) alt_rot = 0; if ((leftconf1 > 1) && abs(leftconf1) > abs(upconf1)) alt_rot = 90; if ((upconf1 < -1) && abs(upconf1) > abs(leftconf1)) alt_rot = 180; if ((leftconf1 < -1) && abs(leftconf1) > abs(upconf1)) alt_rot = 270; if (orient == L_TEXT_ORIENT_UNKNOWN) { statusBar()->showMessage( tr("Confidence is low; no determination is made. " "But maybe there is %1 deg rotation.").arg(alt_rot), 4000); } else if (orient == L_TEXT_ORIENT_UP) { statusBar()->showMessage(tr("Text is rightside-up"), 4000); alt_rot = 0; } else if (orient == L_TEXT_ORIENT_LEFT) { statusBar()->showMessage(tr("Text is rotated 90 deg ccw"), 4000); alt_rot = 90; } else if (orient == L_TEXT_ORIENT_DOWN) { statusBar()->showMessage(tr("Text is upside-down"), 4000); alt_rot = 180; } else { /* orient == L_TEXT_ORIENT_RIGHT */ statusBar()->showMessage(tr("Text is rotated 90 deg cw"), 4000); alt_rot = 270; } pixDestroy(&fpixs); if (alt_rot) { QMessageBox::StandardButton reply; reply = QMessageBox::question(this, tr("Fix orientation?"), tr("Rotate image by %1 degrees?"). arg(alt_rot), QMessageBox::Yes|QMessageBox::No); if (reply == QMessageBox::Yes) { rotate(alt_rot/90); } } }
main(int argc, char **argv) { char *filein; l_int32 i, orient; l_float32 upconf1, upconf2, leftconf1, leftconf2, conf1, conf2; PIX *pixs, *pixt1, *pixt2; static char mainName[] = "flipdetect_reg"; if (argc != 2) exit(ERROR_INT(" Syntax: flipdetect_reg filein", mainName, 1)); filein = argv[1]; if ((pixt1 = pixRead(filein)) == NULL) exit(ERROR_INT("pixt1 not made", mainName, 1)); pixs = pixConvertTo1(pixt1, 130); pixDestroy(&pixt1); fprintf(stderr, "\nTest orientation detection\n"); startTimer(); pixOrientDetect(pixs, &upconf1, &leftconf1, 0, 0); fprintf(stderr, "Time for rop orient test: %7.3f sec\n", stopTimer()); makeOrientDecision(upconf1, leftconf1, 0, 0, &orient, 1); startTimer(); pixOrientDetectDwa(pixs, &upconf2, &leftconf2, 0, 0); fprintf(stderr, "Time for dwa orient test: %7.3f sec\n", stopTimer()); if (upconf1 == upconf2 && leftconf1 == leftconf2) { printStarredMessage("Orient results identical"); fprintf(stderr, "upconf = %7.3f, leftconf = %7.3f\n", upconf1, leftconf1); } else { printStarredMessage("Orient results differ"); fprintf(stderr, "upconf1 = %7.3f, upconf2 = %7.3f\n", upconf1, upconf2); fprintf(stderr, "leftconf1 = %7.3f, leftconf2 = %7.3f\n", leftconf1, leftconf2); } pixt1 = pixCopy(NULL, pixs); fprintf(stderr, "\nTest orient detection for 4 orientations\n"); for (i = 0; i < 4; i++) { pixOrientDetectDwa(pixt1, &upconf2, &leftconf2, 0, 0); makeOrientDecision(upconf2, leftconf2, 0, 0, &orient, 1); if (i == 3) break; pixt2 = pixRotate90(pixt1, 1); pixDestroy(&pixt1); pixt1 = pixt2; } pixDestroy(&pixt1); fprintf(stderr, "\nTest mirror reverse detection\n"); startTimer(); pixMirrorDetect(pixs, &conf1, 0, 1); fprintf(stderr, "Time for rop mirror flip test: %7.3f sec\n", stopTimer()); startTimer(); pixMirrorDetectDwa(pixs, &conf2, 0, 0); fprintf(stderr, "Time for dwa mirror flip test: %7.3f sec\n", stopTimer()); if (conf1 == conf2) { printStarredMessage("Mirror results identical"); fprintf(stderr, "conf = %7.3f\n", conf1); } else { printStarredMessage("Mirror results differ"); fprintf(stderr, "conf1 = %7.3f, conf2 = %7.3f\n", conf1, conf2); } fprintf(stderr, "\nSafer version of up-down tests\n"); pixUpDownDetectGeneral(pixs, &conf1, 0, 10, 1); pixUpDownDetectGeneralDwa(pixs, &conf2, 0, 10, 1); if (conf1 == conf2) fprintf(stderr, "Confidence results are identical\n"); else fprintf(stderr, "Confidence results differ\n"); pixDestroy(&pixs); exit(0); }