#include <bits/stdc++.h>
#include "opencv2/core.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/opencv.hpp"
#include "opencv2/videoio.hpp"
#include <X11/Xlib.h> //-lX11
#include <X11/Xutil.h>
#include <X11/Xmd.h>
#include <X11/Xatom.h>
using namespace std;
using namespace cv;
Mat getScreenShot()
{
Display *dis=XOpenDisplay((char *)0);
Screen *scr = XDefaultScreenOfDisplay(dis);
Drawable drawable = XDefaultRootWindow(dis);
XImage *image = XGetImage(dis, drawable, 0, 0, scr->width, scr->height, AllPlanes, ZPixmap);
int size=image->bytes_per_line*image->height;
unsigned char imagedata[size];
memcpy(imagedata,image->data,size);
cv::Mat ret=cv::Mat(scr->height,scr->width,CV_8UC4,imagedata);
XDestroyImage(image);文章来源:https://www.toymoban.com/news/detail-555790.html
XCloseDisplay(dis);
return ret;
}文章来源地址https://www.toymoban.com/news/detail-555790.html
到了这里,关于通过X11获取屏幕截图并转为opencv Mat的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!