1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
|
#define WINVER 0x0500
#include <tesseract/baseapi.h>
#include <leptonica/allheaders.h>
#include <opencv2/opencv.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/videoio.hpp>
#include <iostream>
#include <fstream>
#include <Windows.h>
#include <iostream>
#include <string>
#include <iomanip>
#include <QFile>
#include <cstdlib>
#include <windows.h>
#include <stdio.h>
#include <psapi.h>
#include <iostream>
#include <iomanip>
using std::cout;
using std::endl;
using std::cin;
using std::ios;
using std::setiosflags;
using std::hex;
using std::oct;
using std::dec;
using std::cout;
using std::endl;
using std::cin;
using std::ios;
using std::setiosflags;
using std::hex;
using std::oct;
using std::dec;
using namespace std;
void screenCapture ();
int PrintMemoryInfo( DWORD processID );
class hwnd2Mat
{
public:
hwnd2Mat(HWND hwindow, float scale = 1);
virtual ~hwnd2Mat();
virtual void read();
cv::Mat image;
private:
HWND hwnd;
HDC hwindowDC, hwindowCompatibleDC;
int height, width, srcheight, srcwidth;
HBITMAP hbwindow;
BITMAPINFOHEADER bi;
};
hwnd2Mat::hwnd2Mat(HWND hwindow, float scale)
{
hwnd = hwindow;
hwindowDC = GetDC(hwnd);
hwindowCompatibleDC = CreateCompatibleDC(hwindowDC);
SetStretchBltMode(hwindowCompatibleDC, COLORONCOLOR);
RECT windowsize;
GetClientRect(hwnd, &windowsize);
srcheight = windowsize.bottom;
srcwidth = windowsize.right;
height = (int)(windowsize.bottom * scale);
width = (int)(windowsize.right * scale);
image.create(height, width, CV_8UC4);
ReleaseDC(hwnd, hwindowDC);
hbwindow = CreateCompatibleBitmap(hwindowDC, width, height);
bi.biSize = sizeof(BITMAPINFOHEADER);
bi.biWidth = width;
bi.biHeight = -height;
bi.biPlanes = 1;
bi.biBitCount = 32;
bi.biCompression = BI_RGB;
bi.biSizeImage = 0;
bi.biXPelsPerMeter = 0;
bi.biYPelsPerMeter = 0;
bi.biClrUsed = 0;
bi.biClrImportant = 0;
SelectObject(hwindowCompatibleDC, hbwindow);
read();
}
void hwnd2Mat::read(){
StretchBlt(hwindowCompatibleDC, 0, 0, width, height, hwindowDC, 0, 0, srcwidth, srcheight, SRCCOPY); //change SRCCOPY to NOTSRCCOPY for wacky colors !
GetDIBits(hwindowCompatibleDC, hbwindow, 0, height, image.data, (BITMAPINFO*)&bi, DIB_RGB_COLORS); //copy from hwindowCompatibleDC to hbwindow
}
hwnd2Mat::~hwnd2Mat(){
DeleteObject(hbwindow);
DeleteDC(hwindowCompatibleDC);
ReleaseDC(hwnd, hwindowDC);
image.release();
cout << "destructor called" << endl;
}
int main()
{
int processNumber = _getpid();
int i = 0;
int memoryLoad = 0;
int first = 0;
while (true)
{
cout << i << endl;
screenCapture();
memoryLoad = PrintMemoryInfo( processNumber );
cout << " Load " << memoryLoad << " MB " << memoryLoad/1000000 << endl;
if (i == 0 )
first = memoryLoad;
cout << "first " << first << endl;
cout << "load " << memoryLoad << endl;
i++;
}
}
int PrintMemoryInfo( DWORD processID ){
int memory_value;
int processNumber = _getpid();
HANDLE hProcess;
PROCESS_MEMORY_COUNTERS pmc;
if (processID == processNumber)
hProcess = OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,FALSE, processID );
else
return 0;
if (processID == processNumber)
if ( GetProcessMemoryInfo( hProcess, &pmc, sizeof(pmc)))
memory_value = pmc.WorkingSetSize;
hProcess = NULL;
return memory_value;
}
void screenCapture (){
cv::Mat capturedImage;
hwnd2Mat capDesktop(GetDesktopWindow());
cv::VideoWriter writer;
int codec = cv::VideoWriter::fourcc('X', 'V', 'I', 'D');
double fps = 10.0;
string filename = "./caP3.mkv";
writer.open(filename, codec, fps, capDesktop.image.size(), true);
capDesktop.read();
cv::cvtColor(capDesktop.image, capturedImage, cv::COLOR_BGRA2BGR);
}
| |