截取特定区域的屏幕截图

Taking a screenshot of a particular area

本文关键字:屏幕截图 区域 截取      更新时间:2023-10-16

寻找一种在C++中截取屏幕上特定区域屏幕截图的方法。(所以不是整个屏幕)然后它应该将其保存为.png .jpg之后与另一个函数一起使用的任何内容。

另外,我将以某种方式将其与openCV一起使用。以为我会提到这一点,也许这是一个有用的细节。

OpenCV无法直接从您的计算机截取屏幕截图。您将需要一个不同的框架/方法来执行此操作。@Ben是正确的,这个链接值得研究。

一旦你读懂了这个图像,你需要把它存储到cv:Mat中,以便你能够对它执行OpenCV操作。

为了在OpenCV中裁剪图像,以下代码片段会有所帮助。

CVMat * imagesource;
// Transform it into the C++ cv::Mat format
cv::Mat image(imagesource); 
// Setup a rectangle to define your region of interest
cv::Rect myROI(10, 10, 100, 100);
// Crop the full image to that image contained by the rectangle myROI
// Note that this doesn't copy the data
cv::Mat croppedImage = image(myROI);