main(int argc, char **argv) { char *filein, *fileout; l_float32 deg2rad; l_float32 angle, conf; PIX *pixs, *pixd; static char mainName[] = "deskew"; if (argc != 3) exit(ERROR_INT(" Syntax: deskew filein fileout", mainName, 1)); filein = argv[1]; fileout = argv[2]; deg2rad = 3.1415926535 / 180.; if ((pixs = pixRead(filein)) == NULL) exit(ERROR_INT("pixs not made", mainName, 1)); pixd = deskew(pixs, DESKEW_REDUCTION); pixWrite(fileout, pixd, IFF_PNG); pixDestroy(&pixd); pixDestroy(&pixs); exit(0); }
Pix* dewarpOrDeskew(Pix* pix) { FUNCNAME("dewarpOrDeskew"); Pix* pixText = NULL; l_int32 dewarpResult = pixDewarp(pix, &pixText); if(dewarpResult){ L_INFO("dewarp failed. Attempting to correct skew instead.", procName); pixText = deskew(pix); } pixCopyResolution(pixText, pix); return pixText; }
int main(int argc,char *argv[]) { char infile[255], outfile[255]; if (argc > 1) { check_for_help(argc, argv); handle_license_and_version_args(argc, argv, TOOL_NAME); } if (argc != 3) { usage(); exit(1); } create_name(infile, argv[1], ".img"); create_name(outfile, argv[2], ".img"); deskew(infile, outfile); return 0; }
int main(int argc, char *argv[]){ // Check to ensure we've got an argument for the device we want to read from. if(argc < 2){ printf("Please provide the tty device as an argument. EX: %s /dev/tty.usbSerial0\r\n", argv[0]); return 1; } // Try opening the device, and error if we can't. int fd = open(argv[1], O_RDONLY | O_NOCTTY); if(fd < 0){ printf("Could not open the tty device, %s. Error %d: %s\r\n", argv[1], errno, strerror(errno)); return 2; } // Set serial interface attributes struct termios tty; if(tcgetattr(fd, &tty) != 0){ printf("Could not get tty device attributes. Error %d: %s\r\n", errno, strerror(errno)); return 5; } // Set what we want the serial interface attributes to be tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS8; // 8 bit characters tty.c_iflag &= ~IGNBRK; // Ignore Breaks tty.c_lflag = 0; tty.c_oflag = 0; tty.c_iflag &= ~(IXON | IXOFF | IXANY); // Disable hardware flow control tty.c_cflag |= (CLOCAL | CREAD); // Local control, enable reads tty.c_cflag &= ~(PARENB | PARODD); // No parity tty.c_cflag &= ~CSTOPB; tty.c_cflag &= ~CRTSCTS; if(tcsetattr(fd, TCSANOW, &tty) != 0){ printf("Could not set tty device attributes. Error %d: %s\r\n", errno, strerror(errno)); return 6; } // Assert and then clear DTR #ifdef __APPLE__ if(ioctl(entFileHandle, TIOCSDTR) != 0){ char logmessage[200]; sprintf(logmessage, "<ERROR> Could not assert DTR. Error %d: %s", errno, strerror(errno)); exit_cleanup(-16); } if(ioctl(entFileHandle, TIOCCDTR) != 0){ char logmessage[200]; sprintf(logmessage, "<ERROR> Could not clear DTR. Error %d: %s", errno, strerror(errno)); exit_cleanup(-17); } #elif __linux int setdtr = TIOCM_DTR; if(ioctl(entFileHandle, TIOCMBIC, &setdtr) != 0){ char logmessage[200]; sprintf(logmessage, "<ERROR> Could not assert DTR. Error %d: %s", errno, strerror(errno)); exit_cleanup(-16); } if(ioctl(entFileHandle, TIOCMBIS, &setdtr) != 0){ char logmessage[200]; sprintf(logmessage, "<ERROR> Could not clear DTR. Error %d: %s", errno, strerror(errno)); exit_cleanup(-17); } #endif // Set up a couple variables char buf [128]; int result = 0; int num_bytes = 0; // The device is now open, lets try reading from it. while(1){ // Reset our variables. result = -1; num_bytes = 0; // Check on how many bytes are available ioctl(fd, FIONREAD, &num_bytes); if(num_bytes >= 128){ // Read two bytes from the serial port int n = read(fd, buf, sizeof(buf)); // Check for an error if(n < 0){ printf("Error reading from tty device. Error %d: %s\r\n", errno, strerror(errno)); return 3; } if(n < sizeof(buf)){ printf("Error reading from tty device. Fewer bytes than expected. Num bytes: %d", n); return 4; } // Read through the bytes unsigned char i = 1; for(; i < n; i+=2){ // If for some reason we get an EOF, quit. if(buf[i-1] == EOF || buf[i] == EOF) return 0; // Deskew (whiten) the data by reading two bytes result = deskew(&buf[i-1], &buf[i]); // If whitening threw away the bits, we'll get a -1, if we didn't lets output it. if(result >= 0){ result += '0'; fwrite(&result, sizeof(result), 1, stdout); } } }else{ // Sleep for 100ms (non-blocking wait, lowers CPU time dramatically) usleep(100*1000); } } // Close the file descriptor. close(fd); return 0; }