Panda3D
webcamVideoOpenCV.cxx
1 // Filename: webcamVideoOpenCV.cxx
2 // Created by: drose (20Oct10)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "webcamVideoOpenCV.h"
16 
17 #ifdef HAVE_OPENCV
18 
19 #include "webcamVideoCursorOpenCV.h"
20 #include "configVariableInt.h"
21 
22 TypeHandle WebcamVideoOpenCV::_type_handle;
23 
24 ////////////////////////////////////////////////////////////////////
25 // Function: find_all_webcams_opencv
26 // Access: Public, Static
27 // Description: Finds all OpenCV webcams and adds them to the global
28 // list _all_webcams.
29 ////////////////////////////////////////////////////////////////////
30 void
31 find_all_webcams_opencv() {
32  // OpenCV doesn't really provide a way to enumerate cameras. We ask
33  // the user to do this via a config variable.
34  static ConfigVariableInt wemcam_opencv_camera_index
35  ("webcam-opencv-camera-index", "0",
36  PRC_DESC("Specify the space-separated list of integer camera index "
37  "numbers that are assumed to be available via OpenCV to the "
38  "WebcamVideo interface. The default camera index is 0. "
39  "Specify empty string if there are no available cameras."));
40  for (int i = 0; i < wemcam_opencv_camera_index.get_num_words(); ++i) {
41  PT(WebcamVideo) wc = new WebcamVideoOpenCV(wemcam_opencv_camera_index[i]);
42  WebcamVideoOpenCV::_all_webcams.push_back(wc);
43  }
44 }
45 
46 ////////////////////////////////////////////////////////////////////
47 // Function: WebcamVideoOpenCV::Constructor
48 // Access: Published, Virtual
49 // Description:
50 ////////////////////////////////////////////////////////////////////
51 WebcamVideoOpenCV::
52 WebcamVideoOpenCV(int camera_index) :
53  _camera_index(camera_index)
54 {
55  ostringstream strm;
56  strm << "OpenCV webcam " << _camera_index;
57  set_name(strm.str());
58 }
59 
60 ////////////////////////////////////////////////////////////////////
61 // Function: WebcamVideoOpenCV::open
62 // Access: Published, Virtual
63 // Description: Open this video, returning a MovieVideoCursor.
64 ////////////////////////////////////////////////////////////////////
65 PT(MovieVideoCursor) WebcamVideoOpenCV::
66 open() {
67  return new WebcamVideoCursorOpenCV(this);
68 }
69 
70 #endif
Allows you to open a webcam or other video capture device as a video stream.
Definition: webcamVideo.h:25
A MovieVideo is actually any source that provides a sequence of video frames.
This is a convenience class to specialize ConfigVariable as an integer type.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85