void ImageViewer_ex2::mouseReleaseEvent(QMouseEvent *ev) { if(pinmanager->pinlist.count()<pinmanager->MaxPins){ pinmanager->createPin(ev->pos()); }else{ switch (pinmanager->type) { case PinManager::TYPE_THREE: adjustImage(this->width(), this->height()); break; case PinManager::TYPE_FOUR: adjustimageAffineSimilarity(); break; default: break; } } }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); connect(ui->browseSampleButton, SIGNAL(clicked()), this, SLOT(browseSampleImages())); connect(ui->browseTestButton, SIGNAL(clicked()), this, SLOT(browseTestImage())); connect(ui->recognizeButton, SIGNAL(clicked()), this, SLOT(recognize())); connect(ui->adjustButton, SIGNAL(clicked()), this, SLOT(adjustImage())); //connect(ui->teachButton, SIGNAL(clicked()), this, SLOT(teach())); ui->recognizeButton->setEnabled(false); ui->noiseSpinBox->setEnabled(false); ui->adjustButton->setEnabled(false); imageLabels[0] = ui->sample00ImageLabel; imageLabels[1] = ui->sample01ImageLabel; imageLabels[2] = ui->sample02ImageLabel; imageLabels[3] = ui->sample03ImageLabel; imageLabels[4] = ui->sample10ImageLabel; imageLabels[5] = ui->sample11ImageLabel; imageLabels[6] = ui->sample12ImageLabel; imageLabels[7] = ui->sample13ImageLabel; imageLabels[8] = ui->sample20ImageLabel; imageLabels[9] = ui->sample21ImageLabel; imageLabels[10] = ui->sample22ImageLabel; imageLabels[11] = ui->sample23ImageLabel; similarityLabels[0] = ui->similarity0Label; similarityLabels[1] = ui->similarity1Label; similarityLabels[2] = ui->similarity2Label; this->setFixedSize(this->size()); }
int main(int argc, char *argv[]) { image myPic; imageInfo picInfo; int count; char *outputType = NULL; int err; int aCrop = NO; int left = -1, right = -1, top = -1, bottom = -1; double xscale = 1, yscale = 1; double xs2, ys2; int xdim = 0, ydim = 0; int ditherMode = ' '; int mMono = NO; int outType = NO; int scaletofit = NO; int numBits = 1; char *outFile = NULL; char *type = NULL, *ext = NULL; char *p; int nv; double darken = 0; double contrast = 0; double rotate = 0; struct stat sbuf; int blend = NO; static char filename[MAXPATHLEN + 1] = ""; int negative = NO; int enhance = NO; formatInfo fInfo; count = getargs(argc, argv, "nbosabLiRiTiBixdydXiYidcmbpbsbbiDdSbKdfseird", &negative, &outputType, &aCrop, &left, &right, &top, &bottom, &xscale, &yscale, &xdim, &ydim, &ditherMode, &mMono, &outType, &scaletofit, &numBits, &darken, &blend, &contrast, &outFile, &enhance, &rotate ); if (count < 0 || count == argc) { if (count < 0 && -count != '-') fprintf(stderr, "Bad flag: %c\n", -count); fprintf(stderr, "Usage: %s [-options] filename\n" " options:\n" "\tn: make negative\n" "\to: string indicating output format\n" "\ta: auto crop non plotting areas\n" "\tL, R, T, B: specify where to crop picture\n" "\tx, y: specify scale factor in that direction\n" "\tX, Y: specify dimension of picture in that direction\n" "\td: select dither method: (D)ither, (T)hreshold, or (H)alftone\n" "\tm: convert image to monochrome\n" "\tp: dither image for output to printer\n" "\ts: scale image to fill up specified screen\n" "\tb: number of bits to dither to\n" "\tD: how much to brighten image\n" "\tK: contrast level\n" "\tS: blend pixels together when scaling\n" "\tf: file name to save to\n" "\te: contrast for enhance image\n" "\tr: number of degrees to rotate\n" , *argv); exit(1); } for (; count < argc; count++) { if ((err = load_pic(argv[count], &myPic))) { fprintf(stderr, "Cannot load file %s\nError: %s\n", argv[count], picErrorStr(err)); exit(1); } if (!getImageInfo(argv[count], &picInfo)) type = picInfo.extension; if (!outputType) outputType = type; if (!infoForFormat(outputType, &fInfo)) { ext = fInfo.extension; if (scaletofit && !xdim && !ydim && fInfo.maxWidth && fInfo.maxHeight) { xdim = fInfo.maxWidth; ydim = fInfo.maxHeight; } } if (mMono) makeMono(&myPic); if (left >= 0 || right >= 0 || top >= 0 || bottom >= 0) { if (left < 0) left = 0; if (right < 0) right = myPic.width - 1; if (top < 0) top = 0; if (bottom < 0) bottom = myPic.height - 1; cropImage(left, top, right, bottom, &myPic); } if (aCrop) autoCropImage(&myPic, 40); if (rotate) rotateImage(&myPic, (rotate * -3.141592) / 180.0); xs2 = xscale; ys2 = yscale; if (scaletofit) { if (!ydim && xdim) { xs2 = (double) xdim / ((double) myPic.width * xscale) * xscale; ys2 = ((double) xdim / ((double) myPic.width * xscale)) * yscale; } else if (ydim) { xs2 = ((double) ydim / ((double) myPic.height * yscale)) * xscale; ys2 = (double) ydim / ((double) myPic.height * yscale) * yscale; if (xdim && (myPic.width * xs2) > xdim) { xs2 = (double) xdim / ((double) myPic.width * xscale) * xscale; ys2 = ((double) xdim / ((double) myPic.width * xscale)) * yscale; } } } else { if (xdim) xs2 = (double) xdim / (double) myPic.width; if (ydim) ys2 = (double) ydim / (double) myPic.height; } xscale = xs2; yscale = ys2; scaleImage(xscale, yscale, blend, &myPic); if (darken || contrast) adjustImage(&myPic, contrast, darken); if (enhance) { makeMono(&myPic); enhanceImage(&myPic, enhance); } handle_dithering(ditherMode, &myPic, outType, numBits); if (negative) negateImage(&myPic); if (outFile) { strcpy(filename, outFile); if (!stat(filename, &sbuf) && (sbuf.st_mode & S_IFDIR)) { if (filename[strlen(filename) - 1] != '/') strcat(filename, "/"); if ((p = strrchr(argv[count], '/'))) strcat(filename, p + 1); else strcat(filename, argv[count]); } } else strcpy(filename, argv[count]); p = change_extension(filename, type, ext, 0); nv = 2; while (!stat(p, &sbuf)) { p = change_extension(filename, type, ext, nv); nv++; } if ((err = save_pic(p, outputType, &myPic))) { fprintf(stderr, "Cannot save file %s\nError: %s\n", p, picErrorStr(err)); exit(1); } fprintf(stderr, "Saved %s as %s\n", argv[count], p); freeImage(&myPic); } exit(0); return 0; }