-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
input: added desktop screen as a possible image source (Qt Qscreen ba…
…sed)
- Loading branch information
Raphaël Droz
committed
Nov 11, 2018
1 parent
e627d40
commit 395ffc6
Showing
5 changed files
with
159 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
//############################################################################# | ||
// | ||
// This file is part of ImagePlay. | ||
// | ||
// ImagePlay 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. | ||
// | ||
// ImagePlay 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 ImagePlay. If not, see <http://www.gnu.org/licenses/>. | ||
// | ||
//############################################################################# | ||
|
||
#ifndef IPLSCREENSHOT_H | ||
#define IPLSCREENSHOT_H | ||
|
||
#include <string> | ||
#include <QGuiApplication> | ||
#include <QScreen> | ||
#include <QPixmap> | ||
#include <QImage> | ||
|
||
#include "IPL_global.h" | ||
#include "IPLProcess.h" | ||
|
||
#include "opencv2/core/core.hpp" | ||
#include "opencv2/imgproc/imgproc.hpp" | ||
#include "opencv2/highgui/highgui.hpp" | ||
|
||
/** | ||
* @brief The IPLScreenshot class | ||
*/ | ||
class IPLSHARED_EXPORT IPLScreenshot : public IPLClonableProcess<IPLScreenshot> | ||
{ | ||
public: | ||
IPLScreenshot() : IPLClonableProcess() { init(); } | ||
~IPLScreenshot() { destroy(); } | ||
|
||
void init(); | ||
void destroy(); | ||
virtual bool processInputData (IPLData* data, int inNr, bool useOpenCV); | ||
virtual IPLImage* getResultData (int outNr); | ||
virtual void afterProcessing (); | ||
|
||
protected: | ||
IPLImage* _result; | ||
bool _continuous; | ||
|
||
int _winId; | ||
QPixmap _pixmap; | ||
QImage _qimage; | ||
cv::Mat _mat; | ||
}; | ||
|
||
#endif // IPLSCREENSHOT_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
//############################################################################# | ||
// | ||
// This file is part of ImagePlay. | ||
// | ||
// ImagePlay 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. | ||
// | ||
// ImagePlay 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 ImagePlay. If not, see <http://www.gnu.org/licenses/>. | ||
// | ||
//############################################################################# | ||
|
||
#include "IPLScreenshot.h" | ||
|
||
void IPLScreenshot::init() | ||
{ | ||
// init | ||
_result = NULL; | ||
_winId = 0; | ||
|
||
// basic settings | ||
setClassName("IPLScreenshot"); | ||
setTitle("Load from another running window/desktop"); | ||
setCategory(IPLProcess::CATEGORY_IO); | ||
setIsSource(true); | ||
|
||
// inputs and outputs | ||
addOutput("Image", IPL_IMAGE_COLOR); | ||
|
||
addProcessPropertyUnsignedInt("trigger", "Trigger Image", "", 0, IPL_WIDGET_BUTTON); | ||
addProcessPropertyBool("continuous", "Run continuously", "", false, IPL_WIDGET_CHECKBOXES); | ||
// addProcessPropertyInt("wid", "Window Selector", "", ...); | ||
} | ||
|
||
void IPLScreenshot::destroy() | ||
{ | ||
delete _result; | ||
} | ||
|
||
bool IPLScreenshot::processInputData(IPLData*, int, bool) | ||
{ | ||
// delete previous result | ||
delete _result; | ||
_result = NULL; | ||
_continuous = getProcessPropertyBool("continuous"); | ||
|
||
notifyProgressEventHandler(-1); | ||
|
||
// if (const QWindow *window = windowHandle()) | ||
// screen = window->screen(); | ||
QScreen *screen = QGuiApplication::primaryScreen(); | ||
// QDesktopWidget* dw = QApplication::desktop(); | ||
if (!screen) | ||
return NULL; | ||
_pixmap = screen->grabWindow(0); | ||
|
||
_qimage = _pixmap.toImage(); | ||
_mat = cv::Mat(_qimage.height(), _qimage.width(), CV_8UC4, (uchar*)_qimage.bits(), _qimage.bytesPerLine()); | ||
_result = new IPLImage(_mat); | ||
|
||
if(!_result) | ||
{ | ||
addError("Could not fetch screenshot."); | ||
return false; | ||
} | ||
|
||
/* | ||
std::stringstream s; | ||
s << "Foo "; | ||
addInformation(s.str()); | ||
*/ | ||
|
||
return true; | ||
} | ||
|
||
IPLImage *IPLScreenshot::getResultData(int) | ||
{ | ||
return _result; | ||
} | ||
|
||
void IPLScreenshot::afterProcessing() | ||
{ | ||
if(_continuous) | ||
{ | ||
notifyPropertyChangedEventHandler(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters