Skip to content

Commit 395ffc6

Browse files
author
Raphaël Droz
committed
input: added desktop screen as a possible image source (Qt Qscreen based)
1 parent e627d40 commit 395ffc6

5 files changed

Lines changed: 159 additions & 1 deletion

File tree

IPL/IPL.pro

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
#
1818
##############################################################################
1919

20-
CONFIG -= qt
20+
# CONFIG -= qt
21+
QT += core gui
2122

2223
TARGET = IPL
2324
CONFIG(debug, debug|release): DESTDIR = ../ImagePlay/debug

IPL/include/IPL_processes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
//#include "IPLLoadVideo.h"
2828
#include "IPLCamera.h"
2929
#include "IPLLoadImageSequence.h"
30+
#include "IPLScreenshot.h"
3031
#include "IPLSynthesize.h"
3132
#include "IPLSaveImage.h"
3233
#include "IPLBinarize.h"
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//#############################################################################
2+
//
3+
// This file is part of ImagePlay.
4+
//
5+
// ImagePlay is free software: you can redistribute it and/or modify
6+
// it under the terms of the GNU General Public License as published by
7+
// the Free Software Foundation, either version 3 of the License, or
8+
// (at your option) any later version.
9+
//
10+
// ImagePlay is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU General Public License
16+
// along with ImagePlay. If not, see <http://www.gnu.org/licenses/>.
17+
//
18+
//#############################################################################
19+
20+
#ifndef IPLSCREENSHOT_H
21+
#define IPLSCREENSHOT_H
22+
23+
#include <string>
24+
#include <QGuiApplication>
25+
#include <QScreen>
26+
#include <QPixmap>
27+
#include <QImage>
28+
29+
#include "IPL_global.h"
30+
#include "IPLProcess.h"
31+
32+
#include "opencv2/core/core.hpp"
33+
#include "opencv2/imgproc/imgproc.hpp"
34+
#include "opencv2/highgui/highgui.hpp"
35+
36+
/**
37+
* @brief The IPLScreenshot class
38+
*/
39+
class IPLSHARED_EXPORT IPLScreenshot : public IPLClonableProcess<IPLScreenshot>
40+
{
41+
public:
42+
IPLScreenshot() : IPLClonableProcess() { init(); }
43+
~IPLScreenshot() { destroy(); }
44+
45+
void init();
46+
void destroy();
47+
virtual bool processInputData (IPLData* data, int inNr, bool useOpenCV);
48+
virtual IPLImage* getResultData (int outNr);
49+
virtual void afterProcessing ();
50+
51+
protected:
52+
IPLImage* _result;
53+
bool _continuous;
54+
55+
int _winId;
56+
QPixmap _pixmap;
57+
QImage _qimage;
58+
cv::Mat _mat;
59+
};
60+
61+
#endif // IPLSCREENSHOT_H
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
//#############################################################################
2+
//
3+
// This file is part of ImagePlay.
4+
//
5+
// ImagePlay is free software: you can redistribute it and/or modify
6+
// it under the terms of the GNU General Public License as published by
7+
// the Free Software Foundation, either version 3 of the License, or
8+
// (at your option) any later version.
9+
//
10+
// ImagePlay is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU General Public License
16+
// along with ImagePlay. If not, see <http://www.gnu.org/licenses/>.
17+
//
18+
//#############################################################################
19+
20+
#include "IPLScreenshot.h"
21+
22+
void IPLScreenshot::init()
23+
{
24+
// init
25+
_result = NULL;
26+
_winId = 0;
27+
28+
// basic settings
29+
setClassName("IPLScreenshot");
30+
setTitle("Load from another running window/desktop");
31+
setCategory(IPLProcess::CATEGORY_IO);
32+
setIsSource(true);
33+
34+
// inputs and outputs
35+
addOutput("Image", IPL_IMAGE_COLOR);
36+
37+
addProcessPropertyUnsignedInt("trigger", "Trigger Image", "", 0, IPL_WIDGET_BUTTON);
38+
addProcessPropertyBool("continuous", "Run continuously", "", false, IPL_WIDGET_CHECKBOXES);
39+
// addProcessPropertyInt("wid", "Window Selector", "", ...);
40+
}
41+
42+
void IPLScreenshot::destroy()
43+
{
44+
delete _result;
45+
}
46+
47+
bool IPLScreenshot::processInputData(IPLData*, int, bool)
48+
{
49+
// delete previous result
50+
delete _result;
51+
_result = NULL;
52+
_continuous = getProcessPropertyBool("continuous");
53+
54+
notifyProgressEventHandler(-1);
55+
56+
// if (const QWindow *window = windowHandle())
57+
// screen = window->screen();
58+
QScreen *screen = QGuiApplication::primaryScreen();
59+
// QDesktopWidget* dw = QApplication::desktop();
60+
if (!screen)
61+
return NULL;
62+
_pixmap = screen->grabWindow(0);
63+
64+
_qimage = _pixmap.toImage();
65+
_mat = cv::Mat(_qimage.height(), _qimage.width(), CV_8UC4, (uchar*)_qimage.bits(), _qimage.bytesPerLine());
66+
_result = new IPLImage(_mat);
67+
68+
if(!_result)
69+
{
70+
addError("Could not fetch screenshot.");
71+
return false;
72+
}
73+
74+
/*
75+
std::stringstream s;
76+
s << "Foo ";
77+
addInformation(s.str());
78+
*/
79+
80+
return true;
81+
}
82+
83+
IPLImage *IPLScreenshot::getResultData(int)
84+
{
85+
return _result;
86+
}
87+
88+
void IPLScreenshot::afterProcessing()
89+
{
90+
if(_continuous)
91+
{
92+
notifyPropertyChangedEventHandler();
93+
}
94+
}

ImagePlay/src/MainWindow.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@ void MainWindow::loadProcesses()
456456
_factory->registerProcess("IPLCamera", new IPLCamera);
457457
//_factory->registerProcess("IPLLoadVideo", new IPLLoadVideo);
458458
_factory->registerProcess("IPLLoadImageSequence", new IPLLoadImageSequence);
459+
_factory->registerProcess("IPLScreenshot", new IPLScreenshot);
459460
_factory->registerProcess("IPLSaveImage", new IPLSaveImage);
460461
_factory->registerProcess("IPLSplitPlanes", new IPLSplitPlanes);
461462
_factory->registerProcess("IPLMergePlanes", new IPLMergePlanes);

0 commit comments

Comments
 (0)