MF 的个人资料CMF.net照片日志列表更多 工具 帮助
 

取得網路磁碟機及其路徑的對照 (VB.NET)

 
  '   TO  UNC Path
' ================================================================
  Imports System.Runtime.InteropServices
 ...
     Dim bufSize As Int32 = 2000
     Dim bufPtr As IntPtr = Marshal.AllocHGlobal(bufSize)
     Dim ret As Int32 = WNetGetUniversalName("Z:\", 2, bufPtr, bufSize)
     If ret = 0 Then
         Dim remNil As New RemoteNIL()
         Marshal.PtrToStructure(bufPtr, remNil)
     End If
     Marshal.FreeHGlobal(bufPtr)
 ...
     <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto), Serializable()> Class RemoteNIL
         <MarshalAs(UnmanagedType.LPTStr)> Public UniversalName As String
         <MarshalAs(UnmanagedType.LPTStr)> Public ConnectionName As String
         <MarshalAs(UnmanagedType.LPTStr)> Public RemainingPath As String
     End Class
 ...
     <DllImport("mpr.dll", SetLastError:=False, CharSet:=CharSet.Auto)> _
     Function WNetGetUniversalName( _
         ByVal lpLocalPath As String, _
         ByVal dwInfoLevel As Int32, _
         ByVal lpBuffer As IntPtr, _
         ByRef lpBufferSize As Int32) As Int32
     End Function
 
 

日志


6月17日

TrackEye : 使佣 Webcam 即時人眼追蹤追蹤 (OpenCV + C++)

 
 
 

 

介紹

眼睛是人面的最重要的特點。 那麼眼運動有效的作為在使佣者與電腦之間的介面的通信技術可能找到地方以各種各樣的應用範圍。

眼睛跟蹤和眼睛特點提供的信息有潛力成為一個有趣的方式溝通與在一個人機交互(HCI)系統的一臺計算機。 因此以這刺激,設計跟蹤軟件的一個實時眼睛特點是這個項目的目標。

項目的目的將實施一臺實時眼睛特點跟蹤儀以以下能力:

  • 跟蹤與標度和自轉不變性的實時面孔
  • 單獨地跟蹤眼睛區域
  • 跟蹤眼睛特點
  • 眼睛注視測向
  • 遙遠控制使用眼運動

指示跑和重建TrackEye

安裝說明

  1. 萃取物TrackEye_Executable.zip文件。 在跑TrackEye_636.exe之前,複製二個文件SampleHUE.jpgSampleEye.jpg C:\ 文件夾。 這兩個文件為CAMSHIFT和模板匹配的算法使用。
  2. 沒有用戶將跟隨的其他步運行軟件。 沒有DLL附庸,軟件用靜態地包括的DLLs建立了。

將做的設置執行一好跟蹤

面孔&眼睛偵查的設置

在TrackEye菜單之下 -->跟蹤儀設置

  • 輸入源: 錄影
  • 點擊精選的文件并且選擇。\ Avis \ Sample.avi
  • 面孔偵查算法: Haar面孔偵查算法
  • 檢查「軌道也注視」複選框
  • 眼睛偵查算法: 能適應的PCA
  • 不選定「變化檢查」
  • 數據庫圖像的數字: 8
  • EigenEyes的數字: 5
  • 從eyespace的最大容許的距離: 1200年
  • 面孔寬度或眼睛模板寬度比率: 0.3
  • ColorSpace 在PCA期間,鍵入對用途: CV_RGB2GRAY

瞳孔偵查的設置

檢查「在細節的軌道眼睛」然後檢查「也查出眼睛瞳孔」。 點擊「調整參量」按鈕:

  • 輸入「120」作為「閾值」
  • 點擊「Save Settings」然後點擊「關閉」

Snake

的設置

檢查「Indicate eye boundary using active snakes」。 點擊「snake的設置」按鈕:

  • 選取 ColorSpace 使用: CV_RGB2GRAY
  • 選擇簡單的閾值化并且輸入100作為「閾值」
  • 點擊「Save Settings」然後點擊「Close」

背景

到目前為止有在眼睛偵查的很多工作,并且在項目之前,早先方法小心地被學習確定執行的方法。 我們可以分類研究與眼睛有關入二個主要類別如下所示:

特別設備基於方法

這些研究的類型使用將給某一排序信號與眼睛位置是比例在軌道的必要的設備。 是當前在使用中的各種各樣的方法是眼動電圖描記法,紅外Oculography, Scleral探察線圈。 這些方法完全地是在我們的項目外面。

圖像基於方法

圖像基於方法進行在圖像的眼睛偵查。 使用眼睛的特點,大多數圖像根據方法設法查出眼睛。 到目前為止使用的方法是基於知識的方法,基於特點的方法(顏色,梯度),簡單模板匹配,出現方法。 另一個有趣的方法是「根據匹配在眼睛圖像的一塊幾何眼睛模板通過使幾何模型的能量減到最小的可變性模板匹配」。

TrackEye的實施

被實施的項目在三個組分:

  1. 人臉偵查: 進行標度不變式的面孔偵查
  2. 眼睛偵查: 由於這步,兩隻眼睛被查出
  3. 眼睛特徵抽出: 眼睛特點被提取在這步的結束

人臉偵查

二個不同的方法在項目執行。 他們是:

  1. 連續地能適應意味轉移算法
  2. Haar面孔探知方法
連續地能適應意味轉移算法

能適應的卑鄙轉移算法為跟蹤人面使用和根據攀登密度梯度的健壯非參數技術發現方式(峰頂)稱卑鄙轉移算法的概率分佈。 當面孔在錄影序列被跟蹤,手段修改轉移算法應付動力變化的顏色概率分佈的問題。 如下給算法的結構圖:

[img]http://www.codeproject.com/KB/cpp/TrackEye/TrackEye2.jpg[/img]

Camshift Algorithm

Haar面孔探知方法

第二種面孔偵查算法根據量詞與Haar像特點(即小瀑布一起使用促進的量詞與Haar像特點一起使用)。 首先它訓練與一些數百面孔的樣品視圖。 在量詞被訓練之後,它在輸入圖像上可以被申請於興趣的區域。 量詞輸出「1「如果區域可能顯示面孔和」0「否則。 使用量詞,要搜尋在整體圖像的對象,一個人可能移動橫跨圖像的查尋窗口和檢查每個地點。 量詞被設計,以便它可以「容易地被重量尺寸」為了能發現對象利益在不同的大小,比重量尺寸圖像高效率。

眼睛偵查

二個不同的方法在項目執行:

  1. 模板匹配
  2. 能適應 EigenEye 方法
模板匹配

模板匹配是對象偵查的一個知名的方法。 在我們的模板匹配方法,標準眼孔圖樣手動地被創造,并且給輸入圖像,與標準圖案的交互作用價值為眼睛被計算。 眼睛的存在根據交互作用價值是堅定的。 這種方法有好處的是簡單實施。 然而,因為它不可能有效地應付在標度、姿勢和形狀上的變化它也許有時是不充分的為眼睛偵查。

能適應的EigenEye方法

能適應 EigenEye 方法根據知名的方法 EigenFaces. 然而,因為方法為眼睛偵查使用我們命名了它「EigenEye 方法」。 主要想法是分解眼睛圖像入小套稱eigeneyes的性能特徵圖像,也許被重視作為原始的圖像的主要成分。 這些eigeneyes功能作為稱eyespace的子空間的正交依據傳染媒介。 然而我們知道 eigenface 方法不是不變式的標度。 要提供標度不變性我們可以一次重量尺寸眼睛數據庫與面孔偵查算法收集的信息(EyeWidth/FaceWidth ? 0.35使用一個數據庫),我們只可以提供稱不變式的偵查。

對象跟蹤和偵查的OpenCV作用

OpenCV 圖書館提供很多圖像處理和對象跟蹤&偵查圖書館。 如下給用於這些項目的主函數和他們的用法:

Haar面孔跟蹤的樣品代碼

Collapse
void CTrackEyeDlg : :HaarFaceDetect (IplImage* img, CvBox2D* faceBox) { int標度= 2; IplImage*臨時雇員= cvCreateImage (cvSize (img->width/2, img->height/2), 83); CvPoint pt1, pt2; int我; cvPyrDown (img,臨時雇員, CV_GAUSSIAN_5x5); #ifdef WIN32 cvFlip (臨時雇員,臨時雇員, 0); #endif cvClearMemStorage (存貯); if(hid_cascade) { CvSeq*面對= cvHaarDetectObjects (臨時雇員, hid_cascade,存貯, 1.2, 2, CV_HAAR_DO_CANNY_PRUNING); NumOfHaarFaces = faces->total; if (NumOfHaarFaces >0) { CvRect* r = (CvRect*) cvGetSeqElem (面孔, 00); pt1.x = r->x*scale; pt2.x = (r->x+r->width) *scale; #ifdef WIN32 pt1.y = img->height - r->y*scale; pt2.y = img->height - (r->y+r->height) *scale; #else pt1.y = r->y*scale; pt2.y = (r->y+r->height) *scale; #endif faceBox->center.x = (float) (pt1.x+pt2.x)/2.0; faceBox->center.y = (float) (pt1.y+pt2.y)/2; faceBox->size.width = (float) (pt2.x - pt1.x); faceBox->size.height = (float) (pt1.y - pt2.y); } } cvShowImage ( "Tracking ", img); cvReleaseImage (&temp); }

CamShift算法的樣品代碼

//CamShift的algorithm 輸入 IplImage*顏色= cvCreateImage (cvGetSize (SampleForHUE), IPL_DEPTH_8U, 1); extractHUE (SampleForHUE,顏色); // ** 萃取物顏色information

int hist_size = 20; float排列[] = {0180}; float* pranges [] = {範圍}; hist = cvCreateHist (1, &hist_size, CV_HIST_ARRAY, pranges,1); cvCalcHist (&HUE, hist); //計算顏色part直方圖 hueFrame = cvCreateImage (cvGetSize (CameraFrame), IPL_DEPTH_8U, 1); backProject = cvCreateImage (cvGetSize (CameraFrame), IPL_DEPTH_8U, 1); extractHUE (CameraFrame, hueFrame); while (trackControl! = 0) { extractHUE (CameraFrame, hueFrame); cvCalcBackProject (&hueFrame、backProject, hist); //可能性是formed
    //cvShowImage (「Tester2」, backProject); cvCamShift( backProject, searchWin, cvTermCriteria( CV_TERMCRIT_EPS | CV_TERMCRIT_ITER, 15, 0.1 ), &comp, &faceBox); searchWin = comp.rect; }

樣品代碼模板匹配

Collapse
//模板匹配眼睛的detection
void 面孔: :findEyes_TM (IplImage* faceImage, TrackingSettings*設置) { CvSize faceSize; faceSize = cvGetSize (faceImage); //從眼睛database的裝載模板 CString文件名; //模板的名字左eye的 fileName.Format ( "_s \ \ eye_d.jpg ", settings->params->DBdirectory, 0); IplImage* eyeImage_Left = cvLoadImage (文件名, - 1); //模板的名字左eye的 fileName.Format ( "_s \ \ eye_d.jpg ", settings->params->DBdirectory, 1); IplImage* eyeImage_Right = cvLoadImage (文件名, - 1); IplImage* tempTemplateImg_Left; IplImage* tempTemplateImg_Right; IplImage* templateImg_Left; IplImage* templateImg_Right; if (eyeImage_Left ==零位 || eyeImage_Right ==零位) { MessageBox (零位, "Templates不可能被裝載。\ n 請檢查您的眼睛數據庫文件夾", "Error ", MB_OK||MB_ICONSTOP); 出口(1); } else { // 根據user輸入的設置改變彩色空間 tempTemplateImg_Left = cvCreateImage (cvGetSize (eyeImage_Left), IPL_DEPTH_8U, 1); changeColorSpace (設置、eyeImage_Left, tempTemplateImg_Left); tempTemplateImg_Right = cvCreateImage (cvGetSize (eyeImage_Right), IPL_DEPTH_8U, 1); changeColorSpace (設置、eyeImage_Right, tempTemplateImg_Right); float idealWidth = faceSize.width * settings->params->ratio; float conversionRatio = idealWidth/(float) tempTemplateImg_Left->width; CvSize newSize; newSize.width = (int) idealWidth; newSize.height = (int) (tempTemplateImg_Left->height*conversionRatio); templateImg_Left = cvCreateImage (newSize, IPL_DEPTH_8U, 1); cvResize (tempTemplateImg_Left, templateImg_Left, CV_INTER_LINEAR); //是NNcvReleaseImage (&eyeImage_Left); cvReleaseImage (&tempTemplateImg_Left); templateImg_Right = cvCreateImage (newSize, IPL_DEPTH_8U,1); cvResize (tempTemplateImg_Right, templateImg_Right, CV_INTER_LINEAR); //是NNcvReleaseImage (&eyeImage_Right); cvReleaseImage (&tempTemplateImg_Right); } // *************************************************************
    // ************眼睛************************的查尋faceImage
    // ************************************************************* IplImage* GRAYfaceImage = cvCreateImage (faceSize, IPL_DEPTH_8U, 1); changeColorSpace (設置, faceImage, GRAYfaceImage); //cvCvtColor (faceImage, GRAYfaceImage, CV_RGB2GRAY); 
    //GRAYfaceImage->origin = 1;
    // ** 警告這時圖像起源是底部左corner.

    // ** Eye1查尋area
    int x_left = 0; int y_left = 0; int width_left = (int) ((float) (faceSize.width/2.0)); int height_left = (int) ((float) (faceSize.height)); CvRect rect_Eye1 = cvRect (x_left、y_left、width_left, height_left); CvMat* Eye1Image = cvCreateMat (width_left, height_left, CV_8UC1); cvGetSubRect (GRAYfaceImage, Eye1Image, rect_Eye1); cvFlip (Eye1Image、Eye1Image, 0); // ** Eye2查尋area
    int x_right= (int) ((float) (faceSize.width/2.0)); int y_right = 0; int width_right = (int) ((float) (faceSize.width/2.0)); int height_right = (int) ((float) (faceSize.height)); CvRect rect_Eye2 = cvRect (x_right、y_right、width_right, height_right); CvMat* Eye2Image = cvCreateMat (width_right, height_right, CV_8UC1); cvGetSubRect (GRAYfaceImage, Eye2Image, rect_Eye2); cvFlip (Eye2Image、Eye2Image, 0); // OpenCV說結果的大小一定下列: CvSize大小; size.height= Eye1Image->height - templateImg_Left->height + 1; size.width = Eye1Image->width - templateImg_Left->width + 1; IplImage* result1 = cvCreateImage (大小, IPL_DEPTH_32F, 1); IplImage* result2 = cvCreateImage (大小, IPL_DEPTH_32F, 1); //被留下的Eye cvMatchTemplate (Eye1Image, templateImg_Left, result1, settings->params->tempMatch); //糾正Eye cvMatchTemplate (Eye2Image, templateImg_Right, result2, settings->params->tempMatch); //發現最佳的比賽地點-留下EYE
        doubleminValue1, maxValue1; CvPoint minLoc1, maxLoc1; cvMinMaxLoc (result1、&minValue1、&maxValue1、&minLoc1, &maxLoc1); cvCircle (result1, maxLoc1,5, settings->programColors.colors [2], 1); //變換點回到原始的image maxLoc1.x += templateImg_Left->width/2; maxLoc1.y += templateImg_Left->height/2; settings->params->eye1.coords.x = maxLoc1.x; settings->params->eye1.coords.y = maxLoc1.y; settings->params->eye1.RectSize.width = templateImg_Left->width; settings->params->eye1.RectSize.height = templateImg_Left->height; settings->params->eye1.eyefound = true; //發現最佳的比賽地點-正確的EYE
        doubleminValue2, maxValue2; CvPoint minLoc2, maxLoc2; cvMinMaxLoc (result2、&minValue2、&maxValue2、&minLoc2, &maxLoc2); cvCircle (result2, maxLoc2,5, settings->programColors.colors [2], 1); //變換點回到原始的image maxLoc2.x += templateImg_Left->width/2; maxLoc2.y += templateImg_Left->height/2; settings->params->eye2.coords.x = maxLoc2.x+ (int) faceSize.width/2; settings->params->eye2.coords.y = maxLoc2.y; settings->params->eye2.RectSize.width = templateImg_Left->width; settings->params->eye2.RectSize.height = templateImg_Left->height; settings->params->eye2.eyefound = true; cvCircle (Eye1Image, maxLoc1, 5, settings->programColors.colors [2], 1); cvCircle (Eye2Image, maxLoc2, 5, settings->programColors.colors [2], 1); }

樣品代碼能適應的EigenEye方法

Collapse
void 面孔: :findEyes (IplImage* faceImage, TrackingSettings*設置) { IplImage **圖像= (IplImage **) malloc (sizeof (IplImage*) *numOfImages); IplImage ** eigens = (IplImage **) malloc (sizeof (IplImage*) *numOfImages); IplImage* averageImage; IplImage*投射; CvSize faceSize; faceSize = cvGetSize (faceImage); eigenSize newEigenSize; newEigenSize.width = faceSize.width * settings->params->ratio; newEigenSize.conversion = ((float) newEigenSize.width)/((float)數據庫[0] - >width); newEigenSize.height = ((float)數據庫[0] - >height) * newEigenSize.conversion; CvSize newSize; newSize.width = (int) newEigenSize.width; newSize.height = (int) newEigenSize.height; IplImage* tempImg = cvCreateImage (newSize, IPL_DEPTH_8U, 1); // **********初始化********** 
    for (int i=0; 我params->nImages; i++) { 圖像[i] = cvCreateImage (newSize, IPL_DEPTH_8U, 1); cvResize (數據庫[i],圖像[i], CV_INTER_LINEAR); //是NN } cvShowImage ( "Eigen ",圖像[0]); cvReleaseImage (&tempImg); // 創造EigenFaces的空間
    for (i=0; 我params->nImages; i++) eigens [i] = cvCreateImage (cvGetSize (圖像[0]), IPL_DEPTH_32F, 1); averageImage = cvCreateImage (cvGetSize (圖像[0]), IPL_DEPTH_32F, 1); 投射= cvCreateImage (cvGetSize (圖像[0]), IPL_DEPTH_8U, 1); // *************************************************************
    // ************計算特徵向量&本徵值*************
    // ************************************************************* CvTermCriteria標準; criteria.type = CV_TERMCRIT_ITER|CV_TERMCRIT_EPS; criteria.maxIter = 13; criteria.epsilon = 0.1; // ** n是存在而不是numOfImages cvCalcEigenObjects (settings->params->nImages,圖像, eigens, 000, &criteria、averageImage, vals); // *************************************************************
    // ************眼睛************************的查尋faceImage
    // ************************************************************* IplImage* GRAYfaceImage = cvCreateImage (faceSize, IPL_DEPTH_8U, 1); changeColorSpace (設置, faceImage, GRAYfaceImage); //cvCvtColor (faceImage, GRAYfaceImage, CV_RGB2GRAY); 
    // ** 警告這時圖像起源是底部左corner. GRAYfaceImage->origin = 1; int 邊際= settings->params->MaxError; double極小值=邊際; double距離=邊際; // ** Eye1查尋Space settings->params->eye1.xlimitLeft = 0; settings->params->eye1.xlimitRight = faceSize.width/2.0 -圖像[0] - >width - 1; settings->params->eye1.ylimitUp = (int)( ((float)faceSize.height)*0.75 -圖像[0] - >height - 1); settings->params->eye1.ylimitDown = faceSize.height/2; // ** Eye2查尋Space settings->params->eye2.xlimitLeft = faceSize.width/2.0; settings->params->eye2.xlimitRight = faceSize.width -圖像[0] - >width - 1; settings->params->eye2.ylimitUp = (int)( ((float)faceSize.height)*0.75 -圖像[0] - >height - 1); settings->params->eye2.ylimitDown = faceSize.height/2; settings->params->eye1.initializeEyeParameters (); settings->params->eye2.initializeEyeParameters (); settings->params->eye1.RectSize.width =圖像[0] - >width; settings->params->eye1.RectSize.height =圖像[0] - >height; settings->params->eye2.RectSize.width =圖像[0] - >width; settings->params->eye2.RectSize.height =圖像[0] - >height; IplImage* Image2Comp = cvCreateImage (cvGetSize (圖像[0]), IPL_DEPTH_8U, 1); int x, y; // ** 即查尋左眼睛eye1
    for (y=settings->params->eye1.ylimitDown; yparams->eye1.ylimitUp; y+=2) { for (x=settings->params->eye1.xlimitLeft; xparams->eye1.xlimitRight; x+=2) { cvSetImageROI (GRAYfaceImage, cvRect (x, y,圖像[0] - >width,圖像[0] - >height)); if (settings->params->varianceCheck == 1) { if (calculateSTD (GRAYfaceImage) <= (

double) (settings->params->variance)) { cvResetImageROI (GRAYfaceImage); continue; } } cvFlip (GRAYfaceImage, Image2Comp, 0); cvResetImageROI (GRAYfaceImage); // 決定它是否是眼睛或not cvEigenDecomposite (Image2Comp, settings->params->nEigens, eigens, 00, averageImage,重量); cvEigenProjection (eigens, settings->params->nEigens, CV_EIGOBJ_NO_CALLBACK, 0,重量、averageImage,投射); 距離= cvNorm (Image2Comp,投射, CV_L2, 0); if (距離<minimum &&距離 >0) { settings->params->eye1.eyefound = true; 極小值=距離; settings->params->eye1.distance =距離; settings->params->eye1.coords.x = x; settings->params->eye1.coords.y = y; } } } 極小值=邊際; 距離=邊際; // ** 即查尋右眼睛eye2 for (y=settings->params->eye2.ylimitDown; yparams->eye2.ylimitUp; y+=2) { for (x=settings->params->eye2.xlimitLeft; xparams->eye2.xlimitRight; x+=2) { cvSetImageROI (GRAYfaceImage, cvRect (x, y,圖像[0] - >width,圖像[0] - >height)); if (settings->params->varianceCheck == 1) { if (calculateSTD (GRAYfaceImage) <= (double) (settings->params->variance)) { cvResetImageROI (GRAYfaceImage); continue; } } cvFlip (GRAYfaceImage, Image2Comp, 0); cvResetImageROI (GRAYfaceImage); // ** 決定它是否是眼睛或not cvEigenDecomposite (Image2Comp, settings->params->nEigens, eigens, 00, averageImage,重量); cvEigenProjection (eigens, settings->params->nEigens, 00,重量、averageImage,投射); 距離= cvNorm (Image2Comp,投射, CV_L2, 0); if (距離<minimum &&距離 >0) { settings->params->eye2.eyefound = true; 極小值=距離; settings->params->eye2.distance =距離; settings->params->eye2.coords.x = x; settings->params->eye2.coords.y = y; } } } cvReleaseImage (&Image2Comp); // ** CleanupcvReleaseImage (&GRAYfaceImage);for (i=0; 我params->nImages; i++) cvReleaseImage (&images [i]);for (i=0; 我params->nImages; i++) cvReleaseImage (&eigens [i]); cvReleaseImage (&averageImage); cvReleaseImage (&projection); 釋放(圖像); 釋放(eigens); }

歷史

  • v 1.0 : 第一個版本 TrackEye
  • v 2.0 : 第二個版本 TrackEye
    • TrackEye 現在v2.0支持:
      • 二種不同面孔偵查算法:
      • 二種不同眼睛偵查算法:
      • 跟蹤算法可以由用戶選擇在過程初通過GUI。
      • 可選擇的輸入源:

    *请注意: TrackEye 寫了與 OpenCV 在改建期間,圖書館v3.1,因此保證使用它。

 

4月8日

4月7日 DHL 寄來的 MVP Award Box

Subject: [MVP]恭禧您成為第七屆第三回合微軟「最有價值專家」!!

 

親愛的微軟「最有價值專家」(MVP),您好︰

 

在歷經長達數星期的激烈競爭與評選,恭禧您從眾多優秀的競爭者中脫穎而出,成為微軟技術社群暨最有價值專家,第七屆第三回合微軟「最有價值專家」(Most Valuable Professional, MVP)!微軟最有價值專家暨社群 APAC, (Asia and Pacific)EMEA, (Europe, the Middle East and Africa) 總經理 Karen-Ann Young,帶領全微軟最有價值專家暨社群同仁,在此恭禧您!微軟「最有價值專家」(MVP)是贏得微軟技術社群討論區參與者肯定的最高榮譽!

MVP 證書

MVP Award Box



MVP CARD

MVP 徽章

MVP 禮物 : 藍牙工具包

3月24日

A Neural Network on GPU

 

A Neural Network on GPU

 
 

Introduction

An Artificial Neural Network is an information processing method that was inspired by the way biological nervous systems function, such as the brain, process information. It is composed of a large number of highly interconnected processing elements (neurons) working in unison to solve specific problems. Neural Networks have been widely used in "analogous" signal classifications, including handwriting, voice and image recognitions. Neural network can also be used in computer games. It enables games with the ability to adaptively learn from player behaviors. This technique has been used in racing games, such that opponent cars controlled by computer can learn how to drive from human players.

Since a Neural Network requires considerable number of vector and matrix operations to get results, it is very suitable to be implemented in a parallel programming model and run on Graphics Processing Units (GPUs). Our goal is to utilize and unleash the power of GPUs to boost the performance of a Neural Network solving handwriting recognition problems.

This project was originally our graphics architecture course project. We ran on GPU the same neural network described by Mike O'Neill in his brilliant article "Neural Network for Recognition of Handwritten Digits".

 

CadLib for creating DXF(Drawing Interchange Format) files

 

CadLib for creating DXF(Drawing Interchange Format) files

 
 
 

Introduction

What is DXF?

Drawing Interchange Format (DXF) files enable the interchange of drawings between AutoCAD and other programs. DXF files can be either ASCII or binary formats. Because ASCII DXF files are more common than the binary format, CadLib uses ASCII DXF format.

What is CadLib?

The CadLib is not a Computer Aided Design (CAD) program. It is a tool for creating DXF files that are used in the CAD programs. It consists of two parts. One of them is a Dynamic Link Library to create the DXF file. The other part is the programming interface. It is a class that integrates the cadio.dll functions. It can be used in Microsoft Visual C++ projects. In addition, the cadio.dll can be used in other Win32 programs.

Why use CadLib?

In some programs, it is needed to create a drawing output for use in other programs such as AutoCad. For example, in a "Building Detail Sheet Generator Program", the program needs to create a drawing output. And the most standard format for communicating drawing data is DXF.

DXF file structure

The DXF format is a tagged data representation of all the information contained in a drawing file. Tagged data means that each data element in the file is preceded by an integer number that is called a group code. A group code's value indicates what type of data element follows. This value also indicates the meaning of a data element for a given object (or record) type. Virtually all user-specified information in a drawing file can be represented in DXF format. (from AutoCad's DXF reference)

A DXF file consists of some sections. Each section has some drawing data in itself. The CadLib uses the following sections:

  1. HEADER
  2. TABLES
  3. BLOCKS
  4. ENTITIES

The main reference for DXF file structure that is used for CadLib is the AutoCad's DXF reference. You can find more information about DXF file structure here.

2月26日

在程式中開啟 檔案總管 (Using C#)

 

     // Starts Windows Explorer with two different command line arguments.
      ProcessStartInfo startInfo = new ProcessStartInfo("explorer.exe");

        // Opens a new single-pane Window for the default selection.
        // This is usually the root of the drive on which Windows is installed.

      startInfo.Arguments = "/n";         //  或 直接指定 資料夾路徑    startInfo.Arguments = "C:\\TEST\\";        

        Process.Start(startInfo);

2月14日

FTPClient.vb 原始碼

 
FTPClient.vb  原始碼
命名空間:    Utilities.FTP
 
下載點: 
 
2月1日

取得 目前系統 登入 的 使用者帳號 (C#)

  private void button1_Click(object sender, EventArgs e)
        {
            // 取得 目前系統 登入 的 使用者帳號
           String Us=System.Windows.Forms.SystemInformation.UserName;
           MessageBox.Show( "使用者帳號:"  + Us);
         }
. . .
1月30日

加入參考 System.Design 組件 (.NET)

 
 方案總管  ->  右鍵選單  ->  加入參考
 
Add System.Design
 

命名空間: System.ComponentModel.Design
組件: System.Design (在 system.design.dll 中)

System.ComponentModel.Design 命名空間 (Namespace) 包含的類別,可供開發人員用來建置 (Build) 元件的自訂設計階段行為以及在設計階段設定元件的使用者介面。設計階段環境提供讓開發人員排列元件和設定其屬性的系統。有些元件可能需要僅適用設計階段的行為,才能在設計階段環境中正常作用。提供協助開發人員設定元件或複雜資料型別值的自訂使用者介面可能也頗有價值。在此命名空間內定義的類別和介面,也可以用來建置元件的自訂設計階段行為、存取設計階段服務以及實作自訂的設計階段組態介面

說明文件

http://msdn2.microsoft.com/zh-tw/library/system.componentmodel.design(VS.80).aspx

 
1月25日

取得網路磁碟機及其路徑的對照 (C#)

//  Get UNC Path
 

    [DllImport("mpr.dll")]
        [return: MarshalAs(UnmanagedType.U4)]
        static extern int WNetGetUniversalName(
                string lpLocalPath,
                [MarshalAs(UnmanagedType.U4)] int dwInfoLevel,
                IntPtr lpBuffer,
                [MarshalAs(UnmanagedType.U4)] ref int lpBufferSize);

       [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode), Serializable()]
        class MyUNC
        {
                [MarshalAs(UnmanagedType.LPStr)]
                public string UniversalName;
                [MarshalAs(UnmanagedType.LPStr)]
                public string ConnectionName;
                [MarshalAs(UnmanagedType.LPStr)]
                public string RemainingPath;
        }
        [STAThread]
        static void Main()
        {
                int bufferSize = 2000;
                IntPtr buffer = Marshal.AllocHGlobal(bufferSize);
                int ret = WNetGetUniversalName("Z:", 2, buffer, ref bufferSize);
                if (ret == 0)
                {
                        MyUNC unc = new MyUNC();
                        Marshal.PtrToStructure(buffer, unc);
                        Console.WriteLine(unc.UniversalName);
                }
                Marshal.FreeHGlobal(buffer);
                return;
        }

 說明文件

說明文件

===============================
範例2
 
Converting network drive-based path to universal path name

'The following code shows how to use the WNetGetUniversalName for converting
'network drive-based path (Like I:\windows) to universal path name (Like \\MyComputer\c\windows)
'
Private Declare Function WNetGetUniversalName Lib "mpr" Alias "WNetGetUniversalNameA" _
(ByVal lpLocalPath As String, ByVal dwInfoLevel As Long, lpBuffer As Any, lpBufferSize As Long) As Long

Private Const UNIVERSAL_NAME_INFO_LEVEL = 1
Private Const REMOTE_NAME_INFO_LEVEL = 2
Private Const UNIVERSAL_NAME_BUFFER_SIZE = 1000
Private Const NO_ERROR = 0

Private Type UNIVERSAL_NAME_INFO
    lpUniversalName                         As Long
    buf(UNIVERSAL_NAME_BUFFER_SIZE - 4)     As Byte
End Type

Private Sub cmdGetUniversal_Click()
    Dim BufSize         As Long
    Dim uni             As UNIVERSAL_NAME_INFO
    
    BufSize = UNIVERSAL_NAME_BUFFER_SIZE
    If WNetGetUniversalName(txtPath.Text, UNIVERSAL_NAME_INFO_LEVEL, uni, BufSize) = NO_ERROR Then
        'After we return from WNetGetUniversalName, the lpUniversalName contains a pointer for the 
	'universal path name.
        'The pointer is usually points to the first byte of the buffer array 
	'(buf variable in UNIVERSAL_NAME_INFO ).
        
	'Just to be safe, I calculate the exact location of the string in the buffer, 
	'by the following expression: (The result is always 1)
        StartLoc = uni.lpUniversalName - VarPtr(uni) - 3
        txtUniversal.Text = Mid$(StrConv(uni.buf, vbUnicode), StartLoc)
    Else
        MsgBox "Error: cannot find the universal path of " & txtPath.Text, vbOKOnly Or vbExclamation, ""
    End If
    
End Sub


 
 
1月23日

取得 電腦中已安裝的 序列埠 數量 (Using VC++ 2008 MFC)

 
//  GET   SERIAL PORTS
 
   void  CMFC_Dlg::OnBnClicked()
{
 
    long   lReturn   =   0;    
     HKEY   hk;  
     LPCTSTR   data_Get = _T("HARDWARE\\DEVICEMAP\\SERIALCOMM");  
      //在註冊表裡的位置  
    lReturn   =   ::RegOpenKeyEx(HKEY_LOCAL_MACHINE,data_Get,0,KEY_READ,&hk);  
 
    //通過ERROR_SUCCESS判斷打開是否成功。    
 if(lReturn   !=   ERROR_SUCCESS)  
      MessageBox(_T("打開註冊表1出現錯誤!"), _T("錯誤"));  
 else{  
     DWORD NumValues;
     ::RegQueryInfoKey(hk,0,0,0,0,0,0,&NumValues,0,0,0,0);
 
      CString  str_ComPortNum;
     str_ComPortNum.Format(_T("Com Port Num=%d"), NumValues);

  
    AfxMessageBox(str_ComPortNum);
   }
  ::RegCloseKey(hk);

}
 
 
說明文件

RegOpenKeyEx Function (Windows)

 

RegQueryInfoKey Function (Windows)

 
 
1月22日

.NET 取得 執行檔 的 起始路徑(C#)

 
 
        private void button1_Click(object sender, EventArgs e)
        {        
            MessageBox.Show(Application.StartupPath);            
        }
 
 
說明文件:

Application.StartupPath 屬性(System.Windows.Forms)

12月17日

在 對話方塊 標題列 上 加入 圖示

 
DialogBox  Title Bar   Add  ICON  
 

 

程式碼區塊

 

#include "resource.h"
#include <windows.h>
#include <stdio.h>

BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);

HWND g_Dlg_hWnd     = NULL; 
HICON  hIcon1;


int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{

 hIcon1 =  (HICON) LoadImage( hInstance, MAKEINTRESOURCE(IDI_ICON1),  IMAGE_ICON,
  16,
  16,
  LR_DEFAULTSIZE);


 HRESULT      hr;
 DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), NULL, (DLGPROC)DialogProc);
 return 1;
}

 

BOOL CALLBACK DialogProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{


 switch(uMsg)
 {
 case WM_INITDIALOG: 
  
 SendMessage(hWnd, WM_SETICON, ICON_SMALL, (LPARAM) hIcon1 );


  g_Dlg_hWnd = hWnd;
  break;
 case WM_COMMAND:
  break;
 case WM_CLOSE:
  DestroyWindow(hWnd);
  break;
 }
 return FALSE;
}

 

 

 
VC_DIALOG_ADD_ICON
12月13日

MultiByte To WideChar (使用 VC++ )

VC_MultiByteToWideChar
 
             wchar_t szwBuffer[128];
             char *pszAnsi = "中文Ansi string\n中文";
             MultiByteToWideChar(CP_ACP, 0, pszAnsi, -1, szwBuffer, 128);

 
12月11日

VB.NET 在 執行時期 顯示 屬性編輯視窗

RunTIME_PropertyGrid
 
 
Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim PG As New System.Windows.Forms.PropertyGrid()
        Dim PGW As New Form
        PGW.Owner = Me
        PGW.StartPosition = FormStartPosition.Manual
        PGW.Left = Me.Left + Me.Width
        PGW.Top = Me.Top
        PGW.ShowInTaskbar = False

        PGW.Controls.Add(PG)
        PG.Dock = DockStyle.Fill
        PG.SelectedObject = Me.Label1
        PGW.Text = "Label1 的 屬性編輯視窗"
        PGW.Show()
    End Sub
End Class
 
 
11月23日

讀取檔案中的數字並統計出現次數- 使用 VB.NET

  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim DataStr As String
        Dim NumStr As String

        Dim re As System.IO.StreamReader = System.IO.File.OpenText("C:\DBS.txt")

        Dim NumDict As New Dictionary(Of String, Integer)()


        Dim input As String = Nothing

        Do
            input = re.ReadLine()

            If Not input Is Nothing Then

                Dim s As String() = input.Split(","c)

                If s.Length = 2 Then
                    DataStr = s(0)
                    NumStr = s(1)
                    If Not NumDict.ContainsKey(NumStr) Then
                        NumDict.Add(NumStr, 1)
                    Else
                        NumDict(NumStr) += 1
                    End If
                End If
            End If

        Loop Until input Is Nothing


        re.Close()

        Dim msg As String = "統計:" + Environment.NewLine
        Dim count As Integer

        For Each ks As String In NumDict.Keys
            count = NumDict(ks)
            msg = msg + ks + "出現" + count.ToString() + Environment.NewLine
        Next

        MessageBox.Show(msg)
    End Sub

===============