-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathInputProcessor.cpp
68 lines (56 loc) · 1.53 KB
/
InputProcessor.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//
// InputProvider.cpp
// opencv_fd_demo
//
// Created by Igor Gridchyn on 10/7/12.
// Copyright (c) 2012 Igor Gridchyn. All rights reserved.
//
#include "InputProcessor.h"
VideoStreamInputProcessor::VideoStreamInputProcessor(int deviceNumber)
{
capture_ = cvCaptureFromCAM( deviceNumber );
}
VideoStreamInputProcessor::VideoStreamInputProcessor(std::string videoFileName)
{
capture_ = cvCaptureFromAVI( videoFileName.c_str() );
}
cv::Ptr<Frame> VideoStreamInputProcessor::Process(cv::Ptr<Frame> frame)
{
if ( !cvGrabFrame(capture_) )
return NULL;
IplImage* nImage = cvRetrieveFrame(capture_);
if ( !nImage )
return NULL;
cv::Ptr<Frame> newFrame = new Frame(nImage);
return newFrame;
}
VideoStreamInputProcessor::~VideoStreamInputProcessor()
{
cvReleaseCapture( &capture_ );
}
PhotoFileListInputProcessor::PhotoFileListInputProcessor(std::string photoListFilePath)
{
photoListFile = fopen( photoListFilePath.c_str(), "rt" );
}
PhotoFileListInputProcessor::~PhotoFileListInputProcessor()
{
fclose(photoListFile);
}
cv::Ptr<Frame> PhotoFileListInputProcessor::Process(cv::Ptr<Frame> frame)
{
char buf[1000 + 1];
if ( fgets(buf, 1000, photoListFile) )
{
int len = (int)strlen(buf);
while( len > 0 && isspace(buf[len-1]) )
len--;
buf[len] = '\0';
IplImage* image = cvLoadImage( buf, 1 );
if ( image )
return new Frame(image);
else
return NULL;
}
else
return NULL;
}