-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwindowcapturewidget.cpp
More file actions
131 lines (111 loc) · 3.54 KB
/
Copy pathwindowcapturewidget.cpp
File metadata and controls
131 lines (111 loc) · 3.54 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
129
130
131
/*-----------------------------------------------------------------------------
* This file is part of Gameroni -
* http://www.vitorian.com/x1/archives/419
* https://github.com/hftrader/gameroni
*
* Gameroni is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Gameroni is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Foobar. If not, see <http://www.gnu.org/licenses/>.
* -----------------------------------------------------------------------------*/
#include "windowcapturewidget.h"
#include <QPainter>
#include <QDebug>
#include <QMouseEvent>
#include <QBrush>
#include <QPen>
#include <QColor>
#include <QMessageBox>
#include <QInputDialog>
#include <QFileInfo>
#include <QMap>
#include <iostream>
#include "windowcapture.h"
#include "imageprocessorlaplacian.h"
#include "imageprocessormotion.h"
#include "win32utils.h"
WindowCaptureWidget::WindowCaptureWidget(QWidget *parent) : QWidget(parent)
{
counter = 0;
avg_time = 0;
_processor_list.push_back( std::shared_ptr<ImageProcessor>(new ImageProcessorLaplacian) );
_processor_list.push_back( std::shared_ptr<ImageProcessor>(new ImageProcessorMotion) );
_processor = _processor_list[0];
startTimer(1);
PrintDevices();
_video.open(0);
}
void WindowCaptureWidget::updateWindow( HWND hWnd )
{
_cap.endCapture();
_cap.startCapture( hWnd, true );
}
void WindowCaptureWidget::updateState( const QVariantMap& vmap )
{
if ( _processor )
_processor->updateState( vmap );
}
void WindowCaptureWidget::paintEvent(QPaintEvent *)
{
QPainter p(this);
QBrush brush;
QPen pen;
pen.setColor(Qt::red);
brush.setColor(qRgba(255,0,0,100));
brush.setStyle(Qt::Dense7Pattern);
p.setPen(pen);
p.setBrush(brush);
if ( !final_img.empty() ) {
QImage image((uchar*)final_img.data, final_img.cols, final_img.rows,
final_img.elemSize()==3 ? QImage::Format_RGB888 : QImage::Format_RGB32 );
p.drawImage(rect(),image,image.rect());
}
}
void WindowCaptureWidget::timerEvent(QTimerEvent *)
{
cv::Mat raw_img;
//_video >> raw_img;
//if ( _video.grab() )
//{
if ( _cap.captureFrame( raw_img ) )
{
// Process image
uint64_t t0 = __rdtsc();
if ( _processor )
_processor->process( raw_img, final_img, counter );
uint64_t elap = __rdtsc() - t0;
// Compute timing stats
const int num_loops = 100;
avg_time += elap;
if ( ++counter % num_loops == 0 ) {
std::cout << " Elapsed:" << avg_time/num_loops << std::endl;
avg_time = 0;
}
repaint();
}
}
void WindowCaptureWidget::setAlgorithm( int algo )
{
_processor = _processor_list[algo];
counter = 0;
avg_time = 0;
}
void WindowCaptureWidget::mousePressEvent(QMouseEvent * )
{
//qDebug() << e->x() << e->y();
}
void WindowCaptureWidget::mouseReleaseEvent(QMouseEvent *)
{
//qDebug() << x1 << y1;
}
void WindowCaptureWidget::mouseMoveEvent(QMouseEvent *)
{
}