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