61 lines
1.0 KiB
C++
61 lines
1.0 KiB
C++
#pragma once
|
|
|
|
#include <opencv2/opencv.hpp>
|
|
|
|
#include <X11/Xlib.h>
|
|
#include <X11/Xutil.h>
|
|
|
|
#include <X11/extensions/XShm.h>
|
|
#include <sys/ipc.h>
|
|
#include <sys/shm.h>
|
|
|
|
class ScreenShot {
|
|
private:
|
|
Display* display = nullptr;
|
|
Window window;
|
|
XWindowAttributes wattrib;
|
|
XImage* ximg = nullptr;
|
|
XShmSegmentInfo shminfo;
|
|
|
|
bool init;
|
|
bool closeDisp = true;
|
|
bool valid = false;
|
|
std::string windowname;
|
|
|
|
bool updateAttrib();
|
|
bool initImg();
|
|
public:
|
|
|
|
static std::vector<ScreenShot*> getWindows(const std::string& name);
|
|
|
|
static const uint32_t DEFAULTWIDTH;
|
|
static const uint32_t DEFAULTHEIGHT;
|
|
|
|
ScreenShot();
|
|
ScreenShot(Display* d, Window w);
|
|
~ScreenShot();
|
|
|
|
void take(cv::Mat& cvimg);
|
|
void operator() (cv::Mat& cvimg);
|
|
|
|
constexpr operator bool () const {
|
|
return valid;
|
|
}
|
|
|
|
constexpr int getXOffset() const {
|
|
return wattrib.x;
|
|
}
|
|
|
|
constexpr int getYOffset() const {
|
|
return wattrib.y;
|
|
}
|
|
|
|
constexpr double getXScale() const {
|
|
return wattrib.width / DEFAULTWIDTH;
|
|
}
|
|
|
|
constexpr double getYScale() const {
|
|
return wattrib.height / DEFAULTHEIGHT;
|
|
}
|
|
};
|