source: level2/competencies/MotionDirectionDetection/src/CaptureFrame.cpp @ 322

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