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

📄 grab_gray_image.c

📁 DCAM1394相机Linux下的驱动源码
💻 C
字号:
/****************************************************************************       Title: grab one gray image using libdc1394**    $RCSfile: grab_gray_image.c,v $**   $Revision: 1.5 $$Name:  $**       $Date: 2004/01/20 04:12:27 $**   Copyright: LGPL $Author: ddennedy $** Description:****    Get one gray image using libdc1394 and store it as portable gray map**    (pgm). Based on 'samplegrab' from Chris Urmson ****-------------------------------------------------------------------------****  $Log: grab_gray_image.c,v $**  Revision 1.5  2004/01/20 04:12:27  ddennedy**  added dc1394_free_camera_nodes and applied to examples****  Revision 1.4  2003/09/02 23:42:36  ddennedy**  cleanup handle destroying in examples; fix dc1394_multiview to use handle per camera; new example****  Revision 1.3  2001/10/16 09:14:14  ronneber**  - added more meaningful error message, when no raw1394 handle could be get**  - does not exit anymore, when camera has no trigger****  Revision 1.2  2001/09/14 08:10:41  ronneber**  - some cosmetic changes****  Revision 1.1  2001/07/24 13:50:59  ronneber**  - simple test programs to demonstrate the use of libdc1394 (based**    on 'samplegrab' of Chris Urmson******************************************************************************/#include <stdio.h>#include <libraw1394/raw1394.h>#include <libdc1394/dc1394_control.h>#include <stdlib.h>#define IMAGE_FILE_NAME "Image.pgm"int main(int argc, char *argv[]) {  FILE* imagefile;  dc1394_cameracapture camera;  int numNodes;  int numCameras;  raw1394handle_t handle;  nodeid_t * camera_nodes;  dc1394_feature_set features;  /*-----------------------------------------------------------------------   *  Open ohci and asign handle to it   *-----------------------------------------------------------------------*/  handle = dc1394_create_handle(0);  if (handle==NULL)  {    fprintf( stderr, "Unable to aquire a raw1394 handle\n\n"             "Please check \n"	     "  - if the kernel modules `ieee1394',`raw1394' and `ohci1394' are loaded \n"	     "  - if you have read/write access to /dev/raw1394\n\n");    exit(1);  }    /*-----------------------------------------------------------------------   *  get the camera nodes and describe them as we find them   *-----------------------------------------------------------------------*/  numNodes = raw1394_get_nodecount(handle);  camera_nodes = dc1394_get_camera_nodes(handle,&numCameras,1);  fflush(stdout);  if (numCameras<1)  {    fprintf( stderr, "no cameras found :(\n");    dc1394_destroy_handle(handle);    exit(1);  }  printf("working with the first camera on the bus\n");    /*-----------------------------------------------------------------------   *  to prevent the iso-transfer bug from raw1394 system, check if   *  camera is highest node. For details see    *  http://linux1394.sourceforge.net/faq.html#DCbusmgmt   *  and   *  http://sourceforge.net/tracker/index.php?func=detail&aid=435107&group_id=8157&atid=108157   *-----------------------------------------------------------------------*/  if( camera_nodes[0] == numNodes-1)  {    fprintf( stderr, "\n"             "Sorry, your camera is the highest numbered node\n"             "of the bus, and has therefore become the root node.\n"             "The root node is responsible for maintaining \n"             "the timing of isochronous transactions on the IEEE \n"             "1394 bus.  However, if the root node is not cycle master \n"             "capable (it doesn't have to be), then isochronous \n"             "transactions will not work.  The host controller card is \n"             "cycle master capable, however, most cameras are not.\n"             "\n"             "The quick solution is to add the parameter \n"             "attempt_root=1 when loading the OHCI driver as a \n"             "module.  So please do (as root):\n"             "\n"             "   rmmod ohci1394\n"             "   insmod ohci1394 attempt_root=1\n"             "\n"             "for more information see the FAQ at \n"             "http://linux1394.sourceforge.net/faq.html#DCbusmgmt\n"             "\n");    dc1394_destroy_handle(handle);    dc1394_free_camera_nodes(camera_nodes);    exit( 1);  }    /*-----------------------------------------------------------------------   *  setup capture   *-----------------------------------------------------------------------*/  if (dc1394_setup_capture(handle,camera_nodes[0],                           0, /* channel */                            FORMAT_VGA_NONCOMPRESSED,                           MODE_640x480_MONO,                           SPEED_400,                           FRAMERATE_7_5,                           &camera)!=DC1394_SUCCESS)   {    fprintf( stderr,"unable to setup camera-\n"             "check line %d of %s to make sure\n"             "that the video mode,framerate and format are\n"             "supported by your camera\n",             __LINE__,__FILE__);    dc1394_release_camera(handle,&camera);    dc1394_destroy_handle(handle);    dc1394_free_camera_nodes(camera_nodes);    exit(1);  }  dc1394_free_camera_nodes(camera_nodes);    /* set trigger mode */  if( dc1394_set_trigger_mode(handle, camera.node, TRIGGER_MODE_0)      != DC1394_SUCCESS)  {    fprintf( stderr, "unable to set camera trigger mode\n");#if 0    dc1394_release_camera(handle,&camera);    dc1394_destroy_handle(handle);    exit(1);#endif  }      /*-----------------------------------------------------------------------   *  report camera's features   *-----------------------------------------------------------------------*/  if(dc1394_get_camera_feature_set(handle, camera.node,&features)     !=DC1394_SUCCESS)   {    fprintf( stderr, "unable to get feature set\n");  }  else  {    dc1394_print_feature_set(&features);  }      /*-----------------------------------------------------------------------   *  have the camera start sending us data   *-----------------------------------------------------------------------*/  if (dc1394_start_iso_transmission(handle,camera.node)      !=DC1394_SUCCESS)   {    fprintf( stderr, "unable to start camera iso transmission\n");    dc1394_release_camera(handle,&camera);    dc1394_destroy_handle(handle);    exit(1);  }  /*-----------------------------------------------------------------------   *  capture one frame   *-----------------------------------------------------------------------*/  if (dc1394_single_capture(handle,&camera)!=DC1394_SUCCESS)   {    fprintf( stderr, "unable to capture a frame\n");    dc1394_release_camera(handle,&camera);    dc1394_destroy_handle(handle);    exit(1);  }  /*-----------------------------------------------------------------------   *  Stop data transmission   *-----------------------------------------------------------------------*/  if (dc1394_stop_iso_transmission(handle,camera.node)!=DC1394_SUCCESS)   {    printf("couldn't stop the camera?\n");  }  /*-----------------------------------------------------------------------   *  save image as 'Image.pgm'   *-----------------------------------------------------------------------*/  imagefile=fopen(IMAGE_FILE_NAME, "w");  if( imagefile == NULL)  {    perror( "Can't create '" IMAGE_FILE_NAME "'");    dc1394_release_camera(handle,&camera);    dc1394_destroy_handle(handle);    exit( 1);  }        fprintf(imagefile,"P5\n%u %u 255\n", camera.frame_width,          camera.frame_height );  fwrite((const char *)camera.capture_buffer, 1,         camera.frame_height*camera.frame_width, imagefile);  fclose(imagefile);  printf("wrote: " IMAGE_FILE_NAME "\n");  /*-----------------------------------------------------------------------   *  Close camera   *-----------------------------------------------------------------------*/  dc1394_release_camera(handle,&camera);  dc1394_destroy_handle(handle);  return 0;}

⌨️ 快捷键说明

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