Friday, May 30, 2008

Save you gvim set

You can add code to .rimrc (in /home/user/);
such as:

syntax on
set shiftwidth=4
set cindent

NOte: Don't add ";" to the end of above sentence.

But I am using the susx linux...You can't find .rimrc under directory /home/user. That's because it's under /etc/...
Unfortunately I don't have right to change anything under the etc file..


So
I create .rimrc under /home/liu
Add some codes to it;;


Now
It works very well;

cvConvertImage ,cvCvtColor and cvFlip

First: How to convert a gray image to a 3 channel color image
cvCvtColor() can do GRAY2RGB
The other method,you can use it to filp image:
cvConvertImage(ori,dst,flag);
ori is original image;
dst is destination image;
flag is CV_CVTIMG_FLIP or CV_CVTIMG_SWAP_RB;
here if you just want to convert image to color , you can set flag=0;


Second: How to flip image by x axis or y axis.
Method: cvFlip
cvFlip(src,dst,flag)

here flag=0,Positive value or passive value..


See more:http://www.cs.iit.edu/~agam/cs512/lect-notes/opencv-intro/opencv-intro.html

缘起 --写这段博文是应了一个博友的要求:“您可否结合自己在国内、国外读书,自己做研究、指导学生的经历具体的说一下国内的研究生教育都有哪些欠缺?要成长为一个qualified的研究者,我们需要在哪些方面多下功夫?” 研究生应当学到些什么?(转载)

缘起 --写这段博文是应了一个博友的要求:“您可否结合自己在国内、国外读书,自己做研究、指导学生的经历具体的说一下国内的研究生教育都有哪些欠缺?要成长为一个qualified的研究者,我们需要在哪些方面多下功夫?”

这 个命题出现在我的博文《博物馆里的研究生院》的评论中(1),起因是我对谭宝林《国外的科研经历》博文的一个评论(2)。博友的名字叫“兔子”。我的研究 的一部分涉及哺乳动物啮形类的起源、演化等等。啮形类包括了啮齿目(耗子)和兔形目(兔子)两大类。看在“兔子”跟我的缘份上,就决定写这篇东西。这个命 题很难讲清楚,因为每个人的具体情况不同,我更多地是把它作为My life来写。

题外话 -- 我不是很习惯-或者说是刚习惯-别人叫我老师。最初有人叫我老师的时候,我身上会起鸡皮疙瘩。总觉得自己起步晚,一直都在念书,一年又一年总是个学生,叫 惯了老师们老师。忽然之间天翻地覆,有点慨而慷不起来。骨子里面顾忌的不光是误人子弟,更恐怕自己从此就老了去。直到今天,很多应当叫我老师的同事也很给 我面子,对我都是直呼其名,或是“哎,那个谁…”。是朋友最好。

大道理 -- 研究生的教育过程不光是选了几门课,做一篇研究论文,答辩通过了就算完。这只是最基本的内容,它让人有一定的知识和技能,并能以所学来做研究为生。教育还 有更广泛的内容,包括思想的交流;人性的理解;让自己知道在社会中的位置和责任;为人处事的举止行为;科学的世界观;团队精神;能够尊重、容忍、同时具有 批判的精神;虚心听取别人的看法,但又不盲目崇拜;懂得批评别人很容易但做出超过别人的实际工作很难;有解决问题并把事情(哪怕是一件小事)做成、做好、 做到最好的意识和努力;知道科学研究不光有关思想,同时也取决于细节;要以学术上做得更好来超越别人而不是靠打压别人来抬高自己,等等。这些东西很多都不 是课堂上能学到的,而是一点一滴领会于生活、工作、以及与人相处的环境中。所以研究生的教育在两个地方完成:课堂上和课堂外。大话说完,下面我就讲一点自 己的经历。

去美国留学 -- 我82年9月在中科院研究生院念书,84年11月拿到硕士学位,同时也开始申请出国念书。85年5月先后拿到Michigan和Columbia大学研究 生院的接收信,我选择了去后者。我的导师叫麦肯纳,是我现在工作博物馆的研究员,同时也是哥大地质学系的教授和哥大董事会成员。他和我所在的研究所以及国 内的导师周明镇先生有工作关系和私人交情。哥大还没有拿到我的GRE成绩就收了我,不知是否有走后门的嫌疑。不过等我的成绩单来了后我补交给了学校。我应 当在85年9月到哥大报道,但麦肯纳让秘书给我寄了一张地形图复印件,是他在怀俄明(Wyoming)夏天的野外工作区域, 他们在那一带做野外发掘。地图上的工作地点旁标了一个电话号码和一个人的名字,麦肯纳让我7月初到那儿去找他们。

我兜里揣了300美 元元,从北京飞到加州三藩市,住在加大一个朋友家,然后乘灰狗巴士从奥克兰到怀俄明东南角的首府夏安。 巴士连夜开,上厕所和吃饭会停一下。我吃了一路的汉堡,那是我唯一知道点的美国饭。路过犹他州的一个小镇,车站边就有吃角子老虎机,我好奇扔了四个25分 币去摇了几把,全军覆灭。到了夏安,在车站打电话联系接头的人。我的英文是二把刀,加上当地人的口音和当初学的英文有些差距,电话里的人话我听不大懂。反 复打了几次后才明白,说麦肯纳给我的电话已经disconnected, 我顿时就傻了眼。那时已是下午五点左右,我一人带了两个箱子一个包,站在空无一人的车站上,彷徨。后来我发现车站上有“黄页”(这个黄不是那个黄),是当 地的电话薄,就在上面找老板留给我的那个人名字,没想到就让我给找到了。按电话号打过去,居然真就是他。对方给了我一个他女儿的电话,说她知道麦肯纳的电 话。几经周折终于联系上了我们的营地,他们派了一辆车来接我。见到麦肯纳后给他说了我来的经过,他说凭你能找到我们,我就该你一个PhD。

我 们野外工作的地区在一个美国农民或者说是农场主的地盘上。此人叫查理.沃克,一个很憨厚的人。每天开着他的皮卡到处转。驾座边上总有两盒六瓶装的啤酒,一 边开车一边喝,美国法律在他的地盘上体现不出来。每次到我们营地前,跳下车就在车那边对着车轱辘撒尿,一边还跟我们打招呼,让我开了一回眼。我大概是查理 头一次见到的外国人,他就专门邀请我去他家玩。他有一个很大的房子,里面给我留下印象的是两样东西,一是他吃剩下的比萨饼,摊在茶几上。是微波炉烤出来的 那种,那个烂样子我觉得狗都不会吃。再就是一个巨大的玻璃罐,里面有上百公斤的一分钱分币,他说是从二战时就开始攒起来的。然后他让我开他刚买的一个大拖 拉机,参观他的车间。他的车间规模之大,工具之齐全让我膛目结舌。当时国内一个县城或者一个小城市里都很难见到这样的车间。他说除了发动机,他可以自己在 这里加工拖拉机上的任何部件。但他很孤独,他的两个儿子早就离他而去,十几年都没有回家来过。所以他很想跟我说话,而我是半懂不懂假装懂,就让他对牛弹琴 好了。这是我第一次体会到美国人物质上的富裕和情感上的贫乏。

野外完了以后,我去了麦肯纳在丹佛附近山中的庄园。麦肯纳的母系是美国 有名的卡内基家族,他们家在丹佛附近有很多资产。庄园的土地是其中一部分。园中有三幢小楼,在绿水青山中,他自己一家,他父母和给他们看庄园的“下人”家 各一幢,相隔三、四公里。站在巨大的玻璃窗前,他指着视线中的山岭,森林,湖泊和河流对我说,这些都是我家的,你到这里来要了解的一件事就是我们和你们在 所有制上的差别。记得当时和他的小儿子布鲁士有一段对话。其中说到我要好好学习,work hard。他说应该是:work hard, work smart(可以翻译成苦干加巧干)。他的话让我觉得中国人比较实干能吃苦,而美国人比较会投机取巧偷奸耍滑。很多年后,我的这个看法有了很大的转变。

哥大学习 -- 哥大原是纽约的“国王学院”,1754年10月31日,经英国国王乔治二世颁发特许状后成立,以“推进文科教育,阻止已经在这个殖民地流行的共和原则的增 长”。尽管如此,自由主义传统最终成为哥大的真正标志。此外,哥大是最早接受中国留学生的美国大学之一。早年的中国校友有顾维钧、郭秉文、陶行知、胡适、 徐志摩、陈公博,闻一多,蒋梦麟、马寅初、冯友兰、唐敖庆、吴文藻、宋子文、何炳棣、金岳霖等。仅从地质科学的角度来说,著名地质和古生物学家,德裔美国 人葛利普(Amadeus William Grabau,1870-1946)来华前任哥伦比亚大学地质系主任。他到北大后的善教影响到中国早期地学界的许多人,比如孙云铸、杨钟健、乐森璕,李四 光、黄汲清,丁道衡等。葛利普1946年逝世于北京,安息在北京大学校园里,进北大西校门往南的荷花池边。这些历史的千丝万缕让我对哥大很有好感。而这些 微妙的地方往往会不经意、但深刻地影响到人的心理,自信,以及对自我标准的要求。

我的专业是哥大和美国自然历史博物馆共同支持的。我 在哥大上课,在博物馆做研究,办公室在馆里,但住在学校附近。第一次选课时,我去征求麦肯纳的意见,他说你选什么课问题都不大,但有一门课你必须要选:微 积分。我很纳闷,我的专业是古生物,需要学的主要是生物和地质两方面的课,基本都是描述性的东西,工作中也从来不会用到微积分。我就问他为什么。他说:我 希望你能理解地球是一个削圆了的立方体。因为我在北大学过微积分,按学校的要求我不用再选这门课。但麦肯纳的回答让我悟出一些道理。他又对我说:你到这儿 来不是因为我能教你什么,你也不要指望我教你什么。我过去有很多的学生,也不是因为我教了他们什么;是你所在的这个环境,它在教你。这一点我当时不是很明 白,但后来明白了。 最后他说,有时间你到七楼库房去自己找一个博士论文课题吧。我们这个楼里有八层都是标本库房,收藏了好几十万件标本,七楼有最多的门类。我那时对专业基本 上是两眼一摸黑,什么都不知道,在接下来的一两年中,把几百个抽屉搜了一遍,最后找了一个论文题目的材料。现在看来,这个论文很普通,如果导师用心指点, 也许会找到更好的论文,而且会省很多时间。但这个过程确实也有助于我自己的独立研究能力。我不能确定哪种方式更好。一个训练好的学生不怕换研究轨道,他可 以同样做得好。但现在的很多情况是PhD研究论文本身就可能决定一个学生的命运,让人没有太多选择、调整和显示自己能力的机会和时间。对我自己来说,如果 当初麦肯纳为我指定一个题目,有可能会是一篇更好的论文,但我现在也许就是另外一个人了。

刚开始上课是不可能都听懂的,能有一半就不 错。下课后借美国学生的笔记来看,花很多的时间自己来补。这种状态在一年以后开始好转。我们这个学科要求45个基本的学分,大约平均下来是15门课。有些 我想学的课哥大没有,我就到纽约州立或市立大学去上。这些学校之间有一定的可以互选的课程。每个PhD候选人要做至少两个学期的助教。这一是对学生的训 练,二是以工换奖学金(否则学校得花钱去雇助教)。同时要把PhD论文的研究方案(proposal)做出来,在学分达到基本要求后,进行博士资格答辩。 答辩时学生介绍自己准备要做的论文。委员会五个成员,其中至少一位是本专业外的教授,每人至少30分钟提问,问题有关论文相关的内容,但更多的是关于背景 知识,问题五花八门。我记得我当时有这样一些状况。一个教授拿了几页纸,上面有几百个普通地质学方面的简单问题(他用同样的单子对付别的学生,教授偷懒的 一种),他在上面随便找问题问,要求我的回答就一个字,不用多说。比如“海底地壳是平的吗?”我答No.“地球背面和纽约相同纬度的城市有?”答 Beijing。等等。有位教授拿一张地形图,让我在上面找到我们工作的点,并说明它的坐标等参数。然后又是一张地质图,要我根据图选择一条剖面线,能够 最好地控制图中的地层。最后又拿出一块沉积岩石,让我根据它说明上下关系,沉积环境和类型,以及相关环境中可能出现的生物类群。麦肯纳问了我一些关于论文 的问题,然后背着我从口袋里拿出一个蹄兔的头骨标本,两手捂着标本的大部分,让我从看到的头骨部位鉴定是什么哺乳动物。然后,把标本放到桌上让我谈蹄兔系 统发育有什么样的问题,当前有些什么新的研究,谁做的,发表在什么地方,有什么看法,等等。 有回答不上的问题很自然。教授们并不是想让你难堪来开心,他们是测试你的知识范围和深度,看你是不是具有了去做博士论文研究的基本能力和知识。通过答辩 后,委员会给我一个评估,告诉我那些方面需要加强,以后可以去选有关的课程或自己读一些相关的书或者文章,当时就给了几篇参考文献。获得博士生资格后,基 本就进入博士论文阶段,时间会比较有弹性一点。

我的奖学金只有九个月,夏天没有钱。有一段时间(大概半年)我到曼哈顿下城打过一段时 间的工。每个周六做一天,帮人卖东西,看铺子。一天下来35元美金。一是为了挣点饭钱,二是体会一下打工生活。我到美国来最遗憾的一件事就是没有机会到餐 馆里去打过工。那是一个特别的环境和文化,很多中国学生都有的经历我错过了。

我在哥大也选了很多杂课。我喜欢美术,同时也和我的形态 学研究有关。从科学院研究生院回所后,我就参加过两个素描的夜校班,自己掏钱。在哥大时我又选了三门美术课,素描、油画和木刻,都是晚上的课,成绩还都不 错,记得木刻还是A加,印象最为深刻。西方美术中的一个核心内容是人体,所以开课后一上来就是画裸体模特儿。头一回看见漂亮MM摆个姿势在那里有点让人透 不过气来。而另外一个模特儿是个干瘦的老翁,一身青筋骨头满身的褶,几乎有点吓人。老师一堂课上就在不停的念叨“beautiful, beautiful 。”我才体会到美术家对美的看法不光是“好看”,这在一定程度上影响到我对科研的看法。那门课的老师英文次得不行,是位前苏联的雕塑家,可能还是成名人 物,自称摸过斯大林的头骨。我们的一堂课是在他Soho的家里上的,那是我最初对Soho区的认识。我的素描是半专业水平,课堂上大量的线条图,班上的同 学说应当拿到街上去摆个摊卖。其实他们不知道在纽约地区学美术的中国学生有多少。

博物馆的日子 —— 学分挣够后,我大部分时间就在博物馆里度过。博物馆的研究人员有一个自己喝咖啡的地方,圆形的屋子,有一个从来不用的壁炉,正面窗户对着中央公园。这是博 物馆中我最怀念的一个地方。博物馆研究人员每个月第一个星期一下午的例会就在这里举行。每天中午这里有免费的咖啡,研究人员,访问者,学生都可以来这里喝 咖啡,聊天。所以,这个地方可以说是研究人员的活动中心。这里也曾经是《支序系统学》(cladism)的真正发源地。当初在形成这个学说的时候,这里总 是硝烟弥漫,充满火药味。大家对很多的理论,概念,方法,哲学争论得十分的激烈,黑板上画得一塌糊涂,拍桌子打板凳互相较劲也时有出现。我去做学生的时 候,已经到了打扫战场的阶段,高潮已经过去。当然,我也受到这个争论的影响,学到了一些东西。尽管仍然有缺陷,支序系统学现在已经是生物学中的一个主流的 方法之一。这个学说和方法本身以及它的形成过程在科学上表现出来的进步主要在两个方面:1)从50-60年代以遗传学,生物种群和生物进化内容形成的、以 物种内研究为主的生物系统学,演变到种上系统的研究。2)把科学哲学(主要是Popper的假说证伪)系统地引人生物学研究中。 现在看来这当中是有缺陷的,生物学毕竟不同于物理学。但这些缺陷不仅是生物学的问题,哲学的贫乏也是一方面。但这个过程中最重要的精髓是打破了过去权威说 了就是真理的传统,而更讲究科学的证据,无论你是名教授还是名不见经传的学生。我自己对这些理论问题曾经很感兴趣,常常觉得一个念头冒出来后自己得到了真 理,晚上睡不着觉想写东西,但把那些想法写在纸上要成为有严密逻辑关系的文字时,却又怎么都说不清。最后做了一个选择,放弃理论的东西,专注具体实际的研 究课题。理论的研究太难了,而且也会因为不容易出文章影响到以后找工作,不太适合我这样英语非母语,起步比较晚的人。对我来说是自己学术当中一个决定性的 选择。

我的第一篇英文研究论文是在我做博士论文期间完成的,它和我的论文没有关系,完全是在一个偶然的机会中发现的一个题目,觉得有 意思,就做了出来。当我把写完的文章交给老板看过后,他在英文上修改了一些地方,然后写上“excellent paper” 两个字。我的一个师兄感到好奇,说麦肯纳从来不说人好,就把我的稿子拿去看。我本来是把麦肯纳的名字放到文稿上的,但他说他没有做任何事情,说: “That’s your baby.”所以我的第一篇英文论文是我单独发表的。

我在博物馆时曾经组织过一个非正式的研讨会,每个礼 拜五中午进行。大家带了午饭,一边吃一边听一边聊。一个人主讲,是学生也可能是研究人员或者是世界上任何地方来的访问者。题目杂且随意,不一定是成熟的研 究。当时来参加的人不少,比如史蒂文.J.古多尔(Stephen J. Gould)有时会来听我们的讨论。他看上去个子不高,是个很和善的人。 1972年他和N.Eldredge两人提出“间断平衡”(punctuated equilibrium)的学说而成名。 他们两人都是从从哥大拿的PhD,专业也是古生物。当年在做研究生时,史蒂文也做过一些早期哺乳动物的研究,后来没有怎么做研究,但写了大量的科普文章和 书籍,成为进化生物学最近这二、三十年的代言人,2002年去世。N.Eldredge身体很好,还在我们系里上班做事,也写了不少的科普文章。跟他们在 一起的感觉是平淡,普通的人,普通的日子。

等到博士答辩时,和博士资格答辩的感觉就完全不同了。两者的差别在什么地方呢?简单地说, 博士资格答辩时,台上的是学生,要回答下面坐的教授的问题,基本情况是考试。博士论文答辩的时候,坐在下面的教授是学生,答辩过程是答辩者显示自己的舞 台,基本情况是答疑。一篇博士论文要达到的基本目标是通过做论文研究把一个学生训练成可以独立做研究的人,而且是在这个课题内容上的权威,他在自己这个具 体研究课题上要达到研究的最前沿。当然,这个研究课题可能只是一个很窄小的研究领域,甚至只是其中的一个方面。但答辩者在这个时候应当要比教授们对论文里 的研究内容知道得更系统、全面、深入,并且有新的、超越前人的、教授们不懂的内容。如果没有做到这一点,那么,一个博士学位就欠了点火候。

博 士以后 —— 拿到博士学位后,一直在做博士后。差不多有五年的时间中都处在找不到工作要改行的巨大压力中。但我一直也都在努力的工作。到了96年的春天,忽然发现有两 个工作在等着自己,我才体会到过去的坚持和努力没有白费。我的第一个工作是麻州大学生物系助理教授。我不担心自己的研究,但对教课没有把握。我教的第一门 课是哺乳动物学,我没有学过这门课,加上英语不是母语,很担心教不好,所以很用心地去备课。我上第一堂课时,有上百个学生,各个专业的都有。很多人是来看 看这门课是否适合他们,并非一定会选这门课。我对学生说,无论你们选不选这门课,我有下面几句话要对你们说:1)人的知识结构应当是“T”字形,有一门深 入的专业,但也要有其它广博的知识。2)“Get things done”。无论做什么大事小事,一定要把事做成;事情做不成,什么好的想法都只是空谈。3)“Don’t give up”。不要轻言放弃,什么事情都要尽自己的最大努力,即使不成也不会后悔。第一个学期下来,我被学生们选为当年的最佳教师奖获奖人。但我的系主任找我谈 话说,系里从来没有给第一次开课的人最佳教师奖的,他把奖给了名单上第二顺位的人,是一位我尊敬的女老师。我在做学生时她就是教授了。我并不在乎那个奖, 但我很高兴自己在教学上的能力得到认可。我也体会到,课堂上老师的主要功能是介绍,解释基本的概念,方法和课程内容中存在的未解或最新出现的前沿课题,启 发学生如何寻找问题,让他们对一门学科产生兴趣。太多的零碎是浪费时间,而且容易让学生失去兴趣。具体的、细节上的内容,学生在需要的时候,会很容易自己 找到。概念和方法等等,学生也不是不能自己去理解或自学,但那要花比较多的时间。所以,教课的一个实际效果,是让一群学生在最短的时间对授课的内容有一定 程度的理解。这是社会教育比较有效率的体系,但不是唯一的教育方法。至少对我来说,我觉得我在课堂上学到的东西有限,多半都是自学而来。但周围的环境很重 要,常常在不经意中学到或领悟一些比掌握一门技术要重要得多的思想。

对于做研究,我就不多说了。我从来都是把我的博士生、博士后看作 同事。我们共同讨论问题,争论问题,有时会很激烈,但我们彼此尊重,我也从他们那里学到东西,很多时候他们是老师,我是学生。但我可以在很多方面对他们有 所帮助,这应当是学界的一个基本规律:做学生的时候你需要别人的帮忙,做了教授后你应当帮助别人。从多年的学生生活和找工作的艰难困苦中走过来,我能深深 体会这句话的含义。

99年我拿到了现在的位置,也是我的第二个工作,应当说是努力加运气的结果。我的办公室就在麦肯纳办公室隔壁,我的感觉就好像历史在这里碰了头。这是一个压力很大的位置,因为占有较多的资源,圈内的人对你的期望值就比较高。当然,这些是我要去面对的问题。

结语 -- 打了一通太极后,回到原来的问题:国内的研究生教育有哪些欠缺?成为一个合格 的研究者需要在哪些方面下功夫?
对第一个问题,我的回答是:欠缺一个思想活跃,有自由空间,少一点权术,多一点学术的环境。
第 二个问题和第一个问题相关。回答是应当在“大道理”里面的方方面面花功夫。但这又受制于环境的缺陷,所以这几乎是一个没有解的两难。但如果能明白这个道 理,每个人总能根据具体的情况找到一个最好的自己。一代一代的努力,总会出现一个好的环境。而每个人的生活别人是没有办法教的,只能自己去过,去努力

Thursday, May 29, 2008

Q:How to use valgrind to detect the memory leak in sub-function?


Today I use the valgrind to find the memory leak in my application.
But it just gives me such information:
==4323==
==4323== 856,984 bytes in 2 blocks are indirectly lost in loss record
7 of 7
==4323== at 0x4021259: malloc (in /usr/lib/valgrind/x86-linux/
vgpreload_memcheck.so)
==4323== by 0x403ADB9: icvDefaultAlloc(unsigned, void*)
(cxalloc.cpp:49)
==4323== by 0x804A95F: main (liuIpm_biLinear.cpp:72)
==4323==

Here liuIpm_biLinear.cpp is sub-function which was used in main(). I
can't get the information about the wrong position in subfunction.


Liu

Allocate/Release Memory function in opencv

Today I find I forget to release the Mat data.....This problem is result in running out of memory..

Allocation Release
cvCreateImage/cvCloneImage cvReleaseImage
cvCreateMat/cvCloneMat cvReleaseMat
cvCreateData cvReleaseData


Dynamic structures:
cvCreateMemStorage
cvMemStorageAlloc
cvReleaseMemStorage
cvClearMemStorage

How to detect Memory leak

1, The simple way must be use mtrace() at the first line of the main() function, and add muntrace() at the end line of main() function. You should include <mcheck.h> in the source code. Then you can do it like:
setenv MALLOC_TRACE /home/liu/tmp/trace.txt
g++ -g -o yourPro yourPro.cpp
./yourPro.cpp
mtrace youPro /home/liu/tmp/trace.txt
Then you will see the report in trace.txt..
Memory not freed:
-----------------
Address Size Caller
0x0804f0c0 0x35 at 0xb7c88327
0x0804f100 0x11 at 0xb7c88327
0x0804fd08 0x28 at 0xb7c88327
0x0804ff50 0x40 at 0xb7edcdba
0x08050000 0x40 at 0xb7edcdba
0x080500c0 0x94 at 0xb7edcdba
0xb6f9b008 0xc6268 at 0xb7edcdba
0xb7062008 0xc6268 at 0xb7edcdba
0xb71ad008 0x5d230 at 0xb7edcdba

As you see, I get some ASCII codes. It's not readable...and not like some other guys said it will be output by character.

Of course ,you can find its meaning by looking for the ascii table. The table comes from http://www.cplusplus.com/doc/ascii.html

2,using valgrind..
It's a tool for detecting the memory leak and other errors.. If you use the suse linux, you need not to download and install it.. Because it's a library in linux system.
If you want to know more you can "man valgrind" or to see "http://www.valgrind.org/"..The simple way to use it is :

valgrind --leak-check=yes ./YourApp

Then you will get a lot of informations about memory using.


In addition, there are many method to detect and trace the memory.
You can see "http://users.actcom.co.il/~choo/lupg/tutorials/unix-memory/unix-memory.html#tools_leaks"

Wednesday, May 28, 2008

How to do adaptive threshold?

  1. Convolve the image i.e. the mean or median. imageCon=imfilter(imageOri) or medfilter()
  2. Subtract the original from the convolved image. imageDif= imageOri-imageCon;
  3. Threshold the difference image with C(constant). imageThr=imageDif-C;
  4. Invert the thresholded image. imageEnd=imcomplement(imageThr);
See More:"http://homepages.inf.ed.ac.uk/rbf/HIPR2/adpthrsh.htm"
Matlab code:"http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=8647"

Canny's Two Thresholds


void cvCanny( const CvArr* image, CvArr* edges, double threshold1,double threshold2, int aperture_size=3 );

In the up sentence, the threshold1 is lower threshold, the other one is higher threshold. Canny edge detection contain three steps: First:
Gaussian filter...Smoothing the image and filter the noise..
Second:
find the edge strength by taking the gradient of the image.
Third: Use the two threshold to determine which pixel is edge.

If the edge gradient below the first threshold, it's set to zero(nonedge). If the magnitude of edge gradient is above the high threshold, it 's made
an edge. And if the edge gradient between lower and higher threshold, then it's set to zero unless there is a path from this pixel to another pixel that have
a edge gradient above higher threshold.

see more "http://www.pages.drexel.edu/~weg22/can_tut.html"

edge detection in OpenCv(sobel,laplace,canny)

void cvLaplace( const CvArr* src, CvArr* dst, int aperture_size=3 );
void cvCanny( const CvArr* image, CvArr* edges, double threshold1,double threshold2, int aperture_size=3 );
void cvSobel( const CvArr* src, CvArr* dst, int xorder, int yorder, int aperture_size=3 );

The important point is that the src image in three above funtctions must be 1 channel (gray). So you need use cvCvtColor() to change the image from BGR to Gray.
The depth of dst image in cvCanny and cvSobel can be 8u and 1 channel.But the output image of cvLaplace can't be 8u too.. It just can use 16s or 32f. I use 16s here, and it can work very well..I dont know why....

How to manage the image in memory?

Both of cvLoadImage and cvCreateImage would allocate a new memory space for image..
After you use that two function, you need cvReleaseImage funtion to release that.
Before you release them , a good habit is to use if(image) to detect if it's NULL..


Also..new and delete is allocating and release function in cpp.Please remember that new function will return a pointer..so you can't use it like this : int a =new int;

for example:
int* a=new int;
delete a;


for array:
int *a=new int[100]
delete[] a;

Tuesday, May 27, 2008

How to install 1394 camera on linux system?

Here is a method:

http://www.linux1394.org/start_install.php


But you need to check you kernel version...
you can do that by:

uname -r


How to find magic number in pnm or pgm images...???

A simple way, you can use vi or cat to see the image 's head file...


But I also try using the "identify", it gives me some image informations. Unfortunately, that's not what I want...

copyright

Before I post this subject, I dont know the copyright on the internet....
After search informations by google about copyright..
I know
I can't copy a whole of webpage in that way....
So
I will write this blog in my own words.....

Static, Shared Dynamic and Loadable Linux Libraries


There are two kinds of library in Linux:
static library(.a) and dynamic library(.so)
The difference between them is
1, static library will link with and become a part of application. But the dynamic library just be used when compile and tied to application.
2, Many setup can use a same dynamic library at a same time. But linux just load them once.
3, You can load,unload and link dynamically library with application by system function

How to build the static library:
ar -cvq libliutest.a cliutest1.o cliutest2.o
List it:
ar -t libcliutest.a
Link it:
  • cc -o myprogram progLiu.c libcliutest.a
  • cc -o myprogram progLiu.c -L/path/to/library-directory -lcliutest

How to build the dynamically library:


    gcc -Wall -fPIC -c *.c
gcc -shared -Wl,-soname,libcliutest.so.1 -o libcliutest.so.1.0 *.o
mv libliuctest.so.1.0 /opt/lib
ln -sf /opt/lib/libcliutest.so.1.0 /opt/lib/libcliutest.so
ln -sf /opt/lib/libcliutest.so.1.0 /opt/lib/libcliutest.so.1



see more website:"http://www.yolinux.com/TUTORIALS/LibraryArchives-StaticAndDynamic.html"


How to set gvim format for programming?

1,syntax on; It will make your gvim window seems more colorful;
2,set cindent; It will make your programming in c style;
3,set shiftwidth=4; It will set the distance between two level sentences.

Program Library HOWTO

Program Library HOWTO

David A. Wheeler

version 1.20, 11 April 2003

This HOWTO for programmers discusses how to create and use program libraries on Linux. This includes static libraries, shared libraries, and dynamically loaded libraries.

Link: http://www.faqs.org/docs/Linux-HOWTO/Program-Library-HOWTO.html



Monday, May 26, 2008

How to change environment variable>>???

As my shell version is tsch..
so here is a method to change environment variable under linux...
There is a file named " .tcshrc" under your root file(/home/liu)...
you can use vi to open and edit it..
so you should change the PATH and PKG_CONFIGX_PATH.....


NIce..
Thanks to IRENE...

My opencv can work again




For debian,
the shell version is bash
so we need add command in "./bashrc"

Note: maybe you want to change something in .bash_profile. but this file can not work under xwindow. so it should be better to change bashrc, as it can work when you log in the termainal or xwindow.

How to set path in environment

Because my shell is tcsh..
so here is a method to set the path..\
But the fault is that you just can use this path this time. If you relog in, then it can't work..
set path=($path $pathWhichYouWantToAdd .)


If you dont want to set it everytime when you login, you can gvim .tcshrc under you root.
I will post it later..

find files in linux


code

find -name whatYouWantToFind

see more:http://www.wallpaperama.com/forums/how-to-find-files-with-linux-shell-command-locating-file-by-name-look-search-t1207.html

How to use CvSaveImage to save pgm images in raw format??

If we use the cvSaveImage to save images in .pgm file, we will see the size of the image is very big...That's because it's plain(P2) but not raw(P5) format...
If you want to save image in pgm which is raw format, then you should do following:
1, find the grfmt_pxm.cpp under the opencv software package. In 332 line you will see GrFmtPxMWriter::WriteImage()
3, set IsBinary from false to true.
4,rebuild the library...\



how to rebuild the library..
sorry
I dont know too much about this..
But you can reinstall opencv...(how to reinstall it??? if you dont know , please google)
then you will get the .pgm image file in raw format...




see more:"http://tech.groups.yahoo.com/group/OpenCV/message/39625"

Memory cost of images


see more:"http://www.scantips.com/basics1d.html"

Large images consume large memory and make our computers struggle. Memory cost for an image is computed from the image size.

For a 6x4 inch image at 150 dpi, the image size is calculated as:

(6 inches × 150 dpi) × (4 inches × 150 dpi) = 900 × 600 pixels

900 × 600 pixels is 900 × 600 = 540,000 pixels.

The memory cost for this RGB color image is:

900 × 600 × 3 = 1.6 million bytes.

The last "× 3" is for 3 bytes of RGB color information per pixel for 24 bit color (3 RGB values per pixel, one 8-bit byte for each RGB value, which totals 24 bit color).

Different color modes have different size values, as shown below:

Image Type
Bytes per pixel
1 bit Line art
1/8 byte per pixel
(1 bit per pixel, 8 bits per byte)
8 bit Grayscale
1 byte per pixel
16 bit Grayscale
2 bytes per pixel
24 bit RGB
3 bytes per pixel
Most common for photos, for example JPG
32 bit CMYK
4 bytes per pixel
For Prepress
48 bit RGB
6 bytes per pixel

Desktops: KDE vs Gnome


v1.0.2 (en), xiando

What Linux Desktop is the Best? Gnome, KDE or something completely different?


  1. What is a desktop anyway?
  2. KDE vs Gnome, What is the better desktop environment?
  3. The Future is Freedesktop
  4. Hardware requirements
  5. The Best Desktop

1. What is a desktop anyway?

The term desktop refers to the graphical environment where you do your work. The desktop usually consists of a workspace (called the root window) with pretty icons and quite possibly a menu that pops up when you click on it, usually a panel on the top or the bottom and/or top of the screen with a menu and a lot of other practical services you may never even notice.

The most important part of any desktop is the window manager, this is the application that handles window placements and movements. The window manager is what draws a border (or no border) around your windows and makes them maximize, minimize, moves and behave according to your preferences.

2. KDE vs Gnome, What is the better desktop environment?

KDE and Gnomeare complete desktop environments that consist of a large number of tightly integrated yet still separate pieces of software. Gnome uses a window manager called metacity, KDE uses kwin. Both these desktops can be used with any other window manager if you do not like the default choice.

Linux is like Lego. You can build your own desktop environment. Both KDE and Gnome are just big packages with software aimed to look and feel the same way, work well together and generally give you a nice experience. If you dislike a component, then replace it with something else. It's that simple.

Application that are "made for gnome" or "made for kde" can be used with any desktop. This only means that that the program use a set of library functions found in their underlying gnome-libs or kdelibs. You do not need to use the actual desktops to use the applications, software made for KDE and Gnome can be used with any window manager / desktop as long as you got the proper libraries installed. There is no reason to use only applications made for the desktop you prefer, the "best software" for one task is made for KDE, the best for another task is made for Gnome. Use the best from both worlds.

Both KDE and Gnome can be customized to behave exactly the way you want. What desktop you prefer is your own choice and preference. When in doubt, try to learn both. Or experiment with other desktops. Remember, *nix applications are not locked to the desktop they are made for, Gnome applications can be used in KDE and vice versa.

There is no "best desktop", but there is a desktop that's best for you. It's a matter of preference, and hardware.

3. The Future is Freedesktop

Freedesktop.org is a software project aimed at developing shared technology standards for the X Window System. They provide common protocols like System Tray Protocol Specification, standard that allows developers to write a program that will work in KDE, GNOME, Fluxbox and other desktops who follow the Freedesktop recommendations.

is a free software project to work on interoperability and shared technology for desktop environments for the X Window System. The most famous X desktops are GNOME and KDE but any developers working on Linux/UNIX GUI technology are welcome to participate.

4. Hardware requirements

Desktop Required RAM Required CPU
fluxbox/idesk 48 100 MHz
XFCE4 128 200 MHz
Gnome 1.x 256 500 MHz
Gnome 2.x 384 800 MHz
KDE 3.x 512 1 GHz

These values are general rules of thumb. KDE will start on computer systems who should have been moved to museums long ago, like a Pentium 100 with 64 MB RAM, but it will run horribly slow. Any computer box can be used for the right purpose if you select software according to it's capacity. A Pentium 100 will let your write email and surf the Internet if you choose the MUTT email client and the web browser Lynx.

For a hot new box with lots of RAM and a fast CPU I recommend KDE 3.x or Gnome 2.x. Gnome is bloated and KDE is even more bloated. This is great, but all those fancy features demand more CPU and ram.

XFCE4 is a very nice complete fast and lightweight Desktop Environment and is probably the best choice for old, but not ancient hardware. The ROX desktop is another good light choice.

For really old hardware you should use something simple to draw icons on your desktop (like idesk) and a fast window manger like fluxbox (based on blackbox), waimea or icewm

5. The Best Desktop

Again: Try them all. This is your choice. There are plenty of Live-CD Linux distributions that let you try both KDE and Gnome without installing anything at all. Knoppix is a nice alternative.

Some people claim KDE is the best choice for beginners.


Desktop Overview

Complete Linux Desktops:

  • GNOME
    • Complete Linux desktop.
  • KDE
    • Complete Linux desktop.
  • XFCE
    • Light Linux desktop.
  • ROX
    • "Light" Linux desktop. The ROX filemanager Filer is clean and nice. ROX Panel and the Filer are excellent and can be used with other desktops.

Popular Windows Window Managers:

  • ION
    • Untraditional window manager using frames and floating workspaces, this helps you use the available on your screen more efficiently.
  • Fluxbox
    • Excellent Window manager, tabbed windowing, layers and more.
  • EvilWM
    • Minimalistic no-fuzz window manager with all basic features, excellent if you like borderless windows.

Copyright (c) 2000-2004 Øyvind Sæther. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled ["GNU Free Documentation License" http://www.gnu.org/licenses/fdl.html].

C++ convert int to string

First: output

#include <sstream>

int i = 5;
std::string s;
std::stringstream out;
out << i;
s = out.str();



Second: C++ function  itoa(int, buffer,num)

 #include <stdio.h>
#include <stdlib.h>

int main ()
{
int i;
char buffer [33];
printf ("Enter a number: ");
scanf ("%d",&i);
itoa (i,buffer,10);
printf ("decimal: %s\n",buffer);
itoa (i,buffer,16);
printf ("hexadecimal: %s\n",buffer);
itoa (i,buffer,2);
printf ("binary: %s\n",buffer);
return 0;
}

Friday, May 23, 2008

Interpolation---biLinear method

In mathematics, bilinear interpolation is an extension of linear interpolation for interpolating functions of two variables on a regular grid. The key idea is to perform linear interpolation first in one direction, and then in the other direction.

see more: This information come from:http://en.wikipedia.org/wiki/Bilinear_interpolation





Interpolation---triLinear method

see more:http://ubiety.uwaterloo.ca/~tveldhui/papers/MAScThesis/node33.html

Thursday, May 22, 2008

important point about double and int data when they are divided

Today when I am programming a small program, I make a small mistake about the double and int data;
The important point is :

int=int/int;

so I can't get a 0.75=4/3 use int data ;
but we could get that through:

double=double/int;
or
double=double/double;

Tuesday, May 13, 2008

What can I do???




As a Chinese, when I see this picture, I am crying.
They are so young, so beautiful, so unfortunately.....
Who can tell me why,,,,
Why the god takes these young life away the world... They almost have not eat good food , have not seen beautiful scene on this world, have not find their lover since they come to this world.....
The earthquake took their life, took the people 's lover, sons, sisters, brothers......
I transfer the money to Red-Cross, but it can't bring the younger life back.
I just can bless..bless the living people, wish them can get out that place earlier, wish them should give some flowers and candies to the unfortunate children .

Famous words for researcher

Nothing will ever be attempted, if all possible objections must be first overcome.

- Samuel Johnson, 1759.

The perfect is the enemy of the good.

- Voltaire, 1772 (though presumably he wrote it in French).

work

I find many useful website about Urban challenge by DARPA, which is hold every year.

test my mail blog

to see

It's simple,

It's fine

First blog

I want to write somethings about my work and research.
My interesting fields are computer vision, image processing, machine vision and learning , pattern recognition etc..
I also want to find more friends who care about these fields.