source: level2/competencies/src/CaptureFrame.cpp @ 157

Revision 157, 2.8 KB checked in by ginevra, 10 years ago (diff)
Line 
1// AUTHOR: Ginevra Castellano
2// Queen Mary University of London
3// DATE: 10/2009
4// VERSION: 1.0
5
6// Copyright (C) 2009 Ginevra Castellano
7
8// This file is part of the FaceTracking program
9
10// FaceTracking is free software: you can redistribute it and/or modify
11// it under the terms of the GNU Lesser General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14
15// This program is distributed in the hope that it will be useful,
16// but WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18// GNU Lesser General Public License for more details.
19
20// You should have received a copy of the GNU Lesser General Public License
21// along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
23// FaceTracking uses the OpenCV library
24// Copyright (C) 2000-2006, Intel Corporation, all rights reserved.
25// Third party copyrights are property of their respective owners.
26// See OpenCV_license.txt, in the program folder, for details.
27
28// FaceTracking uses the Camshift wrapper program (see camshift_wrapper.cpp and camshift_wrapper.h)
29// (Copyright (c) 2007, Robin Hewitt (http://www.robin-hewitt.com)
30// See License.txt, in the Camshift wrapper folder, for details.
31
32
33
34#include "cv.h"
35#include "highgui.h"
36
37#include <stdio.h>
38
39#include "CaptureFrame.h"
40
41
42
43CaptureFrame::CaptureFrame()
44{
45    this->capture = NULL;
46        this->frame = NULL;   
47        this->frameCopy = NULL;
48}
49
50
51CaptureFrame::~CaptureFrame()
52{
53        cvReleaseCapture(&(this->capture));
54}
55
56
57void CaptureFrame::AllocateFrames(int width, int height, int channels)
58{
59        this->frameCopy = cvCreateImage(cvSize(width,height),
60                                            IPL_DEPTH_8U, channels);
61}
62
63
64void CaptureFrame::DeallocateFrames(void)
65{
66        cvReleaseImage(&(this->frameCopy));
67}
68
69
70int CaptureFrame::StartCapture(void)
71{
72        this->capture = cvCaptureFromCAM(0);
73       
74        // If capture is not loaded successfully
75        if(!this->capture)
76    {
77         printf("\nFatal error: capture not loaded successfully");
78         return 0;
79        }
80}
81
82
83bool CaptureFrame::CaptureNextFrame(void)
84//Capture the next frame into frameCopy
85//Return whether video is finished
86{
87    this->frame = cvQueryFrame(capture);
88
89        if (this->frame == NULL)
90        {
91                return true;    //finished
92        }
93
94        if (this->frameCopy == NULL)
95          this->AllocateFrames(this->frame->width,this->frame->height,this->frame->nChannels);
96
97        // If the origin of the image is top left, copy frame to frameCopy
98        if(this->frame->origin == IPL_ORIGIN_TL)
99          cvCopy(this->frame, this->frameCopy, 0);
100               
101        // Else flip and copy the image
102        else
103          cvFlip(this->frame, this->frameCopy, 0);
104
105        return false;
106}
107
108
109IplImage* CaptureFrame::getFrameCopy(void)
110
111{
112        return this->frameCopy;
113}
Note: See TracBrowser for help on using the repository browser.