⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 faq.cn.htm

📁 opencv 中文文档 关于opencv 的所有函数
💻 HTM
📖 第 1 页 / 共 2 页
字号:
      <li>可以为项目创建一个单独的 workspace ("Create new workspace"),
	也可以将新的项目加入到当前的 workspace 中 ("Add to current workspace")。
      <li>单击 "next" 按钮。
      <li>选择 "An empty project",点击 "Finish","OK"。  
    </ol>
    经过以上步骤,Developer Studio 会创建一个项目目录 (缺省情况下,目录名就是项目名),  
      &lt;project name&gt;.dsp 文件以及&lt;project name&gt;.dsw,.ncb 等,如果你创建自己的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)  
        到项目目录中,打开它,并且加入到项目中 (右键点击编辑视图  
        -&gt; "Insert File into Project" -&gt; &lt;your project name&gt; )。
      </ul>
    <li>配置项目:
      <ul>
      <li> 选择菜单"Project"-&gt;&quot;Settings...&quot;以激活项目配置对话框 
      <li>在左边选择你的项目。
      <li>调节设置,对 Release 和 Debug 配置都有效:
        <ul>
        <li>选择 "Settings For:"-&gt;"All Configurations"
        <li>选择 "C/C++" 标签 -&gt; "Preprocessor" category -&gt; "Additional Include Directories:"。
	  加入用逗号分隔的相对路径 (对文件 .dsp 而言)  
          或绝对路径 opencv\cxcore\include, opencv\cv\include, opencv\otherlibs\highgui  
          以及可选的 optionally, opencv\cvaux\include。
        <li>选择 "Link" 标签 -&gt; "Input" category -&gt; "Additional library path:".
	  加入输入库所在的路径 (cxcore[d].lib cv[d].lib hihghui[d].lib cvaux[d].lib)
        </ul>
       <li>调节 "Debug" 配置
       <ul>
        <li>选择 "Settings For:"-&gt;"Win32 Debug"。
        <li>选择 "Link" 标签 -&gt; "General" category -&gt; "Object/library modules"。
	  加入空格分隔的 cvd.lib, highguid.lib, cvauxd.lib (cvauxd.lib可选)  
        <li>可以改变输出文件的名称和位置。如想把产生的 .exe  
          文件放置于项目目录而不是Debug/ 子目录下,可在  
          "Link" tab -&gt; "General" category -&gt; "Output file name:"
          中键入 ./&lt;exe-name&gt;d.exe&nbsp;
        </ul>
       <li>调节 "Release" 配置
       <ul>
        <li>选择 "Settings For:"-&gt;"Win32 Release".
        <li>选择 "Link" 标签 -&gt; "General" category -&gt; "Object/library modules".
          加入空格分隔的 cv.lib, highgui.lib, cvaux.lib (cvaux.lib可选)
        <li>另外,你也可以改变 .exe 文件名。
          键入 ./&lt;exe-name&gt;.exe 到 "Link" 标签 -&gt; "General" category -&gt; "Output file name:"。
       </ul>
       </ul>
    <li>添加 dependency 项目到 workspace 中:
       <ul>
       <li>从菜单中选择: "Project" -&gt; "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" -&gt; "Dependencies..."
        <li>为 "cv" 选择 "cxcore",
        <li>为 "cvaux" 选择 "cv","cxcore",
        <li>为 "highgui" 选择 "cxcore",
        <li>为你的整个项目选择所有的:"cxcore","cv","cvaux","highgui"。
       </ul>
        dependency配置保证了在源代码被改变的情况下,自动重新编译 opencv 的 debug 版本和二进制代码。
    </ul>
    <li>就这么多。可以编译并且运行一切了。
    </ol>

<hr><h1>Linux 的相关问题:</h1>

TODO


<hr><h1>使用库的技术问题:</h1>

<hr><h3>怎么访问图像元素</h3>
<p>(坐标是从0开始的,并且是相对图像原点的位置。
图像原点或者是左上角 (img-&gt;origin=IPL_ORIGIN_TL) 或者是左下角 (img-&gt;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 浮点数, 1-通道 图像 I (IplImage* img):
<pre>
I(x,y) ~ ((float*)(img->imageData + img->widthStep*y))[x]
</pre>
<li>现在,一般的情况下,假设有 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 通道图像)和矩阵的函数(cvGet2D, cvSet2D),  
但是它们非常慢。
</p>

<hr><h3>如何访问矩阵元素?</h3>
<p>方法是类似的(下面的例子都是针对 0 起点的列和行)
<ul>
<li>设有 32-bit 浮点数的实数矩阵 M (CvMat* mat):
<pre>
M(i,j) ~ ((float*)(mat->data.ptr + mat->step*i))[j]
</pre>
<li>设有 64-bit 浮点数的复数矩阵 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 浮点数的实数矩阵:<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 中处理我自己的数据</h3>
<p>
设你有 300x200 32-bit 浮点数 image/array, 也就是对一个有 60000  
个元素的数组。
<pre>
int cols = 300, rows = 200;
float* myarr = new float[rows*cols];

// 第一步,初始化 CvMat 头
CvMat mat = cvMat( rows, cols,
                   CV_32FC1, // 32 位浮点单通道类型
                   myarr // 用户数据指针(没有数据被复制)
                   );
// 第二步,使用 cv 函数, 例如计算 l2 (Frobenius) 模
double norm = cvNorm( &mat, 0, CV_L2 );

...
delete myarr;
</pre>
其它情况在参考手册中有描述.见 cvCreateMatHeader,cvInitMatHeader,cvCreateImageHeader, cvSetData 等。
</p>

<hr><h3>如何读入和显示图像</h3>
<pre>
/* usage: prog &lt;image_name&gt; */
#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); // 非常重要,内部包含事件处理循环
        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 + -