forked from Vorago/iwb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapplication.cpp
More file actions
128 lines (109 loc) · 4.1 KB
/
application.cpp
File metadata and controls
128 lines (109 loc) · 4.1 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include "include/application.hpp"
#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <cstdio>
#include <stdio.h>
#include "include/capture.hpp"
#include "include/analysis.hpp"
#include "include/presentation.hpp"
#include "include/scroller.hpp"
#include "include/handler.hpp"
#include "include/camera.hpp"
#include "include/confirmation.hpp"
#include "include/imageFrame.hpp"
#include <QtGui/QApplication>
namespace iwb {
Application::Application(int argc, char **argv){
this->a = new QApplication(argc, argv);
}
Application::~Application() {
// TODO: make sure that order used doesn't lead to memory leaks
delete(cpt);
delete(scroller);
delete(hndl);
delete(prs);
delete (a);
}
int Application::initialize(int argc, char* argv[]) {
hndl = new Handler();
cpt = NULL;
if (!hndl->handleArguments(argc, argv, &cpt, 0, 0)) return -1;
prs = new Presentation();
Camera::getInstance()->calibrate(cpt, prs);
analysis = new Analysis(cpt);
imageFrame = new ImageFrame(cpt, prs, analysis);
// imageFrame->setImagePath("res/no.jpg");
imageFrame->saveFrame();
prs->addComponent(imageFrame);
scroller = new Scroller(prs, hndl, imageFrame);
scroller->reloadFileNames();
// Confirmation::create(prs, hndl);
return 0;
}
int Application::run() {
int i = 0;
int camWidth = Camera::getInstance()->getWidth();
int camHeight = Camera::getInstance()->getHeight();
IplImage *cf = cvCreateImage(cvSize(camWidth, camHeight), IPL_DEPTH_8U, 3);
IplImage *diff = cvCreateImage(cvSize(camWidth, camHeight), IPL_DEPTH_8U, 3);
IplImage *gs = NULL;
// cpt->saveFrame("bgcapt.jpg", cf);
// cvWaitKey(5000);
cf = cvQueryFrame(cpt->getCapture());
// cpt->saveFrame("bgcapt2.jpg", cf);
// const char* winFrame = "winFrame";
// cvNamedWindow(winFrame, CV_WINDOW_AUTOSIZE);
// cvNamedWindow("test", CV_WINDOW_AUTOSIZE);
cpt->getCapture();
// cvWaitKey(3000);
IplImage* previous = cvCloneImage(cvQueryFrame(cpt->getCapture()));
IplImage* current;
IplImage* movementDiff;
// int threshold = 1;
bool backgroundChanged = false;
while(true) {
current = cvCloneImage(cvQueryFrame(cpt->getCapture()));
if (i++ == 30) {
imageFrame->captureFrame(current);
}
movementDiff = analysis->getCornerDiff(previous, current);
// cvSaveImage("movementDiff.jpg", movementDiff);
// int c = 0;
// for (int x=0; x<movementDiff->width && !backgroundChanged; x++)
// for (int y=0; y<movementDiff->height && !backgroundChanged; y++) {
// int elem = CV_IMAGE_ELEM( movementDiff, uchar, y, x);
// if (elem) {
// printf(" %d ", elem);
// c++;
//
// }
// }
// if (c < threshold) {
// analysis->refreshBackground();
// backgroundChanged = true;
// printf("#### CHANGING BACKGROUND #####\n");
// }
imageFrame->update();
cf = cvQueryFrame(cpt->getCapture());
gs = analysis->getDiff();
cvCvtColor(gs, diff, CV_GRAY2RGB);
// cvShowImage(winFrame, diffs);
// prs->drawDiff(diff);
// prs->putImage(cvPoint(0,0), cvPoint(prs->getScreenWidth(), prs->getScreenHeight()), NULL, NULL, analysis->bg);
prs->drawComponents();
// TODO: somehow get this gs from somewhere
hndl->detectTouchedComponents(gs);
cvReleaseImage(&gs);
cvWaitKey(5);
cvReleaseImage(&previous);
previous = current;
backgroundChanged = false;
}
cvReleaseImage(&previous);
cvReleaseImage(¤t);
cvReleaseImage(&movementDiff);
// delete(scroller);
delete(analysis);
return 0;
}
}