You are on page 1of 4

S dng OpenCV v DirectShow trong Visual C++ 6.

To mt Project c tn bt k(kiu Dialog Based), chng hn tn l AzC

Trong file AzCDlg.h, trong phn nh ngha Include, trc phn nh ngha lp CAzCDlg, chng ta thm cc
header files sau y:
#include "cv.h"
#include "highgui.h"
#include "DShow.h"
#include "initguid.h"
Le Khanh Thanh Computer Vision Software Group __ Le Khanh Thanh CVSG

#include "vector"
#pragma comment (lib,"strmiids.lib")
#pragma comment (lib,"quartz.lib")
using namespace std;

#define PI 3.1415926535897932384626433832795
#define SAFE_RELEASE(p){if(p){(p)->Release();(p)=NULL;}}

Trong file AzCDlg.cpp, ta thm on code sau trn phn khai trin lp CazCDlg.h nh sau:

#include "stdlib.h"
#include "string.h"
#include "cv.h"
#include "highgui.h"
#include "cvcam.h"
#include "DShow.h"
#include "initguid.h"
#include "math.h"
#if !defined iProxyTrans_h
#include "iProxyTrans.h"
#endif

#if !defined ProxyTransuids_h


#include "ProxyTransuids.h"
#endif

#pragma comment (lib,"cvcam.lib")


void callback(void* imgCallback){
CAzCDlg* dlgcam=(CAzCDlg*)AfxGetApp()->m_pMainWnd;
dlgcam->lktCallbackCam((IplImage*)imgCallback);
}

: Hm callback l hm c gi li trong b lc ProxyTrans, hm ny l hm ngoi lp CAzCDlg , n gip


bn c th to lin kt vi lp CazCDlg khi bn mun v hnh nh thu c t Graph ln Dialog ca bn.
Tip theo, t Project->Settings, hp thoi Project Settings xut hin, chn tab C/C++. Trn tab ny, t
Catergory tr xung, bn chn Preprocessor. Sau , bn thm cc ng dn sau vo hp hp text: Additional
Include Directories
- C:\Program Files\OpenCV\cv\include
- C:\Program Files\OpenCV\cxcore\include
- C:\Program Files\OpenCV\cvaux\include
- C:\Program Files\OpenCV\otherlibs\cvcam\include
- C:\Program Files\OpenCV\otherlibs\highgui
Ch : Cc ng dn trn ph thuc vo vic OpenCV c ci u, y OpenCV c ci
C:\Program Files\. Nu OpenCV c ci ng gin khc th cc ng gin trn cng s thay i theo.
Bn s nhn thy trc tip cc ng gin trn c thm vo Project Options bn di:
Le Khanh Thanh Computer Vision Software Group __ Le Khanh Thanh CVSG

Tip theo, cng trong hp thoi Project Settings, chng ta chuyn sang chn tab Link. Trn tab ny, trog
Category tr xung, chn General. Trong hp text Object/Library modules, ta nhp cc thu vin sau vo v
nhn Enter kt thc:
- cv.lib
- cxcore.lib
- highgui.lib
- cvcam.lib
- cxts.lib
- trs.lib
Hp thoi trng nh sau:
Le Khanh Thanh Computer Vision Software Group __ Le Khanh Thanh CVSG

Tip theo, t Tools->Options, hp thoi Options xut hin, chn tab Directories, gi nguyn mc nh cho
Platform, trong Show directories for tr xung, chn Include files. Tng ng vi Include files th Directories
bn di, chng ta thm cc ng dn sau(nu bn bit cc ci t cn thm nm u _ nu khng bit, bn
c th nhn chut vo tn cng ca hng tm ng gin ti ).
- C:\DXSDK\Include
- C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE
- C:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE
- C:\Program Files\Microsoft Visual Studio\VC98\ATL\INCLUDE
- C:\PROGRAM FILES\OPENCV\CV\INCLUDE
- C:\PROGRAM FILES\OPENCV\CVAUX\INCLUDE
- C:\PROGRAM FILES\OPENCV\CXCORE\INCLUDE
- C:\PROGRAM FILES\OPENCV\FILTERS\PROXYTRANS
- C:\PROGRAM FILES\OPENCV\OTHERLIBS\CVCAM\INCLUDE
- C:\PROGRAM FILES\OPENCV\OTHERLIBS\HIGHGUI
: Ch l cc ng dn mu xanh dng l cc ng gin c trc khi ci Visual C++
Bn c th quan st tab ny nh di y:
Le Khanh Thanh Computer Vision Software Group __ Le Khanh Thanh CVSG

Cng t tab Directories xung, chn Library Files, Directories bn di, thm cc ng dn sau nh i
vi Include files.
- C:\DXSDK\Lib
- C:\Program Files\Microsoft Visual Studio\VC98\LIB
- C:\Program Files\Microsoft Visual Studio\VC98\MFC\LIB
- C:\PROGRAM FILES\OPENCV\LIB
: Cc dng mu xanh dng l cc dng c trc .

Nhn OK kt thc qu trn ci t OpenCV v DirectShow trong mt ng dng Visual C++.

You might also like