opencv python教程简书_OpenCV-Python教程:39.BRIEF

理论

我们知道SIFT使用128维向量做描述子,由于它使用浮点数,需要512字节,同样的SURF也需要最小256字节(64维),创建上千个这样的向量需要很多内存,在资源受限的应用场景特别是嵌入式环境这是不可能的。越大的内存,匹配时间就越长。

但是实际上在匹配的时候不需要所有的这些维度,我们可以使用一些方法比如PCA,LDA等压缩他们,即使是其他方法入LSH(本地敏感hash)把这些浮点的SIFT描述子转换成二进制字符串,这些二进制字符串用来通过Hamming距离匹配特征。这提供了更好的速度,因为找hamming距离只是做异或和位运算,在现代有SSE指令的CPU来说非常快,但是我们需要先找到描述子,然后我们只是能使用hash,还是没有解决内存的问题。

BRIEF在这个时候出现了,它提供了直接找到二进制字符串而不找描述子的简便办法。它取被平滑过的图像块,选择nd(x,y)集合位置对,然后在这些位置对上做像素强度对比,比如,设第一个位置对为p和q,如果I(p) < I(q),那么它的结果是1,否则是0,这用在所有nd个位置对,得到nd维的位串。

这里nd可以是128,256或者512.OpenCV支持所有这些,但是默认是256(OpenCV用字节表示,所以就是16,32和64字节)。当你得到这个,你可以使用Hamming距离来匹配这些描述子

一个重要的点是BRIEF是一个特征描述子,它不提供任何方法来找特征,所以你还得使用别的特征描述子比如SIFT,SURF等,论文推荐使用CenSurE,是个快速检测器,BRIEF甚至和CenSurE比SURF还好点。

简单说,BRIEF是一个快速的特征描述子计算和匹配方法。它提供了高识别率,除非是大的平面旋转

OpenCV里的BRIEFimport numpy as np

import cv2

from matplotlib import pyplot as plt

img = cv2.imread('simple.jpg',0)

# Initiate STAR detector

star = cv2.FeatureDetector_create("STAR")

# Initiate BRIEF extractor

brief = cv2.DescriptorExtractor_create("BRIEF")

# find the keypoints with STAR

kp = star.detect(img,None)

# compute the descriptors with BRIEF

kp, des = brief.compute(img, kp)

print brief.getInt('bytes')

print des.shape

函数brief.getInt('bytes')给的nd大小是字节,默认是32。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Every so often a book comes along that makes you ask yourself, "Gee, when was the last time I had my eyes checked?" David M. Beazley&#39;s Python: Essential Reference is just such a book. Condensing thousands of pages of Python online documentation into a compact 319-page softcover, Beazley and his editors used the old-college trick (often performed in reverse) of dickering with the font size to meet a putative page-limit requirement. The result is a truly condensed product fit for the occularly well-adjusted (nota bene). Beazley&#39;s subject is Python, a full-featured, freely-redistributable, POSIX-compliant (platforms include Linux, Unix, Macintosh, and Windows) scripting language that is based on object-oriented design principles. As advertised, Beazley&#39;s source release (1.5.2) is available from an unfortunately slow server at www.python.org. The installation under Linux (Redhat 5.2) proceeded without incident. Beazley holds true to his catalogic purpose: fully 230 pages are formatted as technical appendices and indices covering the standard litany: built-in function syntax, database features, OS-level interfaces, Internet interfaces, and compiling/profiling/debugging. All references are fully annotated and illustrated with example source code that runs from a couple of lines to a couple of pages. In lock step with competing scripting languages, Python is extensible and embeddable in C and C++, and with blitzkrieg efficiency, Beazley summarizes these crucial practical issues in the final 30 pages. Python users who are tired of chasing questions through hyperlinked online documents will benefit from the expansive random-access index. Python the book captures the orderliness of Python the language. Beazley begins with an 86-page précis of Python in the fashion of Kernighan and Ritchie: too brief for a newbie tutorial but enough to propel old hands into a scripting language that aspires to the elegance of a compiled language. Indeed, it is a byte-compiling language. The line bytecode=compile("some_python_script",&#39;&#39;,&#39;exec&#39;)) creates &#39;bytecode&#39; as a token executed by exec bytecode. But a five-minute investigation through Beazley&#39;s book does not describe how &#39;bytecode&#39; can be written into a separate executable file. If writing the byte-compiled code to a file is not possible, Python suffers from the limitations of other scripting languages: the executable is the source and cannot be hidden from the user, at least not without some difficulty. Despite its extensibility, embeddability, and pleasing architecture, Python is like other scripting languages: appropriate for solving small nonproprietary problems. Those familiar with more established scriptors like Perl may ask, "Why Python?" Unlike Perl, Python is a product of the fully object-oriented (OO) era, and its constructs reflect design principles that aspire beyond keystroke shortcuts of the succinct-but-often-arcane Perl. Python creator Guido van Rossum cleansed Perl&#39;s idiosyncracies and objectified basic data structure, data manipulations, and I/O. With Python, OO is so intrinsic that learning Python is equivalent to learning OO. The same cannot be said of Perl. Unfortunately, comparisons with other languages are missing from Beazley&#39;s book. Van Rossum, in an embarrassingly self-serving foreword, preemptively asserts that we readers need "neither evangelizing nor proselytizing"--after all, we already own the book--but we do need galvanizing and we don&#39;t find it. Specifically, we need a response to the oft-repeated wisdom that new computer languages are only worth learning if they teach us to organize our thinking along new lines. Scripting languages, however, are for quick and dirty projects: quick to write, easy to hack, and ultimately disposable. The essential tension created by van Rossum and friends is between the elegance of object-oriented principles and the utility of a quick-hacked script. Sadly, the tension remains unresolved in Beazley&#39;s reference. There is little to convince us that Python has earned its place in the firmament by changing our thinking. But Beazley has given us much to get us going if we have already taken the leap of faith. --Peter Leopold --This text refers to an out of print or unavailable edition of this title. From Library Journal Though Python is a relatively new programming language, it has quite a significant audience owing to its sensible syntax. An active user of Python since 1996, Beazley provides ample information on the fundamentals of versions 2.0 and 2.1, including syntax, functions, operators, classes, and libraries. This is first and foremost a reference, so he avoids lengthy discussions of Python&#39;s superiority. Peppered with good code samples and featuring a companion web site with more extensive pieces, this title should be on hand in larger libraries. Copyright 2001 Reed Business Information, Inc.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值