?? faq.cn.htm
字號:
<li>可以為項目創(chuàng)建一個單獨的 workspace ("Create new workspace"),
也可以將新的項目加入到當前的 workspace 中 ("Add to current workspace")。
<li>單擊 "next" 按鈕。
<li>選擇 "An empty project",點擊 "Finish","OK"。
</ol>
經(jīng)過以上步驟,Developer Studio 會創(chuàng)建一個項目目錄 (缺省情況下,目錄名就是項目名),
<project name>.dsp 文件以及<project name>.dsw,.ncb 等,如果你創(chuàng)建自己的workspace。
<li>添加文件到 project 中:
<ul>
<li>選擇菜單"File"->"New..."->"Files" 。
<li>選擇"C++ Source File", 鍵入文件名,點擊"OK" 。
<li>增加 OpenCV 相關的 頭文件目錄:
<pre>
#include "cv.h"
/* #inlcude "cvaux.h" // experimental stuff (if need) */
#include "highgui.h"
</pre>
或者你可以拷貝部分已有的文件 (如:opencv\samples\c\morphology.c)
到項目目錄中,打開它,并且加入到項目中 (右鍵點擊編輯視圖
-> "Insert File into Project" -> <your project name> )。
</ul>
<li>配置項目:
<ul>
<li> 選擇菜單"Project"->"Settings..."以激活項目配置對話框
<li>在左邊選擇你的項目。
<li>調(diào)節(jié)設置,對 Release 和 Debug 配置都有效:
<ul>
<li>選擇 "Settings For:"->"All Configurations"
<li>選擇 "C/C++" 標簽 -> "Preprocessor" category -> "Additional Include Directories:"。
加入用逗號分隔的相對路徑 (對文件 .dsp 而言)
或絕對路徑 opencv\cxcore\include, opencv\cv\include, opencv\otherlibs\highgui
以及可選的 optionally, opencv\cvaux\include。
<li>選擇 "Link" 標簽 -> "Input" category -> "Additional library path:".
加入輸入庫所在的路徑 (cxcore[d].lib cv[d].lib hihghui[d].lib cvaux[d].lib)
</ul>
<li>調(diào)節(jié) "Debug" 配置
<ul>
<li>選擇 "Settings For:"->"Win32 Debug"。
<li>選擇 "Link" 標簽 -> "General" category -> "Object/library modules"。
加入空格分隔的 cvd.lib, highguid.lib, cvauxd.lib (cvauxd.lib可選)
<li>可以改變輸出文件的名稱和位置。如想把產(chǎn)生的 .exe
文件放置于項目目錄而不是Debug/ 子目錄下,可在
"Link" tab -> "General" category -> "Output file name:"
中鍵入 ./<exe-name>d.exe
</ul>
<li>調(diào)節(jié) "Release" 配置
<ul>
<li>選擇 "Settings For:"->"Win32 Release".
<li>選擇 "Link" 標簽 -> "General" category -> "Object/library modules".
加入空格分隔的 cv.lib, highgui.lib, cvaux.lib (cvaux.lib可選)
<li>另外,你也可以改變 .exe 文件名。
鍵入 ./<exe-name>.exe 到 "Link" 標簽 -> "General" category -> "Output file name:"。
</ul>
</ul>
<li>添加 dependency 項目到 workspace 中:
<ul>
<li>從菜單中選擇: "Project" -> "Insert project into workspace".
<li>選擇 opencv\cv\make\cv.dsp.
<li>同上,處理opencv\cvaux\make\cvaux.dsp和 opencv\otherlibs\highgui\highgui.dsp.
<li>設置 dependencies:
<ul>
<li>從菜單中選擇: "Project" -> "Dependencies..."
<li>為 "cv" 選擇 "cxcore",
<li>為 "cvaux" 選擇 "cv","cxcore",
<li>為 "highgui" 選擇 "cxcore",
<li>為你的整個項目選擇所有的:"cxcore","cv","cvaux","highgui"。
</ul>
dependency配置保證了在源代碼被改變的情況下,自動重新編譯 opencv 的 debug 版本和二進制代碼。
</ul>
<li>就這么多??梢跃幾g并且運行一切了。
</ol>
<hr><h1>Linux 的相關問題:</h1>
TODO
<hr><h1>使用庫的技術問題:</h1>
<hr><h3>怎么訪問圖像元素</h3>
<p>(坐標是從0開始的,并且是相對圖像原點的位置。
圖像原點或者是左上角 (img->origin=IPL_ORIGIN_TL) 或者是左下角 (img->origin=IPL_ORIGIN_BL) )
<ul>
<li>假設有 8-bit 1-通道的圖像 I (IplImage* img):
<pre>
I(x,y) ~ ((uchar*)(img->imageData + img->widthStep*y))[x]
</pre>
<li>假設有 8-bit 3-通道的圖像 I (IplImage* img):
<pre>
I(x,y)<sub>blue</sub> ~ ((uchar*)(img->imageData + img->widthStep*y))[x*3]
I(x,y)<sub>green</sub> ~ ((uchar*)(img->imageData + img->widthStep*y))[x*3+1]
I(x,y)<sub>red</sub> ~ ((uchar*)(img->imageData + img->widthStep*y))[x*3+2]
</pre>
例如,給點 (100,100) 的亮度增加 30 ,那么可以這樣做:
<pre>
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;
</pre>
或者更高效地:
<pre>
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;
</pre>
<li>假設有 32-bit 浮點數(shù), 1-通道 圖像 I (IplImage* img):
<pre>
I(x,y) ~ ((float*)(img->imageData + img->widthStep*y))[x]
</pre>
<li>現(xiàn)在,一般的情況下,假設有 N-通道,類型為 T 的圖像:
<pre>
I(x,y)<sub>c</sub> ~ ((T*)(img->imageData + img->widthStep*y))[x*N + c]
</pre>
你可以使用宏 CV_IMAGE_ELEM( image_header, elemtype, y, x_Nc )
<pre>
I(x,y)<sub>c</sub> ~ CV_IMAGE_ELEM( img, T, y, x*N + c )
</pre>
</ul>
也有針對各種圖像(包括 4 通道圖像)和矩陣的函數(shù)(cvGet2D, cvSet2D),
但是它們非常慢。
</p>
<hr><h3>如何訪問矩陣元素?</h3>
<p>方法是類似的(下面的例子都是針對 0 起點的列和行)
<ul>
<li>設有 32-bit 浮點數(shù)的實數(shù)矩陣 M (CvMat* mat):
<pre>
M(i,j) ~ ((float*)(mat->data.ptr + mat->step*i))[j]
</pre>
<li>設有 64-bit 浮點數(shù)的復數(shù)矩陣 M (CvMat* mat):
<pre>
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]
</pre>
<li>
對單通道矩陣,有宏 CV_MAT_ELEM( matrix, elemtype, row, col ),
例如對 32-bit 浮點數(shù)的實數(shù)矩陣:<pre>
M(i,j) ~ CV_MAT_ELEM( mat, float, i, j ),</pre>
例如,這兒是一個 3x3 單位矩陣的初始化:<pre>
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;
</pre>
</ul>
<hr><h3>如何在 OpenCV 中處理我自己的數(shù)據(jù)</h3>
<p>
設你有 300x200 32-bit 浮點數(shù) image/array, 也就是對一個有 60000
個元素的數(shù)組。
<pre>
int cols = 300, rows = 200;
float* myarr = new float[rows*cols];
// 第一步,初始化 CvMat 頭
CvMat mat = cvMat( rows, cols,
CV_32FC1, // 32 位浮點單通道類型
myarr // 用戶數(shù)據(jù)指針(沒有數(shù)據(jù)被復制)
);
// 第二步,使用 cv 函數(shù), 例如計算 l2 (Frobenius) 模
double norm = cvNorm( &mat, 0, CV_L2 );
...
delete myarr;
</pre>
其它情況在參考手冊中有描述.見 cvCreateMatHeader,cvInitMatHeader,cvCreateImageHeader, cvSetData 等。
</p>
<hr><h3>如何讀入和顯示圖像</h3>
<pre>
/* 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); // 非常重要,內(nèi)部包含事件處理循環(huán)
cvDestroyWindow( "Image view" );
cvReleaseImage( &img );
return 0;
}
return -1;
}
</pre>
<hr><h3>如何檢測和處理輪廓線</h3>
<p>參考 <a href="../samples/c/squares.c">squares</a> demo</p>
<hr><h3>如何用 OpenCV 來定標攝像機</h3>
<p>TODO</p>
</BODY>
</HTML>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -