?? opencv 中文技術(shù)資料 之 常見問題及解決方法 .txt
字號:
OPenCV 中文技術(shù)資料 之 常見問題及解決方法
作 者: twinboys
所屬分類: 圖像知識
點擊次數(shù): 24
發(fā)表時間: 2005-10-25
內(nèi)容概要: OPenCV 技術(shù)資料是英文的,對于很多英文不是很好的朋友來說,讀起來會很吃力,我就是這樣感覺的,所以,在網(wǎng)上搜集了中文資料,與大家一起分享
常見問題及解決方法
如何正確安裝 OpenCV ?
閱讀 安裝指南
如何快速認(rèn)識 OpenCV ?
參考 樣例。
在 Visual Studio 中加載 OpenCV workspace:
opencv.dsw for Microsoft Visual Studio 6.0
opencv.sln for Miscrosoft Visual Studio .NET 2003
cbuilderx/opencv.bpgr for Borland C++ BuilderX
選擇 cvsample 項目,編譯并運行。閱讀代碼并且按照自己的想法更改它。
也可通讀 參考手冊 - 里面也包含一些樣例代碼.
搜索 http://groups.yahoo.com/group/OpenCV 中的 OpenCV archives,選擇你興趣的主題。
從 scratch 創(chuàng)建新的項目,或者修改現(xiàn)有的 cvsample。 對 Microsoft Visual Studio 有現(xiàn)成的向?qū)韯?chuàng)建 OPENCV 項目。
哪里可以報告OPENCV的Bug ?
發(fā)郵件到 OpenCV@yahoogroups.com Subject: BUG <....your title...>
怎么報告 Intel?Ingegrated Performance Primitives 的BUG?
發(fā)郵件到 developer_support@intel.com
怎么加入 OpenCV 論壇?
發(fā)郵件 OpenCV-subscribe@yahoogroups.com, 如果你是 YAHOO GROUP 的成員并且已經(jīng)登陸。你可以在 http://groups.yahoo.com/group/OpenCV 中閱讀論壇內(nèi)容。
NOTE: 上海阿須數(shù)碼技術(shù)有限公司 設(shè)立了一個 中文OPENCV論壇,可以在那里找到很多有用資料。
怎么修改用戶組設(shè)置使得不再收到大量郵件?
想實時接收郵件或一天只接收一次郵件摘要,可以訪問 http://groups.yahoo.com/mygroups 然后更改設(shè)置。
好,我發(fā)現(xiàn)用戶組一點沒用。如何退掉我訂閱的郵件列表?
發(fā)郵件到 OpenCV-unsubscribe@yahoogroups.com ,主題 subject 為[OpenCV]
當(dāng)同時使用 OpenCV 和 IPL,發(fā)生編譯錯誤。怎么解決這個問題?
為了完全獨立于 IPL (INTEL的圖像處理庫), OpenCV 復(fù)制了 IplImage 和其它一些結(jié)構(gòu)變量的聲明。 在 OpenCV 頭前面定義 HAVE_IPL 或者將語句 "#include <ipl.h>" 放置于 OpenCV 頭文件的前面,可以解決這個沖突。
OpenCV 可以工作在其它處理器下嗎?
是的,OpenCV 本身是開發(fā)源代碼的,而且在32位平臺上非常緊湊。從另外一方面看,如果采用 INTEL 處理器,那么依靠 IPP ,OpenCV 可以運行得更快。
當(dāng)我試圖編譯其中的應(yīng)用程序時,得到錯誤:streams.h 沒有發(fā)現(xiàn).
你需要 DirectShow SDK ,它是 DirectX SDK 的一個部分。
從 msdn.microsoft.com/directx/ 下載 DirectX,(文件很大,但是可以只下載部分)。如果不能正常工作,考慮一下 HighGUI 利用 VFW 或 MIL 來撲捉視頻序列。
帶樣例安裝 (TOGETHER WITH SAMPLES.)
打開項目 <DirectXSDKInstallFolder>\samples\C++\DirectShow\BaseClasses\baseclasses.
{dsw|sln}. 如果沒有這個文件,要么是你沒有下載樣例,要么是路徑不對。
編譯建立 Release 和 Debug 版本
將產(chǎn)生的庫 (在 DirectX 9.x 中,分別叫 strmbase.lib 和 strmbasd.lib) 拷貝到目錄 <DirectXSDKInstallFolder>\lib 下。
在 Developer Studio 添加路徑:
<DirectXSDKInstallFolder>\include
<DirectXSDKInstallFolder>\samples\C++\DirectShow\BaseClasses
到 includes" 搜索路徑中 (在 Tools->Options->Directories->Include files in case of Developer Studio 6.0)
添加 <DirectXSDKInstallFolder>\lib 到庫搜索路徑中 (在 Tools->Options->Directories->Library files in case of Developer Studio 6.0)
注意: 將上面增加的東東添加到最頂端,否則還會出現(xiàn)編譯或鏈接錯誤。因為 Developer Studio 6.0 包含了一些老版本的 DirectX 頭文件和庫文件,它們與新版本有沖突。
大功告成!
安裝了 DirectX SDK 后,仍然有鏈接錯誤,提示:undefined or redefined "TransInPlace" filter class constructors etc.
閱讀前面的示范,特別注意搜索目錄的次序。
當(dāng)我試圖使用 cvcam, 程序崩潰
確保注冊了 ProxyTrans.ax 和 SyncFilter.ax
怎么注冊 *.ax (DirectShow filter)?
運行文件 regsvr32.exe
Filter 不能被注冊 (regsvr32 報告錯誤)
最可能的原因是 filter 需要的一些 DLLs 不在路徑中,這種情況下,OpenCV 可以確保 <OpenInstallFolder>\bin 在路徑中。
cxcore096d.dll 或 cxcored.lib 好像丟失了
cxcore096d.dll 是 cxcore DLL 的 DEBUG 版本,cxcored.lib 是 cxcore096d.dll 的輸入庫。打開Open OpenCV workspace, 選擇 "cxcore" 作為 active project,并且選擇 "Win32 Debug" 的配置. 編譯建立庫,這樣就得到 bin\cxcore096d.dll 和 lib\cxcored.lib。 同樣步驟可以生成其它所有的 OpenCV 組件。加 d 表示 Debug 版本。
當(dāng)我編譯 HighGUI ,得到錯誤 "mil.h is not found"
mil.h 是 Matrox Imaging Library (MIL) 的一個部分,提供 Matrox (或兼容) 視頻采集卡,如 Meteor, Meteor II 等
If you have such a framegrabber and MIL installed, add mil\include and mil\lib to the search paths within Developer Studio (submenu Tools->Options->Directories).
If you do not have MIL, just ignore the error. The file mil.h is only required to build MIL-aware version of Highgui "Win32 MIL Debug" or "Win32 MIL Release". Select "Win32 Debug" or "Win32 Release" configuration of highgui (submenu Build->Set Active Configuration...) instead - these versions of highgui can still be used to grab video via VFW interface, work with AVIs and still images.
怎樣調(diào)試 DirectShow filter?
打開帶 FILTER 的 workspace (e.g. opencv.dsw),
選擇 filter 作為活動項目,建立 debug 配置,
注冊 filter 的 debug 版本(即運行 regsvr32 camshiftd.ax) (只需要做一次就可以了,注冊表里僅保存 filter 的文件名),
回到 Developer Studio 然后開始 debugging 過程 (F5). 在提示 “do you want to run to debug the module”下,選擇 camshiftdemo 通過 camshift.ax 和 DirectX SDK 工具圖形編輯器 graphedit 來調(diào)試 DirectShow filter.
在 graphedit 中建立 filter 圖 (即 camera->camshift->renderer)
保存 graph (下次簡單加載就可以了)
在filter中的變換方法或其它位置設(shè)置斷點.
運行 filter ,并且。。。
怎么創(chuàng)建一個 DeveloperStudio 項目來開始玩 OpenCV
(注意: 這是一個應(yīng)用答案)
為了在 Developer Studio 下創(chuàng)建基于 OpenCV 的項目,按如下步驟進(jìn)行:
在 Developer Studio 中創(chuàng)建新的應(yīng)用程序:
選擇菜單 "File"->"New..."->"Projects" . 選擇 "Win32 Application" 或 "Win32 console application" - 后者是更簡單的方法。
鍵入項目名稱,并且選擇存儲位置
可以為項目創(chuàng)建一個單獨的 workspace ("Create new workspace") , 也可以將新的項目加入到當(dāng)前的 workspace 中 ("Add to current workspace").
單擊 "next"
選擇 "An empty project", 點擊 "Finish", "OK".
經(jīng)過以上步驟,Developer Studio 會創(chuàng)建一個項目目錄 (缺省情況下,目錄名就是項目名), <project name>.dsp 文件以及<project name>.dsw,.ncb ... ,如果你創(chuàng)建自己的workspace.
添加文件到 project 中:
選擇菜單"File"->"New..."->"Files" .
選擇"C++ Source File", 鍵入文件名,點擊"OK"
增加 OpenCV 相關(guān)的 頭文件目錄 #include :
#include "cv.h"
/* #inlcude "cvaux.h" // experimental stuff (if need) */
#include "highgui.h"
或者你可以拷貝部分已有的文件 (如:opencv\samples\c\morphology.c) 到項目目錄中,打開它,并且加入到項目中 (右鍵點擊編輯器的視圖 -> "Insert File into Project" -> <your project name> ).
配置項目:
選擇菜單"Project"->"Settings..."以激活項目配置對話框 .
在左邊選擇你的項目.
調(diào)節(jié)設(shè)置,對 Release 和 Debug 配置都有效:
選擇 "Settings For:"->"All Configurations"
選擇 "C/C++" tab -> "Preprocessor" category -> "Additional Include Directories:". 加入用逗號分隔的相對路徑 (對文件 .dsp 而言) 或絕對路徑 opencv\cxcore\include, opencv\cv\include, opencv\otherlibs\highgui 以及可選的 optionally, opencv\cvaux\include.
選擇 "Link" tab -> "Input" category -> "Additional library path:". 加入輸入庫所在的路徑 (cxcore[d].lib cv[d].lib hihghui[d].lib cvaux[d].lib)
調(diào)節(jié) "Debug" 配置:
選擇 "Settings For:"->"Win32 Debug".
選擇 "Link" tab -> "General" category -> "Object/library modules". 加入空格分隔的 cvd.lib, highguid.lib, cvauxd.lib (optionally)
可以改變輸出文件的名稱和位置。如想把產(chǎn)生的 .exe 文件放置于項目目錄而不是Debug/ 子目錄下,可在 "Link" tab -> "General" category -> "Output file name:" 中鍵入 ./<exe-name>d.exe
調(diào)節(jié) "Release" 配置
選擇 "Settings For:"->"Win32 Release".
選擇 "Link" tab -> "General" category -> "Object/library modules". 加入空格分隔的 cv.lib, highgui.lib, cvaux.lib (optionally)
增加從屬性項目到 workspace 中:
選擇菜單: "Project" -> "Insert project into workspace".
選擇 opencv\cv\make\cv.dsp.
同樣步驟對 opencv\cvaux\make\cvaux.dsp, opencv\otherlibs\highgui\highgui.dsp.
設(shè)置從屬性:
選擇菜單: "Project" -> "Dependencies..."
對 "cv" 選擇 "cxcore",
對 "cvaux" 選擇 "cv", "cxcore",
對 "highgui" 選擇 "cxcore",
對你的項目,選擇所有的: "cxcore", "cv", "cvaux", "highgui".
從屬性配置保證了在源代碼被改變的情況下,自動重新編譯 opencv 庫.
就這么多。可以編譯并且運行一切了。
怎么訪問圖像元素
(坐標(biāo)起點相對于圖像原點 image origin 從 0 開始,或者是左上角 (img->origin=IPL_ORIGIN_TL) 或者是左下角 (img->origin=IPL_ORIGIN_BL)
假設(shè)有 8-bit 1-通道的圖像 I (IplImage* img):
I(x,y) ~ ((uchar*)(img->imageData + img->widthStep*y))[x]
假設(shè)有 8-bit 3-通道的圖像 I (IplImage* img):
I(x,y)blue ~ ((uchar*)(img->imageData + img->widthStep*y))[x*3]
I(x,y)green ~ ((uchar*)(img->imageData + img->widthStep*y))[x*3+1]
I(x,y)red ~ ((uchar*)(img->imageData + img->widthStep*y))[x*3+2]
如果增加點 (100,100) 的亮度 30 ,那么可以:
CvPoint pt = {100,100};
((uchar*)(img->imageData + img->widthStep*pt.y))[pt.x*3] += 30;
((uchar*)(img->imageData + img->widthStep*pt.y))[pt.x*3+1] += 30;
((uchar*)(img->imageData + img->widthStep*pt.y))[pt.x*3+2] += 30;
或者更有效的
CvPoint pt = {100,100};
uchar* temp_ptr = &((uchar*)(img->imageData + img->widthStep*pt.y))[x*3];
temp_ptr[0] += 30;
temp_ptr[1] += 30;
temp_ptr[2] += 30;
假設(shè)有 32-bit 浮點數(shù), 1-通道 圖像 I (IplImage* img):
I(x,y) ~ ((float*)(img->imageData + img->widthStep*y))[x]
現(xiàn)在,通用方法:假設(shè)有 N-通道,類型為 T 的圖像:
I(x,y)c ~ ((T*)(img->imageData + img->widthStep*y))[x*N + c]
或者你可使用宏 CV_IMAGE_ELEM( image_header, elemtype, y, x_Nc )
I(x,y)c ~ CV_IMAGE_ELEM( img, T, y, x*N + c )
也有針對各種圖像(包括 4-通道)和矩陣的函數(shù)(cvGet2D, cvSet2D), 但是它們都很慢.
如何訪問矩陣元素?
方法是類似的 (都是針對 0 起點的列和行)
設(shè)有 32-bit 浮點數(shù)的實數(shù)矩陣 M (CvMat* mat):
M(i,j) ~ ((float*)(mat->data.ptr + mat->step*i))[j]
設(shè)有 64-bit 浮點數(shù)的復(fù)數(shù)矩陣 M (CvMat* mat):
Re M(i,j) ~ ((double*)(mat->data.ptr + mat->step*i))[j*2]
Im M(i,j) ~ ((double*)(mat->data.ptr + mat->step*i))[j*2+1]
設(shè)有單通道矩陣,有宏 CV_MAT_ELEM( matrix, elemtype, row, col ), 例如對 32-bit 浮點數(shù)的實數(shù)矩陣
M(i,j) ~ CV_MAT_ELEM( mat, float, i, j ),
假如初始化 3x3 單位陣:
CV_MAT_ELEM( mat, float, 0, 0 ) = 1.f;
CV_MAT_ELEM( mat, float, 0, 1 ) = 0.f;
CV_MAT_ELEM( mat, float, 0, 2 ) = 0.f;
CV_MAT_ELEM( mat, float, 1, 0 ) = 0.f;
CV_MAT_ELEM( mat, float, 1, 1 ) = 1.f;
CV_MAT_ELEM( mat, float, 1, 2 ) = 0.f;
CV_MAT_ELEM( mat, float, 2, 0 ) = 0.f;
CV_MAT_ELEM( mat, float, 2, 1 ) = 0.f;
CV_MAT_ELEM( mat, float, 2, 2 ) = 1.f;
如何在 OpenCV 中處理我自己的數(shù)據(jù)
設(shè)你有 300x200 32-bit 浮點數(shù) image/array, 也就是對一個有 60000 個元素的數(shù)組.
int cols = 300, rows = 200;
float* myarr = new float[rows*cols];
// step 1) initializing CvMat header
CvMat mat = cvMat( rows, cols,
CV_32FC1, // 32-bit floating-point, single channel type
myarr // user data pointer (no data is copied)
);
// step 2) using cv functions, e.g. calculating l2 (Frobenius) norm
double norm = cvNorm( &mat, 0, CV_L2 );
...
delete myarr;
其它情況在參考手冊中有描述.見 cvCreateMatHeader, cvInitMatHeader, cvCreateImageHeader, cvSetData etc.
如何加載和顯示圖像
/* usage: prog <image_name> */
#include "cv.h"
#include "highgui.h"
int main( int argc, char** argv )
{
IplImage* img;
if( argc == 2 && (img = cvLoadImage( argv[1], 1)) != 0 )
{
cvNamedWindow( "Image view", 1 );
cvShowImage( "Image view", img );
cvWaitKey(0); // very important, contains event processing loop inside
cvDestroyWindow( "Image view" );
cvReleaseImage( &img );
return 0;
}
return -1;
}
如何發(fā)現(xiàn)和處理輪廓線
請看演示 squares
如何用 OpenCV 來定標(biāo)攝像機
TODO
◆用戶舉報◆
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -