Tôi đã xóa câu trả lời cũ vì nó không liên quan. Mới cũng được sử dụng OpenCV (kể từ khi tôi đang cố gắng để hiển thị một hình ảnh OpenCV) nhưng nó có thể được thích nghi với bất kỳ khuôn khổ.
Các lõi code đang nơi nó cần một địa chỉ bộ nhớ address
, và số byte đọc qua numrows
, numcols
, và byte_size
và đọc những byte vào một bộ đệm. Tôi chắc chắn bạn có thể điều chỉnh rằng phần mã cho nhu cầu của riêng bạn.
#include "stdafx.h"
#include <windows.h>
#include <cv.h>
#include <highgui.h>
#include <iostream>
using namespace std;
using namespace cv;
void imshow_debug(const LPCVOID address, const int numrows, const int numcols, const int type, const int byte_size, const int step, const string windows_title)
{
// Initialize
unsigned long PID;
SIZE_T read_bytes = 0;
// Allocate space for the image
const int bytes_to_read = numrows*numcols*byte_size;
uchar *image_data = new uchar[bytes_to_read];
Mat Image(numrows,numcols,type,image_data,step);
// Get the handle and PID
HWND handle = FindWindowA(0, windows_title.c_str());
if (!FindWindowA(0, windows_title.c_str()))
{
printf("Window %s not found!", windows_title);
exit(0);
}
GetWindowThreadProcessId(handle, &PID); /* Get windows PID from a window handle */
HANDLE WindowsProcessHandle = OpenProcess(PROCESS_ALL_ACCESS, false, PID);
// Read the image
ReadProcessMemory(WindowsProcessHandle,address,image_data,bytes_to_read,&read_bytes);
if(bytes_to_read != read_bytes)
{
cout<<"Could not read entire image"<<endl;
exit(0);
}
// Display the image
namedWindow("Image");
imshow("Image",Image);
waitKey();
// Clean up
CloseHandle(WindowsProcessHandle);
delete[]image_data;
}
int main(int argc, char* argv[])
{
imshow_debug((LPVOID)0x03af0370,300,300,CV_64F,sizeof(double),2400,"C:\\Documents and Settings\\jacobm\\My Documents\\Visual Studio 2005\\Projects\\Head\\debug\\SSR_VideoComp.exe");
return 0;
}
Tôi quan tâm đến chính xác cùng một tác vụ. Có tiến bộ nào về vấn đề này không? Bạn đã chấp nhận câu trả lời có liên kết tới imdebug, nhưng nó yêu cầu sửa đổi mã nguồn và mâu thuẫn với nhận xét của riêng bạn: http://stackoverflow.com/questions/1549129/debugging-image-rendering-in-visual-c-any-helpful -add-ins # comment1425286_1549543, phải không? – Mikhail