//編譯環(huán)境VS2005 選WIN32應(yīng)用程序, 我從來不用MFC
創(chuàng)新互聯(lián)堅持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:網(wǎng)站建設(shè)、網(wǎng)站制作、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時代的連云港網(wǎng)站設(shè)計、移動媒體設(shè)計的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!
#include GL/GL.h
#include gl/GLU.h
#include gl/GLAux.h
#include math.h
#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "glu32.lib")
#pragma comment(lib, "glaux.lib")
#define MAX_LOADSTRING 100
//定義遞歸調(diào)用閥值,即其中最小三角形邊長
#define SIDELENGHT (0.05)
// Global Variables:
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name
//自定義全局變量
HGLRC g_hRC = NULL; //OpenGL 繪圖上下文
HDC g_hDC = NULL; //設(shè)備上下文
HWND g_hWnd = NULL; //保存當(dāng)前窗口句柄
//定義三角形頂點指針
typedef struct tagTRIANGLEPOINT
{
GLfloat tpPointX;
GLfloat tpPointY;
}TRIANGLEPOINT,*LTRIANGLEPOINT;
//定義最外面大三角形三個點
TRIANGLEPOINT g_TrianglePoint[3] = {{0.0, 0.0}, {5.0, 0.0}, {2.5,2.5}};
// Forward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
//自定義函數(shù)
void EnableOpenGL(HWND hWnd);
void SceneInit();
void SceneResizeViewport();
void DisableOpenGL();
void Display();
void DrawTriangle(LTRIANGLEPOINT pTrianglePoint, int iPointNum = 3);
void DrawLargeTriangle(LTRIANGLEPOINT pTrianglePoint, int iPointNum);
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
// TODO: Place code here.
MSG msg;
HACCEL hAccelTable;
// Initialize global strings
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_OPENGLTRIANGLE, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);
// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
EnableOpenGL(g_hWnd);
SceneInit();
SceneResizeViewport();
hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_OPENGLTRIANGLE));
// Main message loop:
ZeroMemory(msg, sizeof(msg));
while ( msg.message != WM_QUIT )
{
if (PeekMessage(msg, NULL, 0U, 0U, PM_REMOVE))
{
if(!TranslateAccelerator(msg.hwnd, hAccelTable, msg))
{
TranslateMessage(msg);
DispatchMessage(msg);
}
}
else
{
Display();
SwapBuffers(g_hDC);
}
}
DisableOpenGL();
return (int) msg.wParam;
}
//
// FUNCTION: MyRegisterClass()
//
// PURPOSE: Registers the window class.
//
// COMMENTS:
//
// This function and its usage are only necessary if you want this code
// to be compatible with Win32 systems prior to the 'RegisterClassEx'
// function that was added to Windows 95. It is important to call this function
// so that the application will get 'well formed' small icons associated
// with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_OPENGLTRIANGLE));
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = MAKEINTRESOURCE(IDC_OPENGLTRIANGLE);
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
return RegisterClassEx(wcex);
}
//
// FUNCTION: InitInstance(HINSTANCE, int)
//
// PURPOSE: Saves instance handle and creates main window
//
// COMMENTS:
//
// In this function, we save the instance handle in a global variable and
// create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
hInst = hInstance; // Store instance handle in our global variable
hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
if (!hWnd)
{
return FALSE;
}
g_hWnd = hWnd;
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
//
// FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
// PURPOSE: Processes messages for the main window.
//
// WM_COMMAND - process the application menu
// WM_PAINT - Paint the main window
// WM_DESTROY - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_ABOUT:
DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, ps);
// TODO: Add any drawing code here...
EndPaint(hWnd, ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
// Message handler for about box.
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
UNREFERENCED_PARAMETER(lParam);
switch (message)
{
case WM_INITDIALOG:
return (INT_PTR)TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;
}
break;
}
return (INT_PTR)FALSE;
}
//初始化opengl
void EnableOpenGL(HWND hWnd)
{
PIXELFORMATDESCRIPTOR pfd;
int iFormat;
g_hDC = GetDC(hWnd);
ZeroMemory(pfd, sizeof(pfd));
pfd.nSize = sizeof(pfd);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW| PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 32;
pfd.cDepthBits = 16;
pfd.iLayerType = PFD_MAIN_PLANE;
iFormat = ChoosePixelFormat( g_hDC, pfd );
SetPixelFormat( g_hDC, iFormat, pfd );
g_hRC = wglCreateContext(g_hDC);
wglMakeCurrent( g_hDC, g_hRC);
}
//設(shè)置著色模式
void SceneInit()
{
glShadeModel(GL_SMOOTH);
glClearColor(1.0, 1.0, 1.0, 0.5);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
}
//設(shè)置視口
void SceneResizeViewport()
{
RECT rect;
int w,h;
GLfloat aspect;
GetClientRect( g_hWnd, rect );
w = rect.right - rect.left;
h =rect.bottom - rect.top;
aspect = (GLfloat)w/ (GLfloat)h;
glViewport(0,0,w,h);//設(shè)置視口
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 5.0, 0.0, 5.0/aspect);
}
void DisableOpenGL(){
wglMakeCurrent(NULL, NULL);
wglDeleteContext(g_hRC);
ReleaseDC(g_hWnd, g_hDC);
}
void Display()
{
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
DrawLargeTriangle(g_TrianglePoint, 3);
DrawTriangle(g_TrianglePoint, 3);
glFlush();
}
//畫大三角形
void DrawLargeTriangle(LTRIANGLEPOINT pTrianglePoint, int iPointNum)
{
glBegin(GL_LINE_LOOP);
for ( int i = 0; i 3; ++i)
{
glColor3f(1.0,0.0,0.0);
glVertex2f(pTrianglePoint[i].tpPointX,pTrianglePoint[i].tpPointY);
}
glEnd();
}
//遞歸函數(shù)
void DrawTriangle(LTRIANGLEPOINT pTrianglePoint, int iPointNum)
{
//得到中間三角形的三個點
TRIANGLEPOINT trianglepoint[3];
for (int i = 0; i 3; ++i)
{
if ( i == 2)
{
trianglepoint[i].tpPointX = (pTrianglePoint[i].tpPointX + pTrianglePoint[0].tpPointX) / 2;
trianglepoint[i].tpPointY = (pTrianglePoint[i].tpPointY + pTrianglePoint[0].tpPointY) / 2;
}
else
{
trianglepoint[i].tpPointX = (pTrianglePoint[i].tpPointX + pTrianglePoint[i+1].tpPointX) / 2;
trianglepoint[i].tpPointY = (pTrianglePoint[i].tpPointY + pTrianglePoint[i+1].tpPointY) / 2;
}
}
glBegin(GL_LINE_LOOP);
for ( int i = 0; i 3; ++i)
{
glColor3f(1.0,0.0,0.0);
glVertex2f(trianglepoint[i].tpPointX,trianglepoint[i].tpPointY);
}
glEnd();
//構(gòu)建其它三角
TRIANGLEPOINT trianglepoint1[3];
TRIANGLEPOINT trianglepoint2[3];
TRIANGLEPOINT trianglepoint3[3];
ZeroMemory(trianglepoint1, sizeof(trianglepoint1));
ZeroMemory(trianglepoint2, sizeof(trianglepoint2));
ZeroMemory(trianglepoint2, sizeof(trianglepoint2));
trianglepoint1[0] = pTrianglePoint[0];
trianglepoint1[1] = trianglepoint[0];
trianglepoint1[2] = trianglepoint[2];
trianglepoint2[0] = pTrianglePoint[1];
trianglepoint2[1] = trianglepoint[1];
trianglepoint2[2] = trianglepoint[0];
trianglepoint3[0] = pTrianglePoint[2];
trianglepoint3[1] = trianglepoint[2];
trianglepoint3[2] = trianglepoint[1];
//設(shè)定邊界
if(pow(abs(trianglepoint1[0].tpPointX - trianglepoint1[1].tpPointX), 2)
+pow(abs(trianglepoint1[0].tpPointY - trianglepoint1[1].tpPointY), 2) SIDELENGHT)
DrawTriangle(trianglepoint1, iPointNum);
if(pow(trianglepoint2[0].tpPointX - trianglepoint2[1].tpPointX, 2)
+pow(trianglepoint2[0].tpPointY - trianglepoint2[1].tpPointY, 2) SIDELENGHT)
DrawTriangle(trianglepoint2, iPointNum);
if(pow(trianglepoint2[0].tpPointX - trianglepoint2[1].tpPointX, 2)
+pow(trianglepoint2[0].tpPointY - trianglepoint2[1].tpPointY, 2) SIDELENGHT)
DrawTriangle(trianglepoint3, iPointNum);
python閥值組大于返回結(jié)果小于返回結(jié)果啥意思簡單閾值
對每一個像素都應(yīng)用相同的閾值。如果像素值小于閾值,則將其設(shè)置為0,否則設(shè)置為最大值。
函數(shù):
retval, dst=cv.threshold(src, thresh, maxval, type[, dst])對每個像素使用固定的閾值
參數(shù):
src
輸入圖像 ,灰度圖(多通道, 8-bit or 32-bit floating point).
dst
與src具有相同大小、類型和通道數(shù)的輸出數(shù)組。
thresh
閾值
maxval
當(dāng)像素值超過了閾值(或者小于閾值,根據(jù)type來決定),所賦予的值
type
返回值:
retVal:使用的閾值,在Otsu‘s中會用到
dst: 經(jīng)過閾值處理的圖像
分享標(biāo)題:sharepoint閥值 SHAREPOINT軟件工程師招聘
文章分享:http://muchs.cn/article14/doegcde.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供面包屑導(dǎo)航、服務(wù)器托管、電子商務(wù)、App設(shè)計、網(wǎng)站改版、關(guān)鍵詞優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)