http://code.opencv.org/issues/1577
描述
I attach a patch implementing the Hierarchical MSER. It extends the OpenCV MSER implementation to return the underlying component tree used by the MSER algorithm.
The tree is returned in the CvSeq tree fields (h_next, h_prev, v_next, v_prev) which were previously unused. The result of the algorithm is expanded by these fields, producing otherwise the same output as before.
There is no performance penalty as the component tree is already constructed by the MSER algorithm. This patch just exposes this information.
Two patches are attached: mser-hierarchical.patch and mser-hierarchical-c++.patch. The second one provides a C++ interface for retrieving the tree, equivalent to the one returned by cv::findContours().
A test program that draws the tree and an example output is also provided. Darker regions are closer to the root of the tree.
Hierarchical MSER is introduced in this paper:
Carlos Merino-Gracia, Karel Lenc and Majid Mirmehdi. _A Head-mounted Device for Recognizing Text in Natural Scenes. InCBDAR 2011.
mser-hierarchical.patch(2.2 KB) uganson -, 2012-02-01 18:23
original.jpg(155.6 KB) uganson -, 2012-02-01 18:24
test-mser-hierarchical.cpp(1.8 KB) uganson -, 2012-02-01 18:25
result.jpg(180.1 KB) uganson -, 2012-02-01 18:27
//////////////////////////////////////////////////////////////////////////////////////////////////////////
使用和制作patch文件
创建补丁文件:
CODE:
diff -Naur 旧的目录 新的目录 > patch文件
或者
diff -Naur 旧的文件 新的文件 > patch文件
对于目录层数的一些限制
在创建patch的时候文件夹的层数应当是一样的,比如
CODE:
--- old/modules/pcitableMon Sep 27 11:03:56 1999
+++ new/modules/pcitableTue Dec 19 20:05:41 2000
这样是可以的。
而
CODE:
--- old/try1/other/modules/pcitableMon Sep 27 11:03:56 1999
+++ new/modules/pcitableTue Dec 19 20:05:41 2000
这样做可能会有一些问题。
如何使用patch
对于一个patch文件,有两种常用使用方法:
1.
CODE:
cat new-patch | patch -p02.
2、
CODE:
patch -p0 < new-patch
patch命令里面的层数(-p0?-p1?)
参数-p来指定从第几层开始比较。比如有一个patch文件的补丁头是这样的:
CODE:
--- old/modules/pcitableMon Sep 27 11:03:56 1999
+++ new/modules/pcitableTue Dec 19 20:05:41 2000
如果使用参数-p0,就表示从当前目录,找一个叫作new的目录,在它下面找一个叫modules的目录,再在它下面找一个叫pcitableMon的目录。
如果使用参数-p1,就表示忽略第一层,从当前目录找一个叫modules的目录,在它下面找一个叫modules的目录。这样会忽略掉补丁头提到的new目录。
依此类推。
patch文件的结构
补丁头
补丁头是分别由---/+++开头的两行,用来表示要打补丁的文件。
一个补丁文件中的多个补丁
一个补丁文件中可能包含以---/+++开头的很多节,每一节用来打一个补丁。所以在一个补丁文件中可以包含好多个补丁。
块
块是补丁中要修改的地方。它通常由一部分不用修改的东西开始和结束。他们只是用来表示要修改的位置。他们通常以@@开始,结束于另一个块的开始或者一个新的补丁头。
块的缩进
块会缩进一列,而这一列是用来表示这一行是要增加还是要删除的。
块的第一列
+号表示这一行是要加上的。
-号表示这一行是要删除的。
没有加号也没有减号表示这里只是引用的而不需要修改。
一个patch的例子
CODE:
diff -u old/modules/pcitable new/modules/pcitable
--- old/modules/pcitableMon Sep 27 11:03:56 1999
+++ new/modules/pcitableTue Dec 19 20:05:41 2000
@@ -1,4 +1,6 @@
0x0e110xae10"cpqarray""Compaq|Smart-2/P RAID Controller"
+0x10000x0010"cpqarray""Compaq|Integrated Array Controller"
+0x10110x0046"cpqarray""Compaq|Smart-2/P RAID Controller"
0x0e110xae32"tlan""Compaq|Netelligent 10/100"
0x0e110xae34"tlan""Compaq|Netelligent 10"
0x0e110xae35"tlan""Compaq|Integrated NetFlex-3/P"
@@ -21,6 +23,7 @@
0x10000x000f"ncr53c8xx""Symbios|53c875"
0x10000x0012"ncr53c8xx""Symbios|53c895a"
0x10000x008f"ncr53c8xx""Symbios|53c875J"
+0x10000x000a"sym53c8xx""Symbios|53c1510"
0x10000x0701"yellowfin""Symbios|83C885 gigabit ethernet"
0x10000x0702"yellowfin""Symbios|Yellowfin G-NIC gigabit ethernet"
0x10110x0001"tulip""DEC|DECchip 21050"
--- old/usr/share/kudzu/pcitableSun Sep 26 17:11:23 1999
+++ new/usr/share/kudzu/pcitableTue Dec 19 20:05:41 2000
@@ -15,6 +15,8 @@
0x0e110x3034"unknown""Compaq|QVision 1280/p"
0x0e110x4000"unknown""Compaq|4000 [Triflex]"
0x0e110xa0f3"ignore""Compaq|Triflex PCI to ISA Bridge"
+0x10000x0010"cpqarray""Compaq|Integrated Array Controller"
+0x10110x0046"cpqarray""Compaq|Smart-2/P RAID Controller"
0x0e110xae10"cpqarray""Compaq|Smart-2/P RAID Controller"
0x0e110xae29"unknown""Compaq|MIS-L"
0x0e110xae2a"unknown""Compaq|MPC"
@@ -46,6 +48,7 @@
0x10000x000f"ncr53c8xx""Symbios|53c875"
0x10000x0012"ncr53c8xx""Symbios|53c895a"
0x10000x008f"ncr53c8xx""Symbios|53c875J"
+0x10000x000a"sym53c8xx""Symbios|53c1510"
0x10000x0701"yellowfin""Symbios|83C885 gigabit ethernet"
0x10000x0702"yellowfin""Symbios|Yellowfin G-NIC gigabit ethernet"
0x10000x0901"unknown""Symbios|61C102"
分析
这个例子是由命令
CODE:
diff -u old/modules/pcitable new/modules/pcitable
创建的。不过最好是用命令diff -Naur来代替diff -u。
它修改了两个文件,new/modules/pcitable和new/usr/share/kudzu/pcitable。
第一个补丁头包含两个块,分别增加了两行和一行。
这个是参考了这篇文http://www.cpqlinux.com/patch.html来总结翻译。由于刚刚接触这些东西,很多地方可能翻译的不恰当,尤其是一些术语,如有发现问题,请给我留言说明,以便我来改正,谢谢。
//////////////////////////////////////////////////////////////////////////////////////////////////////////
相关的问题 (新增)