Preface for Chinese Translation 
Since  th在 writing of  book,  OpenCV  is  now  actively  supported  by  Willow  Garage 
(http://www.willowgarage.com).  a  robotics  research  institute  located  in  Menlo  Park, 
California.  During  the  time  when  OpenCV  had  less  support,  Shiqi  Yu  helped  out  by 
producing  a  Chin在se translation  of OpenCV  documentatìon.  It is  therefor  fítting  that 
Shiqi  has  continued  on  to  produce  the  Chinese  主ranslation of this  book.  The  Chinese 
translation  timing  is  also  nicely  aligned  with  the  new  rele在se 2.0  of  OpenCV  ín 
Sept非mb衍 2009. You can fínd  links to current information on OpenCV at the main  wiki 
page  at  ht伊 :Ilopencv. willowgαrage.com  which 
the  detailed  page  at 
ht伊:/Iopencv. willowgarage.comlwikiIFullOpenCVWiki.  The  new  OpenCV  releases  are 
detailed in http://opencv.willowgarage.com/wiki/Welcome/lntroduction得Announcements.
links 
to 
Applications  for  computer  vision  and  machine  perception  are  growing  rapidly.  For 
example,  many  people  are  familiar  with' face  detection  now  available  on  consumer 
cameras.  Many  of those  face  detection  techniques  are  adapted  from  the  face  detection 
algorithms  developed  in  OpenCV.  B时, many  people  are  not  aware  of  just  how 
important  comput在r vision  already 
is 
manufactured  thes号 days without  making  use  of video  inspection  equipment,  camer剖
now  monitor fruits  and  vegetables  for  blemishes, make  sure that the  labels  on  products 
are  put on  in  the  right  plac号,飞存在tch to  make  sure cloth  has  no  flaws ,  or that  each pixel 
works  on  an  LCD  screen  and  much  more.  Many  of  thes缸 applications make  us 在 of
OpenCV routines, many such systems ar在 deployed in China. 
for  manufacturing.  Almost  nothing 
is 
Computer  vision 在lso has  growing  uses  in  monitoring  and  safety.  Some  people 在re
aware  of security  cameras  in  airports  and  train  stations,  but  fewer  people  know  th以
cameras  are  also  increasingly  used  to  monitor  mine  equipment,  prev 告nt drownings  in 
swimming  pools  and  watch  traffic  flow  and  accidents  onfreeways.  OpenCV,  wìth  its 
\i cen白, encourages  commercial  use  and  so  is  deployed  on  many  of  these 
BSD 
monitorìng  systems.  When  you search  th在 web , many  of 住在 image processíng  routines 
run by Google  make 泣se of OpenCV.  These  uses  r在nge from  helping stitch satellite  and 
airplane  ìmages  together  in  Google  Earth  and  Google  Maps,  but  also  tl{… stitch  street 
scenes together and  align the  imagery  with laser sc拍 s in  Google Street View. 
,.,.. 
Computer  vision  has  many  uses  on  th牵 Web , such  as  in  the  Video  Summary  produced 
by  Video  Sur叹http://w附v. videosurf coml)or  for  image retrieval  by 在11 the  m我jor search 
engines.  There  is  a  positive  feedback  here  because  the  more  images  there  are  on  the 
web,  the  more  training  data  becomes  avai1able  such  as  LabelMe(ht伊 ://labelme.csail. 
mit.edu/  datα bases)or  Tiny  Images(ht伊从伊eople. csail. mÌ!. edu/torralba/tinyimages/ 
collection).  Additional1y,  more  and  more  researchers  are  using  Amazon's  Mechanical 
Turk  service(https://www.mturk.com/mturk/welcome}to 
images  databases  for 
pennies  per  image 在nd tools  are  appearing  to  make  such  labeling  tasks  easier  to  run 
(http:牛 r. wi/lowgarage.com/wiki/ROS/mturk).  The  training  data  from  these  databases 
and services helps improve computer vision algorithms. 
label 
By  coincidence,  both  authors  of the  OpenCV  book  now  work  in  robotics where  sensor 
perception  Îs  the  main  obstacle to  enable  wide  deployment  of robotics.  Robots  wilI be 
useful  for  elder1y  care, for  agriculture, for  services  and  for  manufacturing.  Robots  ha可s
been  doing  well  at  navigation  and  mapping(ht伊 ://ww¥毛人youtube.com/watch?v=
qRrMHa06NpE)but the real  key  to  unleashing  a mobile  robotics  in出stry is  perception 
for  manipulation.  Robots  need  to  be  able  to  see  objects  reIiably  in  order to  manipulate 
and build things.  There  is  stilI much work to do to  make  perception  re Ii abl缸, and that is 
to  col1ect the  best work of the top people in 
one of the reasons  why  OpenCV is open -
order  to  enable  se告ing machines.  R在cently there  have  been  many  advances  in  mobile 
manipulation(ht伊 ://Wli几1人youtube.com/watch?v口 OS2dc…B-6Kg)but much  more  work 
remains  to  be  done.  Fortunately,  OpenCV  is  keeping up  and  now  does  a  major release 
every  6  months  with  dai1y  improvements  available  from  the  source  code  repository 
(http://sourc矿orge.net/scm/?type=svn<.是group_id口22870).
1 thank  Shíqi Yu and Ruizhen Liu for  their translation of this book.  People who work in 
open  source  do  their  work  for  all  of  humanity  and  not  for  any  specific  co边往try ,
company  or  group.  OpenCV  was  designed  to 在ccelerate human  knowledge  and 
capabiIity  by  making  advances  in  knowledge 在vailable to  everyon号. This  is  an 
optimistic ¥ iew of humanity  but  it  depends  on  contributions  back.  We  encourage  top 
scientists  and  deγelopers in  China  to  le在rn OpenCV  and  to  contribute  their  advances 
back to the effort. 
Gary Bradski 
Senior Scientist, Willow Garage 
Consulting Professor, Stanford University, CS  Dept. 
g在rybradski 也gmai l. com
September 2009 
阳trJ号
学习 OpenCV
(中文版)
Gary Bradski  Adrian Kaehler 著
于仕琪刘瑞棋译
。要 REILLY@
Be扩ing. Cambridge. Farnham • IGδln. Sebastopol. Ta专7ei. To妙。
。, Reilly Media, Inc. 授权清华大学出版社出版
清华大学出版社
北京
.,.....,;,-~ 
国
内容简介
计算机视觉是在图像处理的基黯上发展起来的新兴学科. OpenCV 是…个开源的计算机挠觉
是英特尔公司资爵的两大器像处理科器之…。它为自像处理、 a模式识别、三维重建、物体跟
踪、机器学习和线性代数提供了各种各样的算法。
本书画 OpenCV 发起人所写,站在二t钱开发人员的角度琦混俗易锚的语言解释了 OpenCV 的
缘起和计算辑视觉3基础结构,演示了如何蹲 OpenCV 和现有的自由代码为各种各样的机缔造好编
程,这些都有助于读者迅速入门并渐入佳境,兴趣盎然地深入探索计算机提党领域。
本书可作为借息处理、计算挠、机器人、人工智能、遥感器像处理、认知神经科学等有关专
业的高年级学生或研究生韵教学用书,也可供招关领域的研究工作者参考。
Copyright @ 2008 G被y Bradski and Adri在n Kaehler. AI1 rights reserv时,
Authorized. Simplified Chinese translation editio珑, by 0'这.eilly Media与 Inc. ,. is published  by Tsi吨hua
University 如ωs, 2009.  Authorized  translation of the original English edition,  2008  O'Rei11y  M创 ia,
Inc., the owner of all rights to p泣blish and sell the same. 
All rights reserved inch品ding the rights of reproduction in whole or in part in any form. 
本书之英文原版自 O'Reilly Media, lnc. 于 2008 年出版。
本书中文简体版由。'Rei IlyMedia,  Inc. 接权清华大学出版社出版 2009 年出殿。此翻译烛的出版
和销售得到出随校和销售权的所有者…--o'Rei Ily  Media, Ino. 的许可。
版权所有,未经书菌许可,本书的任何部分和全都不得以任何形式复醋。
北京市版权局著作权合同登记号 图字 01-2009-5150
本书封离黯有清华大学出版社防伪标签,无标签者不得销售。
版权所有,侵权必究。侵权举拨电话: 010-臼7829嚣9
图书在接摘自 (CIP)数据
学习 Qpe'fçy(中文版.)[(秉)布拉德斯基(Bradsld, G),  (美)克勒。王aehle几A.)著:子仕琪,却瑞祯译.
…北京 z 清华大学出版社, 2009.10 
书名·原文Learning 句enCV
ISBN 978蝙7-302-20993δ
学… II.①布…@克…@子…@刘… m. 图像处理…应用软件 N. TP39 1.41 
中国版本翻书馆 CIP 数据核字。009)第 151959 号
13701121933 
责任编辑 z 文开琪
纣商设计 Ellíe Volckhausen 张健
版式设计 ε 北京东方人华科技有限公司
责任印制 g 李红英
出版发行"清华大学出版社
址 g 北京清华大学学研大厦 A JÆ:
地
邮编 100。在4
http://www.tup.com.cn 
拉总机: 010-62770175 鄙鹅: 010-62786544 
投稿与读者服务: 010ω62776969 仲service@tup. tsi吨hua. edu.cn 
质量最反馈 010币 62772号 15 , zhiliang@tup. tsinghua. ed认 cn
印尉着:清华大学印刷厂
装订者 2 北京市密云县东文奇事j 本装订厂
经
开
版
印数 1-4000
定价 75. ∞元
销:全国新华书店
本 178 X 233 印张: 39.5 字数: 769 千字
次 2009 年 10 月第 1 版
印
次 20的年 10 月第 1 次印麟
本书如存在文字不清、靠着印、缺页、倒页、脱页等印装质量问题,请与清华大学出版社出版
部联系调换@联系电话 (010)62770177 转 3103
产品编号: 029292-01 
目录
击舰前言.………………..副……………..越箱..............……·每............................ VI 
译者序.. .. .. .. .. .. ..  .. .. ..  ,.  ..  ..  ..  ..  ..  ..  ..  ..  ..  ..  ..  ..  ..  ..  ..  ..  ..  "  "  •  ..  "  ..  ..  ..  "  •  ..  ..  ..  ..  ..  ..  ..  .. ~  .,  ..  ..  ..  ..  ..  ..  •  ..  •  ..  ..  ..  •  •  ..  ..  ..  * ,.  ..  ..  ..  ..  ..  ..  ..  ..  ..  ..  ..  •  ..  ..  ..  ..  ..  ..  ..  •  •  ..  ..  ..刻
写在茹丽的话............……….......,.榻………….......…….............".......将·‘...... XIII 
前宵 ……....…...............…编......................喻........………… ......................XV
第 1 章概述................................"..............‘……..细........................蜀 ..............1
什么是 OpenCV …… .........4." ~......... ................................….........…..................................;...............1 
OpenCV 的应用领雄.篝............ ....................................................... ........................................~.......................... ..............蕴..攀…..... 1 
什么是计算机操觉.. ........ ~................... ..….‘…………………………..……………·剥…… .....................2
OpenCV 的越源………........….............毫............盔....... ............................................. O*......~.................. ………..稽 6
下载和安装 0严nCV ...................................................…........………...…唱 .................8
通过 SVN 获取最蔽的 OpenCV 代盹……..…….......….................................…... .... ...11 
多 OpenCV 文档................... •. .... ...... ~............ .......叶'葡萄 .............................w. …………..凰…… ........12
0μnCV 的结构和内容.......... ~. _.... . ....黯稽. .. .. . ... . *." ~.... •• .•• ••• ~‘……………… .........................14 
移植性到............~.. .……..…. ~. . . . . . . . . . . . * • • • • • • • • • • • • • • • • • • • • .…...................……..........................16 
.....................…. ...••••.•••.••..•. ~'.,..... *.......... ... ... .. ......... ......确................ ••••••• ••• •• ~.‘....刊
练}::]
第 2 意 OpenCV 入门....盔..................鹏…民…·晕………......翩.......................渺 ....18
开始准备....................................................................……… ...................................18
初试牛丑…一-显示器像~.. ~.. . .…...............…·…........................................................19 
第工个程序…←-播放 AVI 视频....... .. . .. ...... . . . . . ....... ...... . .. ....... ..... ... ~....... ...... ... .. ..朱 ..21
视频播放控制.........................… .............................................................................23
一个简单的变换................................………….......................……….........................压
…个复杂一点的交换.............………......……....…… H·H·-H·H·-H·H·-UH·H·-1..H·a·-… 28