⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gqcam.c

📁 LINUX下非常有名的视频采集和显示源代码,直接安装后可以使用,效果很好
💻 C
📖 第 1 页 / 共 2 页
字号:
    if( camera->dump )      return;    if(camera->on_timer){      savefile_append_time(camera);      if(camera->timer_struct.beep)	gdk_beep();      switch (camera->savetype) {      case PPM:	ppm_save(camera);	break;           case JPEG:	jpeg_save(camera);		break;	      case PNG:	png_save(camera);	break;      }      if(camera->timer_struct.iscommand){	printf("Commanding...\n");	system(camera->timer_struct.command);      }    }    sem_post( &s_draw );  }}  void delete_event(GtkWidget *widget, struct Camera *camera){  FILE *preffile;  char savefile[255];  sprintf(savefile, "%s/.gqcamrc", getenv("HOME"));  preffile = fopen(savefile, "w");  save_pref_file(preffile, camera);  fclose(preffile);  gtk_main_quit ();}int next_frame(struct Camera *camera) {  int val;    sem_getvalue( &s_grab2, &val );  if( !val )     sem_post( &s_grab2 );  return 1;}int increment_second_counter(struct Camera *camera) {  static int x_seconds = 0;    x_seconds++;  // the following just prevents integer wrap  if( ( x_seconds % 512 ) == 0 ) {    x_seconds /= 2;    x_frames /= 2;  }  camera->fps_avg = x_frames / x_seconds;  camera->fps_current = y_frames;  y_frames = 0;  return;}int main(int argc, char *argv[]){  static struct Camera camera;  pthread_t grab_thread;  pthread_t draw_thread;  guint timeoutid;  int i, brightness=180, contrast=104, whiteness=155;  unsigned char buff[3];  char *filename = NULL, readfile[255];  int done = 0;  FILE *preffile;  init_cam(&camera);/*  g_thread_init(NULL);  gtk_init (&argc, &argv);  gdk_rgb_init();*/  sprintf(readfile, "%s/.gqcamrc", getenv("HOME"));  preffile = fopen(readfile, "r");  if(preffile != NULL){    read_pref_file(preffile, &camera);    fclose(preffile);  }    while( !done ) {    static struct option long_options[] =     {      { "help", no_argument, NULL, 'h' },      { "version", no_argument, NULL, 'V' },      { "swap", no_argument, NULL, 's' },      { "autobright", no_argument, NULL, 'a' },      { "video", required_argument, NULL, 'v' },      { "dump", required_argument, NULL, 'd' },      { "type", required_argument, NULL, 't' },      { "bright", required_argument, NULL, 'b' },      { "white", required_argument, NULL, 'w' },      { "contrast", required_argument, NULL, 'c' },      { "maxfps", required_argument, NULL, 'm' },      { "fullspeed", no_argument, NULL, 'F' },      { 0, 0, 0, 0 }    };    int c;    c = getopt_long( argc, argv, "FhVsav:d:b:w:c:m:t:", long_options, NULL );    switch ( c ) {    case 'h' :      print_usage();      exit(0);      break;    case 'V' :      printf( "gqcam version %s\n", version );      exit(0);      break;    case 's':      camera.swapcolors = 1;      break;    case 'a':      camera.autobright = 1;      break;    case 'v' :      sprintf(camera.devname, "%s", optarg );      break;    case 'd' :      camera.dump = 1;      if( strcmp( optarg, "-" ) != 0 ) /* leave alone if stdout */	filename = optarg;      break;    case 't' :      if(!strcmp(optarg, "PPM"))	camera.savetype = PPM;      else if(!strcmp(optarg, "PNG"))	camera.savetype = PNG;      else if(!strcmp(optarg, "JPEG"))	camera.savetype = JPEG;      break;    case 'b' :      brightness = atoi( optarg );      break;    case 'w' :      whiteness = atoi( optarg );      break;    case 'c' :      contrast = atoi( optarg );      break;    case 'm' :      if( atoi(optarg) > 0 ) /* Avoid weird values */	camera.timeout = 1000/atoi(optarg);      break;    case 'F' :      camera.speed_fastest = 1;      camera.timeout = 0;      break;    case '?' :      fprintf( stderr, "invalid option, or ambiguous argument\n" );      print_usage();      exit(1);      break;    case EOF :      done = 1;      break;    default :      print_usage();      exit(1);    };  }  camera.fps_avg = 0;  camera.fps_current = 0;  if( camera.dump ){       exit( dump_pict( &camera, filename, brightness, contrast, whiteness ) );  }  g_thread_init(NULL);  gtk_init (&argc, &argv);  gdk_rgb_init();  sem_init( &s_draw, 0, 0 );  sem_init( &s_grab1, 0, 1 );  sem_init( &s_grab2, 0, 1 );  open_cam(&camera);  get_cam_info(&camera);  //camera.vid_pic.brightness = brightness*256;  //camera.vid_pic.contrast = contrast*256;  //camera.vid_pic.whiteness = whiteness*256;  //set_cam_info(&camera);  create_frontend(&camera);  if( !camera.speed_fastest )    camera.timeoutid = gtk_timeout_add(camera.timeout, (GtkFunction)next_frame, (gpointer)&camera);  timeoutid = gtk_timeout_add(1000, (GtkFunction)increment_second_counter, (gpointer)&camera);    pthread_create(&grab_thread, NULL, (void *)&grab_image, (void*)&camera);  pthread_create(&draw_thread, NULL, (void *)&display, (void*)&camera);  gdk_threads_enter();  gtk_main();  gdk_threads_leave();  plsquit = 1; // ask our threads to quit  // update semiphores and mutexes so threads can run and finish  pthread_mutex_unlock( &camera.freeze_mutex );  sem_post( &s_draw );  sem_post( &s_grab1 );  sem_post( &s_grab2 );  // join the threads cleanly  pthread_join( grab_thread, NULL );  pthread_join( draw_thread, NULL );  pthread_mutex_unlock( &camera.freeze_mutex );  close_cam(&camera, 1);  exit(0);}void print_usage() {      fprintf(stderr, "gqcam - GTK QuickCam Control\n");      fprintf(stderr, "Copyright (C) 1999  Cory Lueninghoener <cluenin1@bigred.unl.edu>\n");      fprintf(stderr, "This software comes with ABSOLUTELY NO WARRANTY\n");      fprintf(stderr, "This software is free software, and you are welcome to redistribute it\n");      fprintf(stderr, "under certain conditions\n");      fprintf(stderr, "See the README file for a more complete notice.\n");      fprintf( stderr, "usage: gqcam [-hVFs] [-d file] [-c contrast] [-w whiteness] [-b brightness] [-m maxfps] [-d filename] [-t type]\n" );      fprintf(stderr, "\t-h --help\t\tdisplay this help screen\n");      fprintf(stderr, "\t-V --version\t\tdisplay version and exit\n");      fprintf(stderr, "\t-s --swap\t\tswap RGB into BGR (WARNING: this option will disappear in the future, turning into a filter instead)\n");      fprintf(stderr, "\t-a --autobright\tperform autobrightness\n");      fprintf(stderr, "\t-v --video <video dev>\tgrab frames from <video dev>\n");      fprintf(stderr, "\t-d --dump <filename>\tdump image to <filename> \n\t\t\t\t(or stdout if filename is \"-\")\n");      fprintf(stderr, "\t-t --type <type>\ttype of image to dump(default:PNG)\n\t\t\t\t(valid types: PPM PNG JPEG)\n");      fprintf(stderr, "\t-b --brightness <num>\tset brightness to <num>\n");      fprintf(stderr, "\t-w --whiteness <num>\tset white balance to <num>\n");      fprintf(stderr, "\t-c --contrast <num>\tset contrast to <num>\n");      fprintf(stderr, "\t-m --maxfps <num>\tset the maximum frames per second(default:%d)\n", 10 );      fprintf(stderr, "\t-F --fullspeed\t\tdisplay as many frames per second as you can\n" );}int dump_pict( struct Camera *camera, char *filename, int brightness, int contrast, int whiteness ){  FILE *outf = NULL;  if( filename != NULL ){    strcpy(camera->savefile, filename);    strcpy(camera->savefileclean, filename);  }  /*    outf = fopen( filename, "w" );    if( !outf ) {      fprintf( stderr, "Couldn't open %s for writing!\n" );      return 1;    }  }  else {    outf = stdout;  }*/  fprintf( stderr, "Dumping...\n" );  open_cam(camera);  get_cam_info(camera);  camera->vid_pic.brightness = brightness*256;  camera->vid_pic.contrast = contrast*256;  camera->vid_pic.whiteness = whiteness*256;  set_cam_info(camera);  sem_post( &s_grab1 );  sem_post( &s_grab2 );  grab_image(camera);  camera->pic = camera->picbuff;  close_cam(camera, 1);    gdk_threads_enter();  if(camera->savetype == JPEG){    camera->save_struct.smoothness = 0;    camera->save_struct.quality = 75;    camera->save_struct.optimize = 0;    jpeg_save(camera);  }  else if(camera->savetype == PNG){    camera->save_struct.interlace = PNG_INTERLACE_NONE;    camera->save_struct.compression = 6;    png_save(camera);  }  else if(camera->savetype == PPM){    camera->save_struct.format = RAW;    ppm_save(camera);  }  gdk_threads_leave();  return 0;}  

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -