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