게시판 즐겨찾기
편집
드래그 앤 드롭으로
즐겨찾기 아이콘 위치 수정이 가능합니다.
이미지 비교에 관한 고찰
게시물ID : programmer_11100짧은주소 복사하기
작성자 : 대★맛이야
추천 : 0
조회수 : 1037회
댓글수 : 3개
등록시간 : 2015/06/09 23:25:11
옵션
  • 본인삭제금지
 
 이전번에 opencv 질문을 올리고 자체 해결해서 함 이미지 비교를 해보았습니다만...
 
 생각보다 인식률이 영 좋지는 않았습니다.
 
 그냥 못찾더라고요.
 
 그래서 다른 이미지 대 이미지 (Template Matching) 을 찾아보려고 하는데
 
 추천 하나만 부탁드립니다.
 
 
 그리고 2번째 질문. 제가 MSDN인가 개발자 네트워크에 있는 윈도우 전채 스샷 코드를 변형해서 한 윈도우 프로그램만 찾아 스샷 찍게 만들었는데 실력이 부족해서 어디가 문제인지 정확하게 찾기가 힘드네여
 
 문제는 정확하게 그 이미지의 크기대로 나오는게 아니라 특정하게 이미지가 잘려서 나옵니다.
 
 일단
 
1
2
3
#define HookingWindowName L"123.jpg-Windows 사진 뷰어"
 
CaptureAnImage(hWnd, HookingWindowName);
cs
 
이고요
 
아래가 이미지 캡쳐 코드입니다.
 
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
int CaptureAnImage(HWND hWnd, LPCWSTR hDisplayId)
{
    HWND hWndCalc;
    HDC hdcScreen;
    HDC hdcWindow;
    HDC hdcMemDC = NULL;
    HBITMAP hbmScreen = NULL;
    BITMAP bmpScreen;
 
    // Retrieve the handle to a display device context for the client 
    // area of the window. 
    hdcScreen = GetDC(NULL);
    hWndCalc = FindWindow(NULL, hDisplayId);
    hdcWindow = GetDC(hWndCalc);
 
    // Create a compatible DC which is used in a BitBlt from the window DC
    hdcMemDC = CreateCompatibleDC(hdcWindow);
 
    if (!hdcMemDC)
    {
        MessageBox(hWnd, L"CreateCompatibleDC has failed", L"Failed", MB_OK);
        goto done;
    }
 
    // Get the client area for size calculation
    RECT rcClient;
    GetClientRect(hWnd, &rcClient);
 
    //This is the best stretch mode
    SetStretchBltMode(hdcWindow, HALFTONE);
 
    //The source DC is the entire screen and the destination DC is the current window (HWND)
    if (!StretchBlt(hdcWindow,00,rcClient.right, rcClient.bottom,hdcScreen,00,GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN),SRCCOPY))
    {
        MessageBox(hWnd, L"StretchBlt has failed", L"Failed", MB_OK);
        goto done;
    }
 
    // Create a compatible bitmap from the Window DC
    hbmScreen = CreateCompatibleBitmap(hdcWindow, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top);
 
    if (!hbmScreen)
    {
        MessageBox(hWnd, L"CreateCompatibleBitmap Failed", L"Failed", MB_OK);
        goto done;
    }
 
    // Select the compatible bitmap into the compatible memory DC.
    SelectObject(hdcMemDC, hbmScreen);
 
    // Bit block transfer into our compatible memory DC.
    if (!BitBlt(hdcMemDC,00,rcClient.right - rcClient.left, rcClient.bottom - rcClient.top,hdcWindow,00,SRCCOPY))
    {
        MessageBox(hWnd, L"BitBlt has failed", L"Failed", MB_OK);
        goto done;
    }
 
    // Get the BITMAP from the HBITMAP
    GetObject(hbmScreen, sizeof(BITMAP), &bmpScreen);
 
    BITMAPFILEHEADER   bmfHeader;
    BITMAPINFOHEADER   bi;
 
    bi.biSize = sizeof(BITMAPINFOHEADER);
    bi.biWidth = rcClient.right - rcClient.left; //bmpScreen.bmWidth;
    bi.biHeight = rcClient.bottom - rcClient.top, hdcWindow; //bmpScreen.bmHeight;
    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;
 
    DWORD dwBmpSize = ((bmpScreen.bmWidth * bi.biBitCount + 31/ 32* 4 * bmpScreen.bmHeight;
 
    // Starting with 32-bit Windows, GlobalAlloc and LocalAlloc are implemented as wrapper functions that 
    // call HeapAlloc using a handle to the process's default heap. Therefore, GlobalAlloc and LocalAlloc 
    // have greater overhead than HeapAlloc.
    HANDLE hDIB = GlobalAlloc(GHND, dwBmpSize);
    char *lpbitmap = (char *)GlobalLock(hDIB);
 
    // Gets the "bits" from the bitmap and copies them into a buffer 
    // which is pointed to by lpbitmap.
    GetDIBits(hdcWindow, hbmScreen, 0,(UINT)bmpScreen.bmHeight,lpbitmap,(BITMAPINFO *)&bi, DIB_RGB_COLORS);
 
    // A file is created, this is where we will save the screen capture.
    HANDLE hFile = CreateFile(L"captureqwsx.bmp", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
 
    // Add the size of the headers to the size of the bitmap to get the total file size
    DWORD dwSizeofDIB = dwBmpSize + sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);
 
    //Offset to where the actual bitmap bits start.
    bmfHeader.bfOffBits = (DWORD)sizeof(BITMAPFILEHEADER)+(DWORD)sizeof(BITMAPINFOHEADER);
 
    //Size of the file
    bmfHeader.bfSize = dwSizeofDIB;
 
    //bfType must always be BM for Bitmaps
    bmfHeader.bfType = 0x4D42//BM   
 
    DWORD dwBytesWritten = 0;
    WriteFile(hFile, (LPSTR)&bmfHeader, sizeof(BITMAPFILEHEADER), &dwBytesWritten, NULL);
    WriteFile(hFile, (LPSTR)&bi, sizeof(BITMAPINFOHEADER), &dwBytesWritten, NULL);
    WriteFile(hFile, (LPSTR)lpbitmap, dwBmpSize, &dwBytesWritten, NULL);
 
    //Unlock and Free the DIB from the heap
    GlobalUnlock(hDIB);
    GlobalFree(hDIB);
 
    //Close the handle for the file that was created
    CloseHandle(hFile);
 
    //Clean up
done:
    DeleteObject(hbmScreen);
    DeleteObject(hdcMemDC);
    ReleaseDC(NULL, hdcScreen);
    ReleaseDC(hWnd, hdcWindow);
 
    return 0;
}
cs
 
사실 코드 작동 원리도 잘 모릅니다. 그저 핸들 값만 바꿔주면 그 찍히는 이미지가 바뀐다는것뿐 DWORD dwBmpSize 이쪽이 문제인것 같기는 한데 잘 모르겠습니다.
전체 추천리스트 보기
새로운 댓글이 없습니다.
새로운 댓글 확인하기
글쓰기
◀뒤로가기
PC버전
맨위로▲
공지 운영 자료창고 청소년보호