Example #1
0
int main(int argc, char* argv[])
{
    int count = argc - 1;
    char **files = argv + 1;
    if (count == 0) {
        printf("No files specified, defaulting to %s\n\n", default_filename);
        count = 1;
        files = &default_filename;
    }

    for (int i = 0; i < count; i++)
    {
        if (i != 0) printf("\n");
        char *filename = files[i];
        printf("Processing %s\n", filename);
        UInt8Array2D image = pgm_read(filename);

        if (image.sizeX == 1 && image.sizeY == 1) continue;

        struct perfdata perfdata;
        UInt8Array2D binarizedImage = UInt8Array2D_Construct(image.sizeX, image.sizeY);
        UInt8Array2D thinnedImage = UInt8Array2D_Construct(image.sizeX, image.sizeY);
        Extract(&image, &perfdata, &binarizedImage, &thinnedImage);

        printf("Histogram generation: %f\n", diff(perfdata.start_segmentation, perfdata.start_histogram));
        printf("        Segmentation: %f\n", diff(perfdata.start_equalization, perfdata.start_segmentation));
        printf("        Equalization: %f\n", diff(perfdata.start_orientation, perfdata.start_equalization));
        printf("         Orientation: %f\n", diff(perfdata.start_binarisation, perfdata.start_orientation));
        printf("        Binarisation: %f\n", diff(perfdata.start_thinning, perfdata.start_binarisation));
        printf("      Ridge thinning: %f\n", diff(perfdata.start_detection, perfdata.start_thinning));
        printf("  Minutiae detection: %f\n", diff(perfdata.start_filtering, perfdata.start_detection));
        printf("  Minutiae filtering: %f\n", diff(perfdata.end, perfdata.start_filtering));
        printf("               TOTAL: %f\n", diff(perfdata.end, perfdata.start));

        int filenameLen = strlen(filename);

        char binarizedFilename[filenameLen + 11];
        strcpy(binarizedFilename, filename);
        strcpy(binarizedFilename + filenameLen - 4, ".binarized.pgm");
        pgm_write(binarizedFilename, &binarizedImage);

        char thinnedFilename[filenameLen + 9];
        strcpy(thinnedFilename, filename);
        strcpy(thinnedFilename + filenameLen - 4, ".thinned.pgm");
        pgm_write(thinnedFilename, &thinnedImage);
    }

    return 0;
}
Example #2
0
File: main.c Project: aumgn/Cours
int main(int argc, char* argv[]) {
    /* Arguments */
    if ( argc != 2 ) {
        printf("\nUsage: %s <file>\n\n", argv[0]);
        exit(0);
    }

    pgm_t* src = pgm_read(argv[1]);
    
    dmap_t* sobx = sobel_x(src);
    dmap_t* soby = sobel_y(src);
    dmap_t* sobm = magnitude(src, sobx, soby);
    dmap_t* mxx = multiply(src, sobx, sobx);
    dmap_t* myy = multiply(src, soby, soby);
    dmap_t* mxy = multiply(src, sobx, soby);
    dmap_t* mxxf = binomial_filter(mxx);
    dmap_t* myyf = binomial_filter(myy);
    dmap_t* mxyf = binomial_filter(mxy);
    dmap_t* harris1 = harris(src, mxxf, myyf, mxyf, 1);
    dmap_t* harris1f = harris(src, mxxf, myyf, mxyf, 1);

    dmap_write(sobx, argv[1], "sobel_x");
    dmap_write(soby, argv[1], "sobel_y");
    dmap_write(sobm, argv[1], "sobel_magnitude");

    dmap_write(mxx, argv[1], "xx");
    dmap_write(myy, argv[1], "yy");
    dmap_write(mxy, argv[1], "xy");

    dmap_write(mxxf, argv[1], "xxf");
    dmap_write(myyf, argv[1], "yyf");
    dmap_write(mxyf, argv[1], "xyf");

    dmap_write(harris1, argv[1], "harris1");
    dmap_write(harris1f, argv[1], "harris1f");

    pgm_free(src);
    dmap_free(sobx);
    dmap_free(soby);
    dmap_free(sobm);
    dmap_free(mxx);
    dmap_free(myy);
    dmap_free(mxy);
    dmap_free(harris1);

    return 0;
}
Example #3
0
int main(int argc, char* argv[]) {
    /* Arguments */
    if ( argc != 2 ) {
      printf("\nUsage: %s file \n\n", argv[0]);
      exit(0);
    }

    pgm_t* src = pgm_read(argv[1]);
    pgm_t* dest = pgm_create_empty(src->cols, src->rows, src->maxval);
    
    for (int i = 1; i < dest->rows - 1; i++) {
      for (int j = 1; j < dest->cols - 1; j++) {
          gray g = PGM_AT(src, i, j);

          gray c1 = PGM_AT(src, i-1, j-1);
          gray c2 = PGM_AT(src, i-1, j+1);
          gray c3 = PGM_AT(src, i+1, j-1);
          gray c4 = PGM_AT(src, i+1, j+1);

          gray s1 = PGM_AT(src, i-1, j);
          gray s2 = PGM_AT(src, i, j-1);
          gray s3 = PGM_AT(src, i+1, j);
          gray s4 = PGM_AT(src, i, j+1);

          PGM_AT(dest, i, j) = (
                  c1 + c2 + c3 + c4
                  + 2 * s1 + 2 * s2 + 2 * s3 + 2 * s4
                  + 4 * g) / 16;
      }
    }

    pgm_write(dest, true);

    pgm_free(dest);
    pgm_free(src);

    return 0;
}
Example #4
0
int main(int argc, char *argv[])
{
	/* TODO: Program efekt adi ve EN AZ 1 resim dosyasi olmak uzere EN AZ
	 * 2 arguman istemektedir. Bu bilgiye gore asagidaki if()'in icerisini
	 * doldurun.
	 */
	//argc kaçtan küçük olacak onu if'e yaz.
	if (argc < 3) {
		fprintf(stderr, "Usage: %s <invert|binarize|noise|smooth> <PGM image 1> <PGM image 2> ... <PGM image N>\n", argv[0]);
		return 1;
	}

	int i;
	char *effect_name = argv[1];	// Komut satirindan gelen efekt adi

	/* TODO: Bazi efektlerin ihtiyac duyabilecegi rand() rassal
	 * sayi uretecini seed edin.0.eleman prog.adı 1.eleman effect adı. */

	/* argv[0]:     Programin adi
	 * argv[1]:     Efekt cesidi: invert, binarize, noise, smooth
	 * argv[2] ...  argv[argc-1]: Dosya adi veya adlari
	 */

	srand(time(NULL));

	int rassalsayi = rand();

	/* Butun argumanlari gez. Her biri bir resim dosyasi adi */
	for (i = 2; i < argc; ++i) {

		/* TODO: PGM dosyasini oku */
		PGMInfo pgm_info = pgm_read(argv[i]);

		/* Hata olduysa ekrana hata mesajini yazdir */
		if (pgm_info == NULL) {
			pgm_print_error(pgm_info);
		}

		/* Hata yoksa resmin baslik bilgisini ekrana yazdir,
		 * resme efekt uygula ve yeni dosyaya kaydet. */
		else {
			/* Yeni bir string olustur. Bu string efekt uygulanmis
			 * dosyanin adini tutacaktir. */
			char new_filename[64];
			sprintf(new_filename, "%s.%s", argv[i], effect_name);

			/* PGM basligini ekrana yazdir. */
			pgm_print_header(pgm_info);

			if (strcmp(effect_name, "invert") == 0) {
				effect_invert(pgm_info.pixels, pgm_info.width, pgm_info.height);
			} else if (strcmp(effect_name, "binarize") == 0) {
				effect_threshold(pgm_info.pixels, pgm_info.width, pgm_info.height, 150);
			} else if (strcmp(effect_name, "noise") == 0) {
				effect_random_noise(pgm_info.pixels, pgm_info.width, pgm_info.height);
			} else if (strcmp(effect_name, "smooth") == 0) {
				effect_smooth(pgm_info.pixels, pgm_info.width, pgm_info.height);
			}

			/* TODO: Yeni PGM dosyasini olusturun. Eger basarisiz olursa
			 * ekrana yazdirin. */
			pgm_write(new_filename, pgm_info);
			if (new_filename == NULL) {
				fprintf(stderr, "Error while writing %s.\n", new_filename);
			}

			/* TODO: pgm_info'daki pixels dizisini free() etmeliyiz. */
		}
	}
	return 0;
}
Example #5
0
int
qcam_main( int argc, char ** argv )
{
    struct qcam_softc *qs = NULL;
    u_int options = 0;
    int scan_size = QC_S80x60;
    char *infile = "/dev/stdin";
    char *outfile = "/dev/stdout";
    FILE *infilef  = NULL;
    FILE *outfilef = NULL;
    int ch, sizemult=0;
    int pixel_threshold=0, frame_threshold=0;
    int sleeptime = 0;

    progname = argv[0];

    signal( SIGBUS, sigbus_handler );

    if (argc == 1)
        usage();

    while ((ch = getopt(argc, argv, "qm:os:pM:d:twx123z:")) != -1)
        switch (ch) {
        case 'q':
            SET(CAMERA_IN);
            break;
        case 'm':
            SET(MOVIE_IN);
            infile = optarg;
            break;
        case 'o':
            SET(ONE_IN);
            break;
        case 'p':
            SET(PREVIEW_ONE);
            break;
        case 'M':
            SET(MOVIE_OUT);
            outfile = optarg;
            break;
        case 't':
            SET(TTY_OUT);
            break;
        case 'w':
            SET(TTY_OUT);
            SET(TTY_WEB_OUT);
            break;
        case 'x':
            SET(XWIN_OUT);
            break;
        case 's':
            sleeptime = atoi(optarg);
            break;
        case 'd':
        {
            int d = atoi(optarg);
            if (d == 1)
                SET(CAM_DEBUG1);
            else if (d == 2)
                SET(CAM_DEBUG2);
            else if (d != 0)
                usage();
            break;
        }
        case '1':
            if (!sizemult)
                sizemult=1;
            scan_size = QC_S80x60;
            break;
        case '2':
            if (sizemult)
                sizemult=2;
            else {
                sizemult=1;
                scan_size = QC_S160x120;
            }
            break;
        case '3':
            if (sizemult)
                sizemult=3;
            else {
                sizemult=1;
                scan_size = QC_S320x240;
            }
            break;
        case 'z':
            pixel_threshold = atoi(optarg);
            frame_threshold = atoi(argv[optind]);
            optind++;
            SET(MOTION_DET);
            break;
        default:
            usage();
        }
    argc -= optind;
    argv += optind;

    if (ISSET(MOTION_DET))
    {
        motion_detect(options, ISSET(MOVIE_OUT) ? outfile : NULL,
                      pixel_threshold, frame_threshold);
        return 0;
    }

    if (!(ISSET(CAMERA_IN) || ISSET(MOVIE_IN)))
        errx(1, "need input device");

    if (!(ISSET(MOVIE_OUT) || ISSET(TTY_OUT) || ISSET(XWIN_OUT)))
        errx(1, "need output device");

    if (ISSET(MOVIE_IN) && ISSET(MOVIE_OUT))
        errx(1, "file input and file output are mutually exclusive");

    if (ISSET(PREVIEW_ONE) && 
        !(ISSET(TTY_OUT) || ISSET(XWIN_OUT)))
        errx(1, "need tty_out or xwin_out for preview");

    if (ISSET(PREVIEW_ONE) && !(ISSET(MOVIE_OUT)))
        errx(1, "need a file name to output snapshot to");
        
    if (ISSET(CAMERA_IN))
    {
        qs = qcam_open(QCAM);
        if (!qs)
            errx(1, "cannot access quickcam");
        qcam_setsize(qs, scan_size);
        if (ISSET(CAM_DEBUG1))
            qcam_debug = 1;
        if (ISSET(CAM_DEBUG2))
            qcam_debug = 2;
    }

    setuid(getuid());

    if (ISSET(MOVIE_IN))
    {
        int l = strlen(infile);
        qs = qcam_new();
        if (strcmp(infile, "-") == 0)
            infilef = stdin;
        else if ((l > 3 && strcmp(infile+l-3, ".gz")  == 0) ||
                 (l > 4 && strcmp(infile+l-4, ".bz2") == 0))
        {
            int fd, pid, pipefds[2];
            pipe(pipefds);
            fd = open(infile, O_RDONLY);
            if (fd < 0)
                goto error_opening;
            pid = fork();
            if (pid > 0)
            {
                /* in parent */
                close(fd);
                close(pipefds[1]);
                infilef = fdopen(pipefds[0], "r");
            }
            if (pid == 0)
            {
                /* in child */
                close(pipefds[0]);
                if (pipefds[1] != 1)
                {
                    dup2(pipefds[1], 1);
                    close(pipefds[1]);
                }
                if (fd != 0)
                {
                    dup2(fd, 0);
                    close(fd);
                }
                if (strcmp(infile+l-3, ".gz")  == 0)
                    execl("/usr/bin/gzip", "gzip", "-dc", NULL);
                else
                    execl("/usr/bin/bzip2", "bzip2", "-dc", NULL);
                close(0);
                close(1);
                errx(1, "cannot exec");
            }
            if (pid < 0)
            {
                /* busted */
                errx(1, "cannot fork");
            }
        }           
        else
            infilef = fopen(infile, "r");

        if (!infilef)
            error_opening:
        errx(1, "cannot open input file");
        pgm_readhdr(qs, infilef);
    }
 
    if (ISSET(MOVIE_OUT))
    {
        if (strcmp(outfile, "-") == 0)
            outfilef = stdout;
        else
            outfilef = fopen(outfile, "w");

        if (!outfilef)
            errx(1, "cannot open output file");
        pgm_writehdr(qs, outfilef);
    }

    if (ISSET(TTY_OUT))
        ttydisp_init(qs,ISSET(TTY_WEB_OUT));

    if (ISSET(XWIN_OUT) && !ISSET(PREVIEW_ONE))
    {
        if (!sizemult)
            sizemult=1;
        xwindisp_init(qs, sizemult);
    }

    if (ISSET(ONE_IN) && ISSET(PREVIEW_ONE))
    {
        qcam_setsize(qs, QC_S80x60);
        if (ISSET(XWIN_OUT))
            xwindisp_init(qs, 1);
        do {
            qcam_scan(qs);
            qcam_adjustpic(qs);
            if (ISSET(TTY_OUT))
                ttydisp(qs,ISSET(TTY_WEB_OUT));
            if (ISSET(XWIN_OUT))
                xwindisp(qs);
        } while (!keyinput());
        qcam_setsize(qs, scan_size);
        qcam_scan(qs);
        pgm_write(qs, outfilef);
    } else if (ISSET(ONE_IN) && !ISSET(MOVIE_IN))
    {
        qcam_setsize(qs, QC_S80x60);
        do {
            qcam_scan(qs);
        } while (qcam_adjustpic(qs));
        qcam_setsize(qs, scan_size);
        qcam_scan(qs);
        if (ISSET(MOVIE_OUT))
            pgm_write(qs, outfilef);
        if (ISSET(TTY_OUT))
            ttydisp(qs,ISSET(TTY_WEB_OUT));
    } else {
        int done = 0;
        if (ISSET(CAMERA_IN) && ISSET(MOVIE_OUT))
        {
            qcam_setsize(qs, QC_S80x60);
            do {
                qcam_scan(qs);
            } while (qcam_adjustpic(qs));
            qcam_setsize(qs, scan_size);
        }
        while (!done)
        {
            if ( sleeptime != 0 )
                usleep( sleeptime );
            if (ISSET(MOVIE_IN))
            {
                pgm_read(qs, infilef);
                if (feof(infilef))
                    done++;
            }
            if (ISSET(CAMERA_IN))
            {
                qcam_scan(qs);
                qcam_adjustpic(qs);
            }
            if (ISSET(MOVIE_OUT))
                pgm_write(qs, outfilef);
            if (ISSET(TTY_OUT))
            {
                ttydisp(qs,ISSET(TTY_WEB_OUT));
                if (ISSET(MOVIE_IN))
                    usleep(200000);
            }
            if (ISSET(XWIN_OUT))
            {
                xwindisp(qs);
                if (ISSET(MOVIE_IN))
                    usleep(200000);
            }
            if (ISSET(ONE_IN))
            {
                char dummy;
                done++;
                if (ISSET(MOVIE_IN))
                    read(0, &dummy, 1);
            }
            if (!ISSET(MOVIE_IN) && keyinput())
                done++;
        }
    }
    
    if (ISSET(MOVIE_IN))
        fclose(infilef);
    if (ISSET(MOVIE_OUT))
        fclose(outfilef);
    if (ISSET(XWIN_OUT))
        xwindisp_close();
    if (ISSET(CAMERA_IN))
        qcam_close(qs);

    return 0;
}