ViSP
test1394TwoGrabber.cpp
1 
2 /****************************************************************************
3  *
4  * $Id: test1394TwoGrabber.cpp 4574 2014-01-09 08:48:51Z fspindle $
5  *
6  * This file is part of the ViSP software.
7  * Copyright (C) 2005 - 2014 by INRIA. All rights reserved.
8  *
9  * This software is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * ("GPL") version 2 as published by the Free Software Foundation.
12  * See the file LICENSE.txt at the root directory of this source
13  * distribution for additional information about the GNU GPL.
14  *
15  * For using ViSP with software that can not be combined with the GNU
16  * GPL, please contact INRIA about acquiring a ViSP Professional
17  * Edition License.
18  *
19  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
20  *
21  * This software was developed at:
22  * INRIA Rennes - Bretagne Atlantique
23  * Campus Universitaire de Beaulieu
24  * 35042 Rennes Cedex
25  * France
26  * http://www.irisa.fr/lagadic
27  *
28  * If you have questions regarding the use of this file, please contact
29  * INRIA at visp@inria.fr
30  *
31  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
32  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
33  *
34  *
35  * Description:
36  * Firewire cameras video capture.
37  *
38  * Authors:
39  * Fabien Spindler
40  *
41  *****************************************************************************/
42 
43 
52 #include <visp/vpConfig.h>
53 #include <visp/vpDebug.h>
54 
55 #include <iostream>
56 #include <string>
57 
58 #if defined(VISP_HAVE_DC1394_2)
59 
60 #include <visp/vp1394TwoGrabber.h>
61 #include <visp/vpImageIo.h>
62 #include <visp/vpIoTools.h>
69 int
70 main()
71 {
72  try {
73  std::cout << "IEEE1394 test in progress..." << std::endl;
74 
75  // Get the user name
76  std::string username;
77  vpIoTools::getUserName(username);
78  std::string outputpath = "/tmp/" + username;
79  vpIoTools::makeDirectory(outputpath);
80 
81  // Creation of an empty image container
83 
84  // Creation of a framegrabber
86  uint64_t guid;
87 
88  // Get the number of cameras connected on the bus
89  unsigned int ncameras; // Number of cameras on the bus
90  ncameras = g.getNumCameras();
91  for (unsigned int i=0; i < ncameras; i++) {
92  g.setCamera(i);
93  g.getGuid(guid);
94  std::cout << "Detected camera with GUID 0x"
95  << std::hex << guid << std::endl;
96  }
97  // If more than one camera connected, use the last one
98  if (ncameras > 1) {
99  g.setCamera(ncameras -1);
100  g.getGuid(guid);
101  std::cout << "Use camera with GUID 0x" << std::hex << guid << std::endl;
102  g.setCamera(0); // to be sure that the setCamera() in the next line with guid as parameter works
103  g.setCamera(guid);
104  }
105 
106  for (int i=0;i<10;i++) g.acquire(I);
107  g.close();
108  std::string filename = outputpath + "/imagetest1.pgm";
109  std::cout << "Write image: " << filename << std::endl;
110  vpImageIo::write(I, filename);
111 
112  std::cout << "New connection..."<< std::endl;
113  g.open(I);
114  g.close();
115 
116  std::cout << "New connection..."<< std::endl;
117  g.open(I);
118  //g.setVideoMode(vp1394TwoGrabber::vpVIDEO_MODE_800x600_YUV422);
119  g.acquire(I);
120  g.close();
121  filename = outputpath + "/imagetest2.pgm";
122  std::cout << "Write image: " << filename << std::endl;
123  vpImageIo::write(I, filename);
124  }
125  catch (...) {
126  vpCERROR << "Failure: exit" << std::endl;
127  }
128 }
129 #else
130 int
131 main()
132 {
133  vpTRACE("Ieee 1394 grabber capabilities are not available...\n"
134  "You should install libdc1394-2 to use this binary.") ;
135 }
136 
137 #endif
138 
139 /*
140  * Local variables:
141  * c-basic-offset: 2
142  * End:
143  */
static void write(const vpImage< unsigned char > &I, const char *filename)
Definition: vpImageIo.cpp:476
#define vpTRACE
Definition: vpDebug.h:418
#define vpCERROR
Definition: vpDebug.h:369
void getNumCameras(unsigned int &ncameras) const
void acquire(vpImage< unsigned char > &I)
static void makeDirectory(const char *dirname)
Definition: vpIoTools.cpp:384
void open(vpImage< unsigned char > &I)
void setCamera(uint64_t camera)
static std::string getUserName()
Definition: vpIoTools.cpp:141
Class for firewire ieee1394 video devices using libdc1394-2.x api.