Esempio n. 1
0
//return a captured image - from wait_and_read_devices
void ImgCap_V4L2::grabImageToFile() {
  /* 
     1. wait on both devices
     2. read the device that was ready first
     3. wait on the second device
     4. read the second device

  */
  fd_set fds;
  while(true) {
      struct timeval tv;
      int r;

    FD_ZERO(&fds);
//cn/im: adds a file descriptor to a file descriptor set
    FD_SET(r_fd, &fds);
 
    tv.tv_sec = 1;
    tv.tv_usec = 0;

    r = select(r_fd+1, &fds, NULL, NULL, &tv);
    //cn/im: select() is a socket function which monitors a list of file descriptors for readability,so here we have (point to array of file descriptors, number of file descriptors checked, don't check for writeable, no files are checked for exceptions thrown, and a timeout value)

    //these check to see if a camera is connected, if one isn't after one second it throws a connection timeout
  if (-1 == r) {
      if (EINTR == errno)
        continue;
      std::cerr << "select" << std::endl;
      //errno_exit ("select");
    }

    if (0 == r) {
      std::cerr<< "Master select timeout" << std::endl;
      exit (EXIT_FAILURE);
    }

    break;

  }  
    wait_for_device(&r_fd, "right");
    read_frame(&r_fd, &r_buf);
    save_frames();
}
Esempio n. 2
0
int ImgCap_V4L2::grabImageToPPM(const char * fileName) {
  /* 
     1. wait on device
     2. read the device 
  */

 
  fd_set fds;
  while(true) {
    struct timeval tv;
    int r;
    
    FD_ZERO(&fds);
    //cn/im: adds a file descriptor to a file descriptor set
    FD_SET(r_fd, &fds);
    
    tv.tv_sec = 1;
    tv.tv_usec = 0;
   
    //check for readability 
    r = select(r_fd+1, &fds, NULL, NULL, &tv);
    
    //these check to see if a camera is connected, if one isn't after one second it throws a connection timeout
    if (-1 == r) {
      if (EINTR == errno)
        continue;
      if(ImgCap_V4L2::verboseErrorPrinting) std::cerr  << "select" <<std::endl;
      return 1;
    }
    
    if (0 == r) {
      if(ImgCap_V4L2::verboseErrorPrinting) std::cerr  << "Master select timeout" << std::endl;
      return 2;
    }
    
    break;
    
  }  
  wait_for_device(&r_fd, "right");
  read_frame(&r_fd, &r_buf);
  save_frames(fileName);
  return 0;
}
Esempio n. 3
0
/**
 * Entry point of the application
 */
int main(int argc, char * argv[])
{
    int result = STATUS_NODEV;

    if (argc < 3)  {
        usage();
        return STATUS_BADARG;
    }

    FrmGrab_Init();
    
    if (!strcmp("x", argv[1])) {
        V2UDecompressParams dp;
        result = parse_decompress_params(&dp, argv+2, argc-2);
        if (result == STATUS_OK) {
            FILE* in = fopen(dp.fname, "rb");
            if (in) {
                result = decompress_frames(in, &dp);
                fclose(in);
            } else {
                printf("Failed to open file %s\n", dp.fname);
                result = STATUS_IOERR;
            }

        } else {
            usage();
            result = STATUS_BADARG;
        }
    } else {
        V2UCompressParams cp;
        result = parse_compress_params(&cp, argv+1, argc-1);
        if (result == STATUS_OK) {
            FrmGrabber *fg = FrmGrabLocal_Open();
            if (fg) {
                /* Check if hardware compression is supported */
                V2U_Property p;
                p.key = V2UKey_HardwareCompression;
                if (FrmGrab_GetProperty(fg, &p)) {
                    const char* pn = FrmGrab_GetProductName(fg);
                    if (pn) {
                        V2U_VideoMode vm;
                        printf("Found %s hardware\n", pn);

                        /* Set compression level */
                        if (cp.level >= 0) {
                            V2U_Property filter;
                            filter.key = V2UKey_NoiseFilter;
                            filter.value.int32 = cp.level; 
                            FrmGrab_SetProperty(fg, &filter);
                        }

                        /* Detect video mode */
                        if (FrmGrab_DetectVideoMode(fg,&vm) &&
                            vm.width && vm.height) {
                            FILE* out;
                            printf("Detected %dx%d %d.%d Hz\n",
                                vm.width,vm.height, (vm.vfreq+50)/1000,
                                ((vm.vfreq+50)%1000)/100);

                            /* Open the output file */
                            out = fopen(cp.fname, "wb");
                            if (out) {
                                printf("Writing %s\n", cp.fname);
                                result = save_frames(fg, out, &cp, &vm);
                                fclose(out);
                            } else {
                                printf("Failed to open file %s\n", cp.fname);
                                result = STATUS_IOERR;
                            }
                        } else {
                            printf("No signal detected\n");
                            result = STATUS_NOSIGNAL;
                        }
                    } else {
                        printf("%s doesn't support hardware compression\n", pn);
                    }
                } else {
                    printf("Please update the driver.\n");
                }

                FrmGrab_Close(fg);
            } else {
                printf("No VGA2USB frame grabber is found\r\n");
            }
        } else if (result == STATUS_BADARG) {
            usage();
        }
    }
    FrmGrab_Deinit();
    return result;
}