投影筆源代碼參考模板_第1頁(yè)
投影筆源代碼參考模板_第2頁(yè)
投影筆源代碼參考模板_第3頁(yè)
投影筆源代碼參考模板_第4頁(yè)
投影筆源代碼參考模板_第5頁(yè)
已閱讀5頁(yè),還剩4頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、投影筆源代碼/本程由Borland C+ Builder6編寫(xiě),在XP sp2+bcb6+PowerPoint 下運(yùn)行通過(guò)/目前僅為測(cè)試版本,下一步將完成兩個(gè)功能的融合,最終實(shí)現(xiàn)完美程序/Unit1.h#ifndef Unit1H#define Unit1H/-#include #include #include #include #include #include #include /-class TForm1 : public TForm_published:/ IDE-managed Components TButton *btnCChose; TButton *btnPBegin; T

2、Button *btnPEnd; TButton *btnFmt; TButton *btnIEnd; TTimer *Timer1; TButton *btnIBegin; TTimer *Timer2; TComboBox *ComboBox1; TPanel *Panel1; void _fastcall btnCChoseClick(TObject *Sender); void _fastcall btnPBeginClick(TObject *Sender); void _fastcall btnPEndClick(TObject *Sender); void _fastcall b

3、tnFmtClick(TObject *Sender); void _fastcall btnIEndClick(TObject *Sender); void _fastcall Timer1Timer(TObject *Sender); void _fastcall FormCreate(TObject *Sender); void _fastcall CamCreate(TObject *Sender); void _fastcall btnIBeginClick(TObject *Sender); void _fastcall Timer2Timer(TObject *Sender);p

4、rivate:/ User declarations Graphics:TBitmap *pBitmap;public:/ User declarations _fastcall TForm1(TComponent* Owner);/-extern PACKAGE TForm1 *Form1;1 / 9typedef struct Byte Blue; Byte Green; Byte Red; RGBCOLOR;/-#endif/Unit1.cpp#include #pragma hdrstop#include Unit1.h#include vfw.h#include #include #

5、include #include #define IMGHEIGHT 480#define IMGWIDTH 640#define BLKHEIGHT 38#define BLKWIDTH 38#define SQR 10/-#pragma package(smart_init)#pragma resource *.dfmTForm1 *Form1;int i,j,k,m;int tmpc=0;/Byte VarL,VarR,V=80; /全局變量 ,定義在此,防止覆蓋int ImageHeight=480;int ImageWidth=640;RGBCOLOR* ptr1;RGBCOLOR*

6、 ptr2;RGBCOLOR dataImgIMGHEIGHTIMGWIDTH;RGBCOLOR* ptr3;/BYTE* ptr;/LPVIDEOHDR CaptureData;/int cmpcount;/RGBCOLOR dataLeftBLKHEIGHTBLKWIDTH;/RGBCOLOR dataRightBLKHEIGHTBLKWIDTH;/RGBCOLOR dataSqrSQRSQR;double R,dbMaxL,dbMaxR,dSL,dSR,dSS;Byte bPL,bPR;Byte bPT=255; /核像素取值double dST=(double)(BLKHEIGHT)*

7、(BLKWIDTH)*bPT*bPT;double dbMaxV=0.162;/閾值選取,0到1之間double dbErr=1e-3;/double型為零的下限,與dbMaxV的位數(shù)有關(guān)HWND hWndC;HWND hwndPPT=NULL;CAPDRIVERCAPS CapDrvCaps;CAPSTATUS CapStatus;int DFlag;/-_fastcall TForm1:TForm1(TComponent* Owner) : TForm(Owner) pBitmap=NULL; Timer1-Enabled=false; Timer2-Enabled=false;/-voi

8、d _fastcall TForm1:FormCreate(TObject *Sender) char szDeviceName100; char szDeviceVersion100; for (int wIndex = 0; wIndex Items-Add(szDeviceName); /combobox1 if(ComboBox1-Items-Count0) ComboBox1-ItemIndex=0; else ShowMessage(沒(méi)有找到視頻軟件); Close(); CamCreate(NULL);/-void _fastcall TForm1:CamCreate(TObje

9、ct *Sender) hWndC = capCreateCaptureWindow ( (LPSTR) My Capture Window, WS_CHILD | WS_VISIBLE, / window style 0, 0, 640, 480, / window position and dimensions (HWND)Panel1-Handle,/(HWND)Application-Handle,/(HWND) hwndParent, ComboBox1-ItemIndex+1);/(int) nID /* child ID */); /連接設(shè)備: capDriverConnect(

10、hWndC,0); capPreviewRate(hWndC, 50); / rate, in milliseconds capPreview(hWndC, TRUE); / starts preview /獲取視頻驅(qū)動(dòng)相關(guān)性能 capDriverGetCaps(hWndC, &CapDrvCaps, sizeof (CAPDRIVERCAPS); /獲取捕獲窗口狀態(tài) capGetStatus(hWndC, &CapStatus, sizeof (CAPSTATUS); SetWindowPos(hWndC, NULL, 0, 0, CapStatus.uiImageWidth, CapSta

11、tus.uiImageHeight, SWP_NOZORDER | SWP_NOMOVE); /capSetCallbackOnFrame(hWndC,&FrameCallBack);/-void _fastcall TForm1:btnCChoseClick(TObject *Sender) / Video source dialog box. if (CapDrvCaps.fHasDlgVideoSource) capDlgVideoSource(hWndC);/-void _fastcall TForm1:btnPBeginClick(TObject *Sender) hwndPPT=F

12、indWindow(screenClass,NULL); hwndPPT=FindWindowEx(hwndPPT,NULL,paneClassDC,NULL); DFlag=0; /if(SaveDialog2-Execute() AnsiString FileName=GetCurrentDir(); /capFileSaveDIB( hWndC, (SaveDialog2-FileName+.bmp).c_str() ); /截取當(dāng)前幀 capGrabFrameNoStop(hWndC);/截取當(dāng)前幀到緩存里 capFileSaveDIB( hWndC, (FileName+Captur

13、e.bmp).c_str() ); /截取當(dāng)前幀 if(!pBitmap) pBitmap=new Graphics:TBitmap; try pBitmap-LoadFromFile(FileName+Capture.bmp); catch(.) ShowMessage(Could not load bmp); delete pBitmap; pBitmap=NULL; /開(kāi)始識(shí)別圖像 dbMaxL=0.0;for(i=ImageHeight-BLKHEIGHT;iScanLinei); for(j=0;jRed+(ptr1+j)-Green+(ptr1+j)-Blue)/3; dSL+=(

14、double)bPL*bPL; dSS+=(double)bPL*bPT; R=(double)(dSS/(sqrt(dSL)*sqrt(dST); if(RdbMaxL) dbMaxL=R;dbMaxR=0.0,R=0.0;for(i=ImageHeight-BLKHEIGHT;iScanLinei); for(j=ImageWidth-BLKWIDTH;jRed+(ptr2+j)-Green+(ptr2+j)-Blue)/3; dSR+=(double)bPR*bPR; dSS+=(double)bPR*bPT; R=(double)(dSS/(sqrt(dSR)*sqrt(double)

15、dST); if(RdbMaxR) dbMaxR=R;/開(kāi)始識(shí)別區(qū)域if(dbMaxV-dbMaxLdbErr)&(dbMaxR-dbMaxLdbErr) DFlag=1; else if(dbMaxV-dbMaxRdbErr) DFlag=2; /圖像識(shí)別結(jié)束,開(kāi)始控制ppt if(hwndPPT&(DFlag=1) /前翻頁(yè) SetForegroundWindow(hwndPPT); keybd_event( VK_UP,0x45,KEYEVENTF_EXTENDEDKEY | 0,0); /Sleep(500); /SetForegroundWindow(Form1-Handle); i

16、f(hwndPPT&(DFlag=2) /后翻頁(yè) SetForegroundWindow(hwndPPT); keybd_event( VK_DOWN,0x45,KEYEVENTF_EXTENDEDKEY |0,0); /Sleep(500); /SetForegroundWindow(Form1-Handle); Timer1-Enabled=true;/-void _fastcall TForm1:btnPEndClick(TObject *Sender)Timer1-Enabled=false;/-void _fastcall TForm1:btnFmtClick(TObject *Se

17、nder) / Video format dialog box. if (CapDrvCaps.fHasDlgVideoFormat) capDlgVideoFormat(hWndC); / Are there new image dimensions? capGetStatus(hWndC, &CapStatus, sizeof (CAPSTATUS); SetWindowPos(hWndC, NULL, 0, 0, CapStatus.uiImageWidth, CapStatus.uiImageHeight, SWP_NOZORDER | SWP_NOMOVE); /-void _fas

18、tcall TForm1:Timer1Timer(TObject *Sender) /Timer1-Enabled=false; btnPBeginClick(this); /Timer1-Enabled=true;void _fastcall TForm1:btnIEndClick(TObject *Sender) Timer2-Enabled=false;/-void _fastcall TForm1:btnIBeginClick(TObject *Sender) hwndPPT=FindWindow(screenClass,NULL); hwndPPT=FindWindowEx(hwnd

19、PPT,NULL,paneClassDC,NULL); int redCount=0; char strText20; AnsiString FileName=GetCurrentDir(); capGrabFrameNoStop(hWndC); capFileSaveDIB( hWndC, (FileName+.bmp).c_str(); /截取當(dāng)前幀 if(!pBitmap) pBitmap=new Graphics:TBitmap; try pBitmap-LoadFromFile(FileName+.bmp); catch(.) ShowMessage(Could not load bmp); delete pBitmap; pBitmap=NULL; /開(kāi)始識(shí)別圖像 區(qū)域識(shí)別 for(i=0;iScanLinei); for(j=0;jBlue; dataImgij.Green=(ptr3+j)-Green; dataImgij.Red=(ptr3+j)-Red; redCount=0; for(i=0;iImage

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論