예제 #1
0
파일: extract.c 프로젝트: TristramN/libAFIS
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;
}
예제 #2
0
파일: borders.c 프로젝트: Dave2084/freewpc
void
gen_ball_border (void)
{
	PGM *pgm[3];
	int i, x, y;
	PGM *main;
	int next_ball = 0;

#define next ({ next_ball = (next_ball+1) % 3; pgm[next_ball]; })

	for (i=0; i < 3; i++)
	{
		unsigned int color = i+1;
		pgm[i] = pgm_alloc ();
		pgm_set_plane_count (pgm[i], 2);
		pgm_resize (pgm[i], 4, 4);
		pgm_draw_pixel (pgm[i], 1, 0, color);
		pgm_draw_pixel (pgm[i], 0, 1, color);
		pgm_draw_pixel (pgm[i], 1, 1, color);
		pgm_draw_pixel (pgm[i], 2, 1, color);
		pgm_draw_pixel (pgm[i], 1, 2, color);
	}

	main = pgm_alloc ();
	pgm_set_plane_count (main, 2);

	for (x=0; x < 128; x += 8)
		pgm_paste (main, next, x, 0);
	for (x=128-4; x >= 0; x -= 8)
		pgm_paste (main, next, x, 31-4);

	pgm_write (main, "images/ballborder.pgm");
	pgm_write_xbmset (main, "images/ballborder.xbm", "ballborder");
	pgm_free (main);
}
예제 #3
0
파일: borders.c 프로젝트: Dave2084/freewpc
/* Generate the multi-color border */
void
gen_mborder (void)
{
	PGM *pgm;
	XBMSET *xbmset;
	FILE *fp;

	pgm = pgm_alloc ();
	pgm_set_plane_count (pgm, 2);
	pgm_draw_border (pgm, 3, PGM_DARK(pgm));
	pgm_draw_border (pgm, 2, PGM_BRIGHT(pgm));
	pgm_draw_border (pgm, 1, PGM_WHITE(pgm));
	pgm_write (pgm, "images/mborder.pgm");
	pgm_write_xbmset (pgm, "images/mborder.xbm", "mborder");
	pgm_free (pgm);
}
예제 #4
0
void pgm_writef(float *src, int rows, int cols, char *filename) {
  int i;
  float min, max;
  unsigned char *vis = malloc(sizeof(unsigned char) * rows * cols);

  min = 1e+7;
  max = -1e+7;
  for(i=0;i<rows*cols;i++) {
    min = src[i] < min ? src[i] : min;
    max = src[i] > max ? src[i] : max;
  }

  for(i=0;i<rows*cols;i++) {
    vis[i] = (unsigned char)( 255 * (src[i] - min) / (max - min));
  }

  pgm_write(vis, rows, cols, 255, filename);

  free(vis);

  return;
}
예제 #5
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;
}
예제 #6
0
파일: sup2pgm.c 프로젝트: ksa242/sup2pgm
int save_sup_image(FILE* srt_file,
                   size_t subtitle_num,
                   uint32_t start_time, uint32_t end_time, char* timecode_buf,
                   const char* img_base_filename, char* img_filename_buf,
                   const unsigned char* img, size_t img_width, size_t img_height) {
    int result = -1;
    FILE* img_file;

    if (img == NULL) {
        return result;
    }

    sprintf(img_filename_buf, "%s%05lu.pgm", img_base_filename, subtitle_num);
    if ((img_file = fopen(img_filename_buf, "wb")) == NULL) {
        perror("main(): fopen(PGM)");
        return result;
    }

    if (!pgm_write(img_file, img, img_width, img_height)) {
        result = 0;

        DEBUG("Saving image %lu.\n\n", subtitle_num);

        fprintf(srt_file, "%lu\n", subtitle_num + 1);

        srt_render_time(start_time, timecode_buf);
        fprintf(srt_file, "%s --> ", timecode_buf);
        srt_render_time(end_time, timecode_buf);
        fprintf(srt_file, "%s\n", timecode_buf);

        fprintf(srt_file, "%s\n", img_filename_buf);
        fprintf(srt_file, "\n");
    }

    fclose(img_file);
    return result;
}
예제 #7
0
파일: main.c 프로젝트: begum88/INF203-1
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;
}
예제 #8
0
파일: main.c 프로젝트: flipk/pfkutils
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;
}