刘小邦的个人博客分享 http://blog.sciencenet.cn/u/iamliuzhiyong 浮生浪迹笑明月 千愁散尽一剑轻

博文

[机器学习]opencv

已有 5937 次阅读 2013-9-22 07:51 |系统分类:论文交流

explanation:

这里我们简单谈谈xml和yaml文件输入,你的输出只有一个这种extension,而structure来自于此。有两种data structure, 你可能serialize,mapping和element sequence,这两种之间的difference是在map中,每个element都有一个unique的name。而对sequence,你需要go through,并且query一个特定的item。

xmlyaml file open and close。 在你写任何conten之前,你需要open并且close它。 xmlyaml的数据结构是file storgae。 指定这种结构,你可以使用或者constructor或者open function。而第二个argument是一个constant, 指定type of operation,比如write, read, 或者 append。这种指定在file name种的extension,也同时determine 输出的format。如果你指定extension是xml.gz,这种输出甚至是经过压缩的。

input和output text 以及number。 数据结构使用同样的output operator,对于output任何类型的data structure,我们都需要输出任何type的数据结构,我们都需要首先specify它的name。我们简单的print其name,对于基本的type,你会follow这种格式 fs << " iteration nr " <<  100。 而read in simple address, 使用[] operator,并且cast operation通过>> operator。input和output data structure分别的格式如<< 和>>分别表示。对于sequence, 在first element之前,print  [ character,并且在最后一个character之后使用]。对map,我们使用{和}。来read, 我们使用filenode以及filenodelterator数据结构,[]operator返回filenode数据类型,如果node是sequential,我们可以使用filenodeiterator来iterate。

it is possible 来serialize这个,通过opencv io xml/yaml interface,添加一个read和write function inside和outside你的class。

camera calibration:

你可以发现source code 从opencv source library的calibration folder,或者直接从这里下载。这个程序只有一个configuration argument,就是configuration file的名字。如果没有给出,这里会尝试打开一个名叫default.xml的文件,在configuration file,你要选择input camera, 或者video file,以及image list。如果你opt for后者,你需要创建一个configuration file。其enumerate了所有需要用的的images。 重要的part是这些图像需要specified,使用using absolute path,或者relative path,从application working directory。这个application开始于reading setting从你的configuration file,但是这一块和subject of tutorial没有关系。你可以在file input and output using xml and yaml file种发现。这里我们使用simple opencv class input operation,在read file之后,我们有一个additional post-process function来检测input的validity。只有所有的家都是good,才会给出一个goo input value的 true。如果它fail或者我们有足够的图片来进行calibrate,在这之后,我们有一个big loop,如果它fail了或者我们有enough images,我们就运行calibration process,in case of image, 我们step out loop,否则remaining frames会被undistorted。如果no more image,或者足够多,我们stop calibration, 并且show the result。发现current input的pattern,formation equation我提到的包含finding major pattern in the input,in case of chessboard,这是它的corners of square, 而对circule,则是circule自己。 这种position会形成result,并且collected into pointbuf vector。依靠你输入的pattern,你会使用或者findchess board corners,或者findcirculegrid function。对于both them,你需要pass到current image上,the size of the board,你会返回pattern的position。除此之外,他们返回一个boolean variables,其state是否input,我们发现或者not the pattern。in case of camera,我们take camera images当input delay time passed,这是为了允许user move the chess board aroud,并且geting different images。有些images代表者同样的equation,而same equation at calibration会形成ill-posed problem。所以calibration会fail。对于square images,corner position会approximate。我们智慧improve 这个通过calling cornersubpix function。这种方法会获得一个更好的calibration result。在这之后,我们添加一个valid input result on imagepoint vector来手机所有的equation到一个single container。最后为了visualization feedback purpose,我们draw found points在 input image上,使用findchessboardcorners function。show state和result for the user,plus command line control of application。showing part包含了一个在live feed上的text output,对于video和camera input,显示了capturing frame,我们简单的bitwise negate the input image。如果我们只是run the calibration,并且获得camera matrix,以及distortion coefficients,我们可以correct image,with undistorted 函数。然后wait for an input key,如果是u,我们toggle这个distortion removal,如果是g,我们开始start所有的detection process,最后使用esc key来quik这个application. 显示distortion removal for images。如果我们是work with image list,是不太可能在loop之内,remove the distortion。因此,你必须append this after loop。利用undistort function, 我们实际上首先call initundistortrectifymap来发现transformation matrics,你进行transformation with remap function。因此,经过sucessful calibration, map calculation 需要被实现一次,使用expanded form,你需要speed up你的application。calibration需要被实现,一旦每个camera需要在successful calibration之后成功保存信息。这种方式后你可以load 这些value 到你的程序,由于这个,我们必须首先make这个calibration,如果这是成功的,我们保存结果到opencv style或者xmlyaml 文件,depending on 你指定的extension。因此,在第一个function,我们只是split up 两个process。因为我们想要save很多calibration variables,我们create 这些variables,并且pass both of them  in the calibration and saving function。我们运行calibration在calibratecamera function,这拥有以下的一些parameters。包括啊object points, vector point 3f描述了pattern look。如果我们拥有一个planar pattern,我们才能simply设置所有的z coordinate到zero。这是一个collection of points,其important points已经呈现。因为,我们使用single pattern来为所有的input images,我们只计算一次,并且multiply到所有其他的input view上,我们计算corner point使用calboardcornerposition function。image points是一组important points的vector。camera matrix,我们使用fix aspect ration option,我们需要set fx到zero。而distortion coefficient matrix,我们initialize with zero。这个函数会计算所有的roation and translation vector,其transform object points到image points,第7和8 parameter是output vector matrix,包含第ith position, 旋转和translation vector。还有另外一个function 返回的是average reprojection error。这个number给出了good estimation精确程度来发现parameter。这应该as close to zeros as possible。给定的intrinsic distortion,distortion, rotation and translation matrix,我们可能要计算the error, 使用one view,使用using project points来transform object point到image point。然后我们计算absolute norm,between我got with transformation和corner/circule finding algorithm。这里我们所有的input chessboard pattern拥有9*6 size。我们使用axis ip camera来create a couple of snapshots,并且存储到vid5 directory,我已经put 这个到cameracalibration folder里,并且create一个vid5 xml文件,来描述图像是如何使用的。



https://blog.sciencenet.cn/blog-942948-726804.html

上一篇:[机器学习]Seminar in Robotics, Systems, and Controls
收藏 IP: 195.176.111.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-4-19 18:46

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部