xvWidgets
VideoCapture.hpp
1 #pragma once
2 
3 #include <filesystem>
4 
5 #include "wx/wx.h"
6 #include <wx/panel.h>
7 #include <wx/filepicker.h>
8 #include <wx/propgrid/propgrid.h>
9 
10 #include <opencv2/core.hpp>
11 #include <opencv2/highgui.hpp>
12 #include <opencv2/imgproc.hpp>
13 
20 #include <map>
21 
22 namespace xv{
23 
24 class ImagePanel;
25 
30 class VideoCapture : public wxPanel
31 {
32 
33 public:
35  VideoCapture();
36 
38  VideoCapture(wxWindow * parent,
39  wxWindowID id = wxID_ANY,
40  const wxPoint &pos = wxDefaultPosition,
41  const wxSize &size = wxDefaultSize,
42  long style = wxTAB_TRAVERSAL,
43  const wxString &name = wxPanelNameStr
44  );
45 
47  VideoCapture(const std::string& filename);
48 
50  VideoCapture(int device);
51 
52 #pragma region cv::VideoCapture
53  bool open(const std::string& filename);
56  bool isOpened(){ return m_videoCapture.isOpened(); };
57 
59  void release(){ return m_videoCapture.release(); };
60 
62  bool grab(){ return m_videoCapture.grab(); }
63 
65  bool retrieve(cv::Mat& image, int channel = 0);
66 
68  bool read(cv::Mat& image){ return m_videoCapture.read(image); };
69 
71  double get(int propId){ return m_videoCapture.get(propId); };
72 
74  bool set(int propId, double value){ return m_videoCapture.set(propId, value); };
75 
77  void VideoCapture::operator>>(cv::Mat& mat){ m_videoCapture >> mat; };
78 
80  friend void operator>>(VideoCapture&, ImagePanel&);
81 
82 #pragma endregion cv::VideoCapture
83 
84 private:
85  const static std::map <int, std::string> PROPERTY_MAP;
86  const std::map < int, wxPGProperty*> m_properties;
87  static const std::string CLASS_NAME;
88  cv::VideoCapture m_videoCapture;
89 
90 #pragma region layout
91  void init();
92  void initFilePicker(wxSizer*);
93  void initPropertyGrid(wxSizer*);
94  void initButtons(wxSizer*);
95 #pragma endregion layout
96 
97 #pragma region event handling
98  void evtFilePickerChanged(wxFileDirPickerEvent&);
99  void evtOK(wxCommandEvent&);
100  void evtCancel(wxCommandEvent&);
101 #pragma endregion event handling
102 
103  wxFilePickerCtrl* m_filePickerCtrl;
104  wxPropertyGrid* m_propertyGrid;
105  std::tr2::sys::path m_filename;
106  int m_device;
107  bool m_selfHosted;//created its own parent window or embbeded in another control
108 
109  void loadProperties();
110  void clearProperties();
111 };
112 
113 }
bool retrieve(cv::Mat &image, int channel=0)
Decodes and returns the grabbed video frame.
bool set(int propId, double value)
Sets a property in the VideoCapture.
Definition: VideoCapture.hpp:74
void release()
Closes video file or capturing device.
Definition: VideoCapture.hpp:59
bool isOpened()
Returns true if video capturing has been initialized already.
Definition: VideoCapture.hpp:56
friend void operator>>(VideoCapture &, ImagePanel &)
Retrieves a image frame from the opened media into an xv::Image.
bool read(cv::Mat &image)
Grabs, decodes and returns the next video frame.
Definition: VideoCapture.hpp:68
bool grab()
Grabs the next frame from video file or capturing device.
Definition: VideoCapture.hpp:62
Class used to display images and as container of widgets.
Definition: ImagePanel.hpp:32
VideoCapture()
Default constructor.
Definition: Angle.hpp:8
GUI component to capture video from files and devices.
Definition: VideoCapture.hpp:30
bool open(const std::string &filename)
Open video file or a capturing device for video capturing.