1

開いている各アプリケーションのスクリーンショットを撮るアプリケーションを作成する必要があります。たとえば、アプリケーションを実行すると、4 つのウィンドウがある場合、4 つの異なる画像を含む 4 つのスクリーンショットが作成されます。

次のコードがありますが、もう何をすべきかわかりません..

#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/opencv.hpp>
#include <X11/Xlib.h>
#include <X11/Xutil.h>

IplImage *XImage2IplImageAdapter(XImage *ximage)
{
        IplImage *iplImage;
        assert(ximage->format == ZPixmap);
        assert(ximage->depth == 24); 

        iplImage = cvCreateImageHeader(
                cvSize(ximage->width, ximage->height), 
                IPL_DEPTH_8U,
                ximage->bits_per_pixel/8);

        iplImage->widthStep = ximage->bytes_per_line;
        if(ximage->data != NULL)
                iplImage->imageData = ximage->data;

        return iplImage;
}

using namespace cv;

int main(){


    Display* display  = XOpenDisplay(NULL); 


     Screen *screen = DefaultScreenOfDisplay(display);


    int widthX = screen->width;
    int heightY = screen->height;

    XImage* xImageSample = XGetImage(display, DefaultRootWindow(display), 0, 0, widthX, heightY, AllPlanes, ZPixmap);

    if (!(xImageSample != NULL && display != NULL && screen != NULL)){
        return EXIT_FAILURE;
    }

    IplImage *cvImageSample = XImage2IplImageAdapter(xImageSample);

    Mat matImg = Mat(cvImageSample);

    Size dynSize(widthX/3, heightY/3);
    Mat finalMat = Mat(dynSize,CV_8UC1);
    resize(matImg, finalMat, finalMat.size(), 0, 0, INTER_CUBIC);


    imshow("Test",finalMat);
    waitKey(0);


    return 0;
}

それを行う最善の方法は何ですか?

よろしくアレックス

4

1 に答える 1

3

XQueryTreeを使用して子ウィンドウを見つけ、それぞれを保存する必要があります。

ウィンドウ名を出力するだけの使用例を次に示します。

#include <X11/Xlib.h>
#include <iostream>

int main(int argc, char ** argv)
{
    Display *dpy = XOpenDisplay(NULL);

    Window root;
    Window parent;
    Window *children;
    unsigned int num_children;
    Status s = XQueryTree(dpy,  Window DefaultRootWindow(dpy), &root, &parent,
              &children, &num_children);

    if (s != BadWindow) {
        std::cout << "Children: " << num_children << std::endl;
    }

    for (int i=0; i<num_children; i++) {
        char* name;
        XFetchName(dpy, children[i], &name);
        if (name != NULL) {
            std::cout << "Child " << i << ": " << name << std::endl;
        }
    }


    if (children != NULL) {
         XFree(children);
    }
}
于 2013-09-05T13:16:36.943 に答える