function D=height(C) C=double(C) %将二值图像C的类型转化为double型 [Height,Width] = size(C); %计算图


哪位大神 能把这 MATLAB程序 转换成 opencv的c++形式 万分感谢
#include <windows.h>

/* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

LRESULT CALLBACK ScrollProc(HWND, UINT, WPARAM, LPARAM);

int idFocus;
WNDPROC OldScroll[3];

/* Make the class name into a global variable */
char szClassName[ ] = "WindowsApp"凳李;

int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)

{
HWND hwnd; /* This is the handle for our window */
MSG messages; /* Here messages to the application are saved */
WNDCLASSEX wincl; /* Data structure for the windowclass */

/* The Window structure */
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
wincl.style = CS_DBLCLKS; /* Catch double-clicks */
wincl.cbSize = sizeof (WNDCLASSEX);

/* Use default icon and mouse-pointer */
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL; /枣手迟* No menu */
wincl.cbClsExtra = 0; /* No extra bytes after the window class */
wincl.cbWndExtra = 0; /薯拿* structure or the window instance */
/* Use Windows's default color as the background of the window */
wincl.hbrBackground = CreateSolidBrush(0);

/* Register the window class, and if it fails quit the program */
if (!RegisterClassEx (&wincl))
return 0;

/* The class is registered, let's create the program*/
hwnd = CreateWindowEx (
0, /* Extended possibilites for variation */
szClassName, /* Classname */
"Color Scroll", /* Title Text */
WS_OVERLAPPEDWINDOW, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
544, /* The programs width */
375, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to desktop */
NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);

/* Make the window visible on the screen */
ShowWindow (hwnd, nFunsterStil);
UpdateWindow(hwnd);

/* Run the message loop. It will run until GetMessage() returns 0 */
while (GetMessage (&messages, NULL, 0, 0))
{
/* Translate virtual-key messages into character messages */
TranslateMessage(&messages);
/* Send message to WindowProcedure */
DispatchMessage(&messages);
}

/* The program return-value is 0 - The value that PostQuitMessage() gave */
return messages.wParam;
}

/* This function is called by the Windows function DispatchMessage() */

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static COLORREF crPrim[3] = {RGB(255, 0, 0),
RGB(0, 255, 0),
RGB(0, 0, 255)};
static HBRUSH hBrush[3], hBrushStatic;
static HWND hwndScroll[3], hwndLabel[3], hwndValue[3], hwndRect;
static int color[3], cyChar;
static RECT rcColor;
static TCHAR *szColorLabel[] = {TEXT("Red"),
TEXT("Green"),
TEXT("Blue")};
HINSTANCE hInstance;
int i, cxClient, cyClient;
TCHAR szBuffer[10];

switch (message) /* handle the messages */
{
case WM_CREATE:
hInstance = (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE);

// Create the white-rectangle window against which the
// scroll bars will be positioned. The child window ID is 9
hwndRect = CreateWindow(TEXT("static"), NULL,
WS_CHILD | WS_VISIBLE | SS_WHITERECT,
0, 0, 0, 0,
hwnd, (HMENU)9, hInstance, NULL);

for (i=0; i<3; i++)
{
// The three scroll bars have IDs0, 1, and 2, with
// scroll bar ranges from 0 through 255
hwndScroll[i] = CreateWindow(TEXT("scrollbar"), NULL,
WS_CHILD | WS_VISIBLE |
WS_TABSTOP | SBS_VERT,
0, 0, 0, 0, hwnd,
(HMENU)i, hInstance, NULL);

SetScrollRange(hwndScroll[i], SB_CTL, 0, 255, FALSE);
SetScrollPos(hwndScroll[i], SB_CTL, 0, FALSE);

// The Three color-name labels have IDs3, 4, and5,
// and text strings "Red", "Green", and"Blue"
hwndLabel[i] = CreateWindow(TEXT("static"), szColorLabel[i],
WS_CHILD | WS_VISIBLE | SS_CENTER,
0, 0, 0, 0, hwnd, (HMENU)(i+3),
hInstance, NULL);

// The three color-value text fields have IDs6, 7
// and 8, and initial text strings of "0"
hwndValue[i] = CreateWindow(TEXT("static"), TEXT("0"),
WS_CHILD | WS_VISIBLE | SS_CENTER,
0, 0, 0, 0, hwnd, (HMENU)(i+6),
hInstance, NULL);

OldScroll[i] = (WNDPROC)SetWindowLong(hwndScroll[i],
GWL_WNDPROC, (LONG)ScrollProc);
hBrush[i] = CreateSolidBrush(crPrim[i]);
}

hBrushStatic = CreateSolidBrush(GetSysColor(COLOR_BTNHIGHLIGHT));
cyChar = HIWORD(GetDialogBaseUnits());
return 0;
case WM_SIZE:
cxClient = LOWORD(lParam);
cyClient = HIWORD(lParam);
SetRect(&rcColor, cxClient/2, 0, cxClient, cyClient);

MoveWindow(hwndRect, 0, 0, cxClient/2, cyClient, TRUE);

for (i=0; i<3; i++)
{
// Show the scrollbar
MoveWindow(hwndScroll[i],
(2*i+1) * cxClient/14, 2*cyChar,
cxClient/14, cyClient - 4*cyChar, TRUE);
// Show the label of the scrollbar
MoveWindow(hwndLabel[i],
(4*i+1) * cxClient/28, cyChar/2,
cxClient/7, cyChar, TRUE);
// Show the scrollbar's value
MoveWindow(hwndValue[i],
(4*i+1) * cxClient/28,
cyClient - 3*cyChar/2,
cxClient/7, cyChar, TRUE);
}

SetFocus(hwnd);
return 0;
case WM_SETFOCUS:
SetFocus(hwndScroll[idFocus]);
return 0;
case WM_VSCROLL:
i = GetWindowLong((HWND)lParam, GWL_ID);

switch (LOWORD(wParam))
{
case SB_PAGEDOWN:
color[i] += 15;
case SB_LINEDOWN:
color[i] = min(255, color[i]+1);
break;
case SB_PAGEUP:
color[i] -= 15;
case SB_LINEUP:
color[i] = max(0, color[i]-1);
break;
case SB_TOP:
color[i] = 0;
break;
case SB_BOTTOM:
color[i] = 255;
break;
case SB_THUMBPOSITION:
case SB_THUMBTRACK:
color[i] = HIWORD(wParam);
break;
default: break;
}

SetScrollPos(hwndScroll[i], SB_CTL, color[i], TRUE);
wsprintf(szBuffer, TEXT("%i"), color[i]);
// Change the scrollbar's value and show it
SetWindowText(hwndValue[i], szBuffer);

DeleteObject((HBRUSH)
SetClassLong(hwnd, GCL_HBRBACKGROUND,
(LONG)CreateSolidBrush(RGB(color[0], color[1], color[2]))));

InvalidateRect(hwnd, &rcColor, TRUE);
return 0;
case WM_CTLCOLORSCROLLBAR:
// Get the child-window's IDs
i = GetWindowLong((HWND)lParam, GWL_ID);
return (LRESULT)hBrush[i];
case WM_CTLCOLORSTATIC:
i = GetWindowLong((HWND)lParam, GWL_ID);

if (i>=3 && i<=8) // static text controls
{
SetTextColor((HDC)wParam, crPrim[i%3]);
SetBkColor((HDC)wParam, GetSysColor(COLOR_BTNHIGHLIGHT));
return (LRESULT)hBrushStatic;
}
break;
case WM_SYSCOLORCHANGE:
DeleteObject(hBrushStatic);
hBrushStatic = CreateSolidBrush(GetSysColor(COLOR_BTNHIGHLIGHT));
return 0;
case WM_DESTROY:
DeleteObject((HBRUSH)SetClassLong(hwnd, GCL_HBRBACKGROUND,
(LONG)GetStockObject(WHITE_BRUSH)));

for (i=0; i<3; i++)
{
DeleteObject(hBrush[i]);
}

DeleteObject(hBrushStatic);
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
break;
default: /* for messages that we don't deal with */
return DefWindowProc (hwnd, message, wParam, lParam);
}

return 0;
}

LRESULT CALLBACK ScrollProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int id = GetWindowLong(hwnd, GWL_ID);

switch (message)
{
case WM_KEYDOWN:
if (VK_TAB == wParam)
{
SetFocus(GetDlgItem(GetParent(hwnd),
(id + (GetKeyState(VK_SHIFT)<0 ? 2:1)) % 3));
}
break;
case WM_SETFOCUS:
idFocus = id;
break;
}

return CallWindowProc(OldScroll[id], hwnd, message, wParam, lParam);
}