]> git.defcon.no Git - qopencamwidget/blob - doc/html/view_8cpp-source.html
New filename. Cleaner, leaner
[qopencamwidget] / doc / html / view_8cpp-source.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 <html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
3 <title>QOpenCamWidget: view.cpp Source File</title>
4 <link href="doxygen.css" rel="stylesheet" type="text/css">
5 <link href="tabs.css" rel="stylesheet" type="text/css">
6 </head><body>
7 <!-- Generated by Doxygen 1.5.6 -->
8 <div class="navigation" id="top">
9 <div class="tabs">
10 <ul>
11 <li><a href="main.html"><span>Main&nbsp;Page</span></a></li>
12 <li><a href="annotated.html"><span>Classes</span></a></li>
13 <li class="current"><a href="files.html"><span>Files</span></a></li>
14 </ul>
15 </div>
16 <h1>view.cpp</h1><a href="view_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
17 <a name="l00002"></a>00002 <span class="comment"> QOpenCamWidget demo application main window (view.c)</span>
18 <a name="l00003"></a>00003 <span class="comment"> This file is part of a demonstration application, illustrating</span>
19 <a name="l00004"></a>00004 <span class="comment"> how to use the QOpenCamWidget, a Qt 4 widget that displays</span>
20 <a name="l00005"></a>00005 <span class="comment"> video input from a webcam, along with a snapshot button.</span>
21 <a name="l00006"></a>00006 <span class="comment"></span>
22 <a name="l00007"></a>00007 <span class="comment"> Copyright (C) 2009 Jon Langseth</span>
23 <a name="l00008"></a>00008 <span class="comment"></span>
24 <a name="l00009"></a>00009 <span class="comment"> This program is free software; you can redistribute it and/or</span>
25 <a name="l00010"></a>00010 <span class="comment"> modify it under the terms of the GNU General Public License</span>
26 <a name="l00011"></a>00011 <span class="comment"> as published by the Free Software Foundation in its version 2</span>
27 <a name="l00012"></a>00012 <span class="comment"> of the License.</span>
28 <a name="l00013"></a>00013 <span class="comment"></span>
29 <a name="l00014"></a>00014 <span class="comment"> This program is distributed in the hope that it will be useful,</span>
30 <a name="l00015"></a>00015 <span class="comment"> but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
31 <a name="l00016"></a>00016 <span class="comment"> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
32 <a name="l00017"></a>00017 <span class="comment"> GNU General Public License for more details.</span>
33 <a name="l00018"></a>00018 <span class="comment"></span>
34 <a name="l00019"></a>00019 <span class="comment"> You should have received a copy of the GNU General Public License</span>
35 <a name="l00020"></a>00020 <span class="comment"> along with this program; if not, write to the Free Software</span>
36 <a name="l00021"></a>00021 <span class="comment"> Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.</span>
37 <a name="l00022"></a>00022 <span class="comment"> */</span>
38 <a name="l00023"></a>00023
39 <a name="l00024"></a>00024 <span class="preprocessor">#include "<a class="code" href="view_8h.html">view.h</a>"</span>
40 <a name="l00025"></a>00025 <span class="preprocessor">#include "<a class="code" href="qopencamwidget_8h.html">qopencamwidget.h</a>"</span>
41 <a name="l00026"></a>00026
42 <a name="l00027"></a>00027 <span class="comment">// The View class is a QMainWindow, used to display our QOpenCamWidget</span>
43 <a name="l00028"></a>00028 <span class="comment">// The constructor of the View takes care of setting up the Widget,</span>
44 <a name="l00029"></a>00029 <span class="comment">// and handles the result of a user clicking (or activating) the widget's</span>
45 <a name="l00030"></a>00030 <span class="comment">// "Take snapshot" button.</span>
46 <a name="l00031"></a>00031
47 <a name="l00032"></a><a class="code" href="classView.html#74d64dd513eae96bc3196131f865a4e8">00032</a> <a class="code" href="classView.html#74d64dd513eae96bc3196131f865a4e8">View::View</a>( QWidget *parent)
48 <a name="l00033"></a>00033 : QMainWindow(parent)
49 <a name="l00034"></a>00034 {
50 <a name="l00035"></a>00035
51 <a name="l00036"></a>00036 <span class="comment">// Create the widget, setting the Main window (this) as its parent.</span>
52 <a name="l00037"></a>00037 <a class="code" href="classQOpenCamWidget.html">QOpenCamWidget</a> *cw = <span class="keyword">new</span> <a class="code" href="classQOpenCamWidget.html">QOpenCamWidget</a>(<span class="keyword">this</span>);
53 <a name="l00038"></a>00038
54 <a name="l00039"></a>00039 <span class="comment">// bool QOpenCamWidget::grabCapture(int source) tries to get a</span>
55 <a name="l00040"></a>00040 <span class="comment">// video capture handle from OpenCV, using the source number</span>
56 <a name="l00041"></a>00041 <span class="comment">// as the device to open. Here I use -1 as the number, meaning</span>
57 <a name="l00042"></a>00042 <span class="comment">// "give me any supported and available video devica you can find".</span>
58 <a name="l00043"></a>00043 <span class="keywordflow">if</span> ( cw-&gt;<a class="code" href="classQOpenCamWidget.html#23574314cbd7a74bc6f32a640041d55a" title="Grabs an OpenCV video capture source.">grabCapture</a>(-1) )
59 <a name="l00044"></a>00044 {
60 <a name="l00045"></a>00045 <span class="comment">// grabCapture() returns true on success. This means that</span>
61 <a name="l00046"></a>00046 <span class="comment">// we have a capture device available, and can start streaming</span>
62 <a name="l00047"></a>00047 <span class="comment">// video from the device to display on the widget.</span>
63 <a name="l00048"></a>00048
64 <a name="l00049"></a>00049 <span class="comment">// TODO: Document this feature..</span>
65 <a name="l00050"></a>00050 cw-&gt;<a class="code" href="classQOpenCamWidget.html#8f885a8bb88870cd19cfc9eb4e02e2ce" title="Changes the visibility of the optional built-in &amp;quot;Take snapshot&amp;quot; button...">setSnapshotVisible</a>(<span class="keyword">true</span>);
66 <a name="l00051"></a>00051
67 <a name="l00052"></a>00052 <span class="comment">// Video output does not start until QOpenCamWidget::startCapture()</span>
68 <a name="l00053"></a>00053 <span class="comment">// is explicitly called.</span>
69 <a name="l00054"></a>00054 cw-&gt;<a class="code" href="classQOpenCamWidget.html#b378daa447e8d9b94e1c7c8c6853b880" title="Starts up grabbing of video frames.">startCapture</a>();
70 <a name="l00055"></a>00055 }
71 <a name="l00056"></a>00056
72 <a name="l00057"></a>00057 <span class="comment">// The QOpenCamWidget does not provide a video stream for further</span>
73 <a name="l00058"></a>00058 <span class="comment">// processing, but it does provide a snapshot of the stream if</span>
74 <a name="l00059"></a>00059 <span class="comment">// the SLOT void QOpenCamWidget::startSnap(void) is triggered.</span>
75 <a name="l00060"></a>00060 <span class="comment">// In this demo app, the slot is connected to the widgets</span>
76 <a name="l00061"></a>00061 <span class="comment">// internal "Take snapshot" trigger button, but the SLOT is</span>
77 <a name="l00062"></a>00062 <span class="comment">// public, and may easily be triggered from "outside".</span>
78 <a name="l00063"></a>00063 <span class="comment">//</span>
79 <a name="l00064"></a>00064 <span class="comment">// When startSnap() is triggered, it will use a SIGNAL to return</span>
80 <a name="l00065"></a>00065 <span class="comment">// its image, if the aquisition was successful. The image</span>
81 <a name="l00066"></a>00066 <span class="comment">// will be available through QOpenCamWidget::imageReady(Qimage);</span>
82 <a name="l00067"></a>00067 <span class="comment">// In this sample, I hook that signal up to a slot on this QMainWindow,</span>
83 <a name="l00068"></a>00068 <span class="comment">// that saves the image, and exits the application.</span>
84 <a name="l00069"></a>00069 connect( cw, SIGNAL(imageReady(QImage)), <span class="keyword">this</span>, SLOT(<a class="code" href="classView.html#4b82b2654c9dd798bce121f02b30a810">saveImage</a>(QImage)));
85 <a name="l00070"></a>00070
86 <a name="l00071"></a>00071 this-&gt;setCentralWidget(cw);
87 <a name="l00072"></a>00072 }
88 <a name="l00073"></a>00073
89 <a name="l00074"></a><a class="code" href="classView.html#450dfab3f21a52edc03db4310593412f">00074</a> <a class="code" href="classView.html#450dfab3f21a52edc03db4310593412f">View::~View</a>(<span class="keywordtype">void</span>)
90 <a name="l00075"></a>00075 {
91 <a name="l00076"></a>00076 }
92 <a name="l00077"></a>00077
93 <a name="l00078"></a><a class="code" href="classView.html#4b82b2654c9dd798bce121f02b30a810">00078</a> <span class="keywordtype">void</span> <a class="code" href="classView.html#4b82b2654c9dd798bce121f02b30a810">View::saveImage</a>(QImage image)
94 <a name="l00079"></a>00079 {
95 <a name="l00080"></a>00080 <span class="comment">// This is the SLOT that recieves QOpenCamWidget::imageReady(QImage) SIGNAL.</span>
96 <a name="l00081"></a>00081 <span class="comment">// To keep the example as simple as possible, I do as little as possible..</span>
97 <a name="l00082"></a>00082 qDebug() &lt;&lt; <span class="stringliteral">"Recieved an image of size "</span>
98 <a name="l00083"></a>00083 &lt;&lt; image.width() &lt;&lt; <span class="stringliteral">"x"</span> &lt;&lt; image.height();
99 <a name="l00084"></a>00084 image.save(<span class="stringliteral">"snapshot.png"</span>);
100 <a name="l00085"></a>00085
101 <a name="l00086"></a>00086 QApplication::exit();
102 <a name="l00087"></a>00087 }
103 </pre></div></div>
104 <hr size="1"><address style="text-align: right;"><small>Generated on Thu Jun 11 01:49:57 2009 for QOpenCamWidget by&nbsp;
105 <a href="http://www.doxygen.org/index.html">
106 <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.6 </small></address>
107 </body>
108 </html>