Sunday, December 16, 2012

高效人士7个习惯

其实谁都知道要培养好习惯,就是缺乏执行力。   

这是本适合参考并付诸实践的书,从时间管理到思维更新,无一不举例、分步,把行动的每一步说得很细,甚至每章后都将需要付诸实践的内容分点列示。   

七个习惯有:积极主动、以始为终、要事第一、双赢思维、知彼知己、统合综效、不断更新。   
三个成长阶段依次是:依赖期、独立期、互赖期。   
两个领域依次是:个人领域的成功、各个领域的成功。      

一、积极主动   
这部分影响较为深刻的是影响圈和关注圈,积极主动的人专注于“影响圈”,消极的人专注于“关注圈”。    
这对所关注事物的正确选择能够节省不少宝贵的时间去做正确的事情,那些处于“关注圈”的无法控制的事,“我们要做的就是改变面部线条,以微笑、真诚与平和来接受现实。纵使有太多的不满,也要学着泰然处之,这样才不至于被问题控制。”      
行动指南:   
1、减少消极词语的使用频率。   
2、找出一个学习生活中在影响圈内的棘手的问题,找出解决方案,并付诸行动。   
3、积极主动解决问题。      

二、以始为终   
这章一开始的葬礼假想,目的是为了弄清自己内心深处真正重要的愿景,以此来列出个人使命宣言,主动设计自己的生活,从而激励自己保持积极主动。然后讲了以原则为中心。   可是书上那个“和配偶约好去音乐会,老板却突然要你加班”的事例,看了以原则为中心的五个特征,还是不知道该如何选择。      
行动指南:   
1、写下自己的人生角色和目标。   
2、搜集各种资料,每周更新一次个人使命宣言。      

三、要事第一   
看到时间管理矩阵的时候,以为作者提倡我们关注第一类事务,因为是最紧迫的。结果发现,“如果你过分关注第一类事物,那么他们的范围就会越来越大,最终占据你全部的时间”。 关注“建立人际关系、撰写使命宣言、规划长期目标、防患于未然”等未雨绸缪的第二类事务,能够“平衡产出和产能的关系,将时间和精力集中在重要但是并不急迫的事情上”,做到事半功倍。     
行动指南:   
1、找出一项被自己忽略了的第二类事务。   
2、制定周计划。      

四、双赢思维   
不能双赢,就好聚好散。   要相信“资源充足,人人有份”。   
但是现实生活中,如果你抱着双赢的心态,而对方却觉得资源有限,明争暗取,不是很容易初亏么?双赢或许比较适用于商界长期合作的公司吧。      
行动指南:   
1、找到因为这个思想而获得双赢结局的人,仔细观察并向他学习。   
2、列出自己生活中最主要的三个人际关系,估算感情帐户余额,记下有助于感情投资的方式。      

五、知彼知己
学会倾听,干扰这个行为的有:价值判断、追根究底、好为人师、自以为是。   
倾听之后需进行有效的沟通,倾听不是弱点,沟通却是我的软肋,急需学习。   
有效的沟通至少有四个阶段:复述语句、用自己的语句加入解释、渗入个人的感觉、既加以解释又带有感情。   
表达的时候品德第一、感情第二、理性第三。(我往往理性第一了)   “在你能感同身受之前,人们一般不会主动向你吐露心声。”      
行动指南:   
1、下次表达自己的观点时,首先做到移情,然后站在对方的立场,争取让自己的观点得到理解。   
2、有机会旁观他人交流的时候,捂住自己的耳朵,只用眼睛观察。      

六、统合综效  
读到这一章的时候,恰好在看《怦然心动》这部电影。里面的女主角在对大自然的观察之后,开始研究学校里的学生,是整体大于部分之和还是整体小于部分之和。  
 而统合综效讲的就是如何使“整体大于部分之和”。   
接纳、尝试、创新、坦诚……这些似乎讲的是美德,或许无数的美德叠加,产生的效果必然大于一个美德。品德不佳的人,自然无法获得统合综效的效果。   而自然界食物链使得万物密切相关,被誉为统合综效的最佳典范。正是万物参与程度很深,使得创造力最大化,动植物和谐相处,成就了它无与伦比的美丽。      
行动指南:   
1、试想什么情况下需要统合综效,需要哪些条件?如何创造条件?   
2、想想有过的事例,回想和自己不一样看法,做到尊重差异。      

七、不断更新   
少看电视,多阅读,多写作,不断更新身体、智力、精神、社会/情感,依照螺旋式上升的路线成长。      
行动指南:   
1、找到一个适合自己的锻炼身体方法。   
2、每月至少阅读两本新书,并写读后感。   
3、每周对本周四方面的更新进行评估。

Monday, December 10, 2012

C Clustering Library


 
The routines in the C clustering library can be included in or linked to other C programs (this is how we built Cluster 3.0). To use the C clustering library, simply collect the relevant source files from the source code distribution. As of version 1.04, the C clustering library complies with the ANSI C standard. 
Downloadsource codemanual in PDF format.

License
The C clustering library and Pycluster were released under the Python License. Algorithm::Cluster was released under the Artistic License. The GUI-codes Cluster 3.0 for Windows, Mac OS X, and Linux/Unix, as well as the command line version of Cluster 3.0 are still covered by the original Cluster/TreeView license.

Friday, December 7, 2012

Customize ChipKit bootloader into PIC32 Chip


Burn the ChipKit bootloader into a PIC32 Chip
1.      Download the bootloader source file.
2.      Download MPLAB 8 or MPLAB X and the C32 v2.02 compiler
3.      Open one of the bootloader project which is closest to your chip. I have opened uno32.mcp and save it to another project named NewProject
4.      Open the BoardConfig.h and copy one block of code and rename the board name as ‘#elif defined(_BOARD_CHIPKIT_PIC440_)’
a.       Change the capabilities, add blCapUSBInterface
b.      Change the bootLED and download LED pin
c.       Comment # define _USE_UART1_FOR_BOOTLOADER
d.      Define the fLoadFromAVRDudeViaProgramButton pin
                        #define fLoadFromAVRDudeViaProgramButton        (PORTEbits.RE4 == 0)
#define fLoadFromAVRDudeViaVirtualProgramButton (LATEbits.LATE4 == 1)    
#define ClearVirtualProgramButton()             (LATECLR = (1 << 4))
e.       Change the Flash Bytes size : 
#define FLASH_BYTES                 0x80000             // 512K
5.      Open the project in mpLab and programe the code into the chip. Then you need to go into the build options and remove the existing preprocessor macro in the MPLAB PIC32 C Compiler tab and add in the new macro you defined (_BOARD_CHIPKIT_PIC440_).  One important thing is to specify the C32 compiler v2.02.
6.      Program the board in mpIDE with arduino code. If you can blink the LED, you are there.

The detailed process is in ChipKit forum. 
http://www.chipkit.org/forum/viewtopic.php?f=6&t=2134&start=10

Monday, December 3, 2012

Load hex into MPLAB


How can I use my HEX files with MPLAB tools to program my target?


MPLAB is the IDE Microchip provides and provides programming support for all Microchip tools (PICSTART Plus, Promate, ICD2, etc). This provides a simple guide on how to import the HEX file into MPLAB so it can be programmed into your target. For more MPLAB documentation please refer to Microchip's documentation.
First, be sure that your HEX file will run stand-alone (doesn't need a debugger). Click here for pointers on creating a stand-alone HEX file.

Follow these steps:
  1. Start MPLAB. All steps in this FAQ that refer to a toolbar means the toolbar of MPLAB.

  2. Make sure no other project/workspace is open by selecting File -> Close Workspace from the toolbar.

  3. Select your target device by selecting Configure -> Select Device. This will bring-up a dialog where you select your target PIC®MCU(PIC16F877A, PIC18F4520, etc). It also will tell you if your programming tool is supported for this device.

  4. Open the Configuration Bits dialog by selecting Configure -> Configuration Bits from the toolbar. This will open a new dialog window, at the very top of this window you will see a checkbox labeled 'Configuration bits set in code', make sure this checkbox is SET. Failure to do this will cause invalid configuration bits to be written to the device.

  5. Select your programming tool by selecting the Programmer item from the toolbar. This will give you a list of selectable programmers.

  6. Import your HEX file by selecting File -> Import from the toolbar. This will load the HEX file into memory. Importing the hex BEFORE you selected programmer or selected target device will cause the HEX file to be cleared from memory, so it is important to do it in the order shown here.

  7. Program your device. This is done via the Programmer item from the toolbar. This process is different for each programming tool. But for the ICD2, you first need to connect to the device withProgrammer -> Connect Device, and the program the device with Programmer -> Program

  8. Repeat the previous step for each target microcontroller that you wish to program with this HEX file.

Wednesday, November 21, 2012

Illusions of pastoral peace

The quite life of the country has never appealed to me. City born and city bred, I always regarded the country as something you look at through a train window, or something you occasionally visit during the weekend. Most of my friends live in the City, yet they always go into raptures at the mere mention of the country. Though they extol the virtues of the peaceful life, only one of them has ever gone to live in the country and he was back in town within six months. Even he still lives under the illusion that country life is somehow superior to town life. He is forever talking about the friendly people, the clean atmosphere, the closeness to nature and the gentle pace of living. Nothing can be compared, he maintains, with the first cockcrow, the twittering of birds at dawn, the sight of the rising sun glinting on the trees and pastures. This idyllic pastoral scene is only part of the picture. My friend fails to mention the long and friendless winter evening in front of the TV - virtually the only form of entertainment. He says nothing about the poor selection of goods in the shops, or about the unfortunate people who have to travel from the country to the city to get to work. Why people are prepared to tolerate a four-hour journey each day for the privilege of living in the country is beyond me. They could be saved so much misery and expense if they chose to live in the city where they rightly belong.

If you can do without the few pastoral pleasures of the country, you will find the city can provide you with the best that life can offer. You never have to travel miles to see your friend. They invariably live nearby and are always available for an informal chat or an evening's entertainment. Some of my acquaintances in the country come up to two once or twice a year to visit the theater as a special treat. For them this is a major operation which involves considerable planning. As the play draws to its close, they wonder whether they will ever catch that last train home. They city dweller never experiences anxieties of this sort. The latest exhibitions, films, or plays are only a short bus ride away. Shopping, too, is always a pleasure. There is so much variety that you never have to make do with second best. Country people run wild when they go shopping in the city and stagger home loaded with as many of the exotic items as they can carry. Nor is the city without its moments of beauty. There is something comforting about the warm glow shed by advertisements on cold wet winter nights. Few things could be more impressive than the peace that descends on deserted city streets at weekends when the thousands that travel to work every day are tucked away in their home in the country. I has always been a mystery to me why city dwellers, who appreciate all these things, obstinately pretend that they would prefer to live in the country. 



Monday, November 19, 2012

Sunday, November 18, 2012

自控力


想象一下未来的自己
  第一个是希望成为的自己。那个人能坚持锻炼、身体健康、充满能量。第二个是他们害怕成为的自己。那个人懒散度日,毫无活力,体弱多病。这两种想象都能让宅男宅女离开椅子。
  我们还需要记住,为现在的行为承担后果的,看似是未来的自己,实际上还是我们自己。未来的自己会对我们现在的付出感激不尽。

  虚假希望综合征
  我们需要相信,改变是可能做到的。如果失去了希望,我们就会听天由命了。但是,我们必须避免常见的意志力陷阱,即用“改变的承诺”而不是“改变”来改善我们的心情。

  最有效的解压方法包括:
  锻炼或参加体育活动、祈祷或参加宗教活动、阅读、听音乐、与家人朋友相处、按摩、外出散步、冥想或做瑜伽,以及培养有创意的爱好。

  最没效果的缓解压力的方法则包括:
  赌博、购物、抽烟、喝酒、暴饮暴食、玩游戏、上网、花两小时以上看电视或电影。

  有效和无效的策略最主要的区别在于增加大脑中改善情绪的化学物质,如血清素、Y-氨基丁酸和让人感觉良好的催产素。

Thursday, November 15, 2012

Friday, October 26, 2012

Paper 1


  1. Real Time Egomotion of a Nonholonomic Vehicle using LIDAR Measurements
This paper presents a technique to estimate in real time the egomotion of a vehicle based solely on laser range data. This technique calculates the discrepancy between closely spaced two-dimensional laser scans due to the vehicle motion using scan matching techniques. The result of the scan alignment is converted into a nonlinear motion measurement and fed into a nonholonomic extended Kalman filter model. This model better approximates the real motion of the vehicle when compared to more simplistic models, thus improving performance and immunity to outliers. The motion estimate is intended to be used for egomotion compensation in a target-tracking algorithm for situation awareness applications. In this paper, several recent scan matching algorithms were evaluated for their accuracy and computational speed: metric-based iterative closest point (MbICP), point-to-line ICP (PIICP), and polar scan matching. The proposed approach is performed in real time and provides an accurate estimate of the current robot motion. The MbICP algorithm proved to be the most advantageous scan matching algorithm, but it is still comparable to PlICP. The motion estimation algorithm is validated through experimental testing in real world conditions.


  1. Graph Optimization with Unstructured Covariance: Fast, Accurate, Linear Approximation

    This manuscript addresses the problem of optimization- based Simultaneous Localization and Mapping (SLAM), which is of concern when a robot, traveling in an unknown environment, has to build a world model, exploiting sensor measurements. Although the optimization problem underlying SLAM is nonlinear and nonconvex, related work showed that it is possible to compute an accurate linear approximation of the optimal solution for the case in which measurement covariance matrices have a block diagonal structure. In this paper we relax this hypothesis on the structure of measurement covariance and we propose a linear approximation that can deal with the general unstructured case. After presenting our theoretical derivation, we report an experimental evaluation of the proposed technique. The outcome confirms that the technique has remarkable advantages over state-of-the-art approaches and it is a promising solution for large-scale mapping.

Thursday, October 25, 2012

Brandenburg: Wasser, Sand und Kartoffeln

S4chp3

  • Vermutlich kennen Sie es- das Brandenburger Tor mitten in Berlin. Und Berlin liegt mitten in dem Land Brandenburg. Dieses Land möchten wir Ihnen heute vorstellen. Reisen Sie mit us durch Brandenburg!
  • Es ist klar, daß Brandenburg von Berlin, der Hauptstadt von Deutschland, profitiert. Berlin wird politisch und ökonomisch wieder wichtig sein - nicht nur für Deutschland, sondern ach für Europa. 
  • Wir sind jetzt in Potsdam, der Hauptstadt von Brandenburg. Hier gibt es ein wunderschönes Schloß. Sanssouci heißt es - das ist französisch und bedeutet sorgenfrei. Das Schloß ist aus dem 18. Jahrhundert, der Zeit von König Friedrich dem Großen. Er liebte die Künste: die Philosophie, die französische Literatur, die Musik - er schrieb fast nur französisch, lud Voltaire auf sein Schloß ein, er spielte Flöte und komponierte selbst ... kurz, ein Traumleben. 200 Jahre später gab es eine andere Traumwelt: das Kino. In der Nähe von Potsdam, in Babelsberg, gab es große Filmstudios. Hier produzierte man viele berühmte Filme ...

Tuesday, October 23, 2012

Was möchten Sie machen?


  • Sag mal, weißt du, warum Frau Berger uns sprechen will ?
  • Nein, keine Ahnung! Aber ich weiß, warum ich sie sprechen will.
  • Ich auch!
  • Schön, daß Sie alle gekommen sind. 
  • Wieso alle? Mich hat sie nicht gefragt, ob ich komme...
  • Ex, Ich habe gehört, was du gesagt hast. Entschuldige, du bist natürlich auch willkommen! Also- ich habe eine wichtige Entscheidung getroffen. 
  • Jetzt wird es interessant. Ich auch, Frau Berger.
  • Ich muß Ihnen unbedingt etwas sagen.
  • Gleich Hanna, gleich.
  • Aber es ist sehr wichtig. Ich werde nämlich heiraten. Und da möchte ich nicht mehr arbeiten.
  • Ja, das ist wirklich eine Überrraschung.
  • Ich kann auch nicht mehr hier arbeiten. Ich bin doch mit meinem Studium fertig und habe gleich einen super Auftrag bekommen.
  • Was für einen denn?
  • Ich soll Reportagen über die östlichen Bundesländer schreiben. 
  • Interessant - genau dahin will ich gehen.
  • Wie bitte? 
  • Was?
  • s
  • Frau Berger, jetzt sind Sie aber endlich dran! Mich interessiert, was Sie machen möchten.
  • Ganz einfach. Ich bin jetzt so lange in Aachen, ich kenne die Stadt und die Menschen - jetzt möchte ich ein neues Hotel aufmachen?
  • Und wo?
  • Irgendwo in den östlichen Bundesländern - vielleicht auf Rügen order in Leipzig order ...
  • In Leipzig? In der Heimatstadt von Dr. Thürmann?
  • Ich weiß noch nicht, ob ich wieder in eine Stadt möchte. Ich brauche einfach noch Zeit, ich will in Ruhe suchen.
  • Und dabei haben Sie einen Reisebegleiter. Sie reisen und suchen ein neues Hotel, ich reise und schreibe Reportagen. 
  • Und ich? Nimmst du mich mit?
  • Sowieso!

Wednesday, October 17, 2012

Das ist eine brillante Idee

Series 4 chap 1


  • Gibt es schon Reaktionen auf den Sprachkurs?
  • Ja, wir haben viele Hörerbriefe bekommen.
  • Und was steht in den Briefen?
  • Die kann ich doch nicht alle vorlesen. Das dauert viel zu lange.
  • Nicht alle, aber eininge- bitte!
  • Ja, das interessiert mich auch.
  • Na gut.
  • Aber bitte - machen Sie es kurz!
  • Hier habe ich einen Brief von Herrn Card aus America - Moment. ´Mir gefallen die Abentuer von Andreas - als Portier im Hotel Europa.´
  • Mir auch.
  • s
  • Und hier ist ein Brief von Angela aus Kolumbien. Sie schrebt: ´ Ich bin so glücklich, weil ich die Grammatik studiert habe. Jetzt verstehe ich den Akkusative - der war immer .....´
  • Grammatik, Grammatik, Akkusative - das ist ja langweilig! Schreben die Hörer denn nichts über mich? Wie finden die Hörer mich, das will ich wissen!
  • Kein Problem, Ex. Hier ist ein Brief aus England - da steht etwas über dich! ´The introduction of Ex is a brilliant idea´
  • Das verstehe ich doch nicht! Was heißt das denn auf Deutsch?
  • Du bist eine Brillante Idee!
  • Idee? Wieso bin ich eine Idee! Ich bin ich!
  • s
  • Das hier ist noch ganz wichtig: Manche Hörer schreiben, daß sie Ex nicht so gut verstehen.
  • Wir können ihr ja eine andere Stimme geben.
  • Porbieren wir es doch mal! Ex, sprich mal etwas!
  • Bei dem Zauberwort sollte ich das Buch verlassen und ...
  • Okay! Stop! Und noch einmal bitte!
  • Bei dem Zauberwort sollte ich das Buch verlassen und ... 
  • Kann ihre Stimme nicht ganz normal bleiben?
  • Nein - Ex ist ja eine besondere Person, ein weiblicher Kobold, da braucht sie auch eine besondere Stimme.
  • Das finde ich auch!
  • Aber das ist ein techniches Problem. Das lösen wir später.

Wednesday, October 10, 2012

Berlin Alexanderplatz

Series 3 chap 22

Liebe Eleten,

heute war ich in Ostberlin, auf dem berühmten Alex. Schon von weitem sieht man den hohen Fernsehturm, 365 Meter ist der hoch!

Ehrlich gesagt: Ich war enttäuscht. Der Alex ist ein großer Platz, groß und kolossal, aber ziemlich leer - es fahren keine Autos, nur ein paar Fußgänger laufen herum.

Natürlich weiß ich, daß der Alex seit 1964 sehr verändert ist. Man hat damals viele Hochhäuser gebaut, z.B. das Hotel Stadt Berlin - es ist imposant und häßlich. Die anderen Hochhäuser übrigens auch...

Direkt am Bahnhof Alexanderplatz ist das ganz anders. Ja, es gibt ihn noch, den alten Bahnhof. Und da ist alles voller Leben.

Draußen sind viele Buden, man kann alles mögliche kaufen: Kleidung, Geschir, Obst, Gemüse, Essen ...

Wißt Ihr, warum der Platy Alexanderplatz heißt? Nein? Aber ich! Als der russische Zar Alexander der Erste 1805 den König in Berlin besucht hat, hat man dem Platz den Namen Alexanderplatz gegeben.
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

Früher war der Alex wirklich die Mitte von Berlin. Neun Starßen trafen hier zusammen und überall waren Menschen: Sie waren auf den Straßen und verkauften dor ihre Waren- Zeitungen, Zigaretten, Kleidung, Kohlen, Holz..... Sie waren in den Kneiden, tranken Bier und redeten ... Sie arbeiteten hart.

Woher ich das alles so genau weiß? Ich habe das Buch von Döblin gekauft: Berlin Alexanderplatz. Da geht es ja um einen einfachen Straßenhändler am Alex. Und der wollte vom Leben mehr haben als ein Butterbrot ... Das kann man ja gut verstehen, oder?

Heute abend gehe ich in den Film ´ Berlin Alexanderplatz´ von Fassbinder. Ihr seht: es geht mir gut.

Alles Liebe

Euer Andreas

Monday, September 17, 2012

'In contrast' vs. 'by contrast'



http://languagetips.wordpress.com/category/in-or-by-contrast/

“In contrast” vs. “by contrast”

 “In contrast” and “by contrast” mean the same thing: the act of comparing in order to show differences. The difference lies in the way the words are used. “In contrast” is usually followed by “to” or “with” and requires a noun to follow it. “By contrast” is usually followed or preceded by the subject of the sentence.

Examples:
In contrast to the diligent bee, the butterfly flies hither and yon with no apparent purpose.
In contrast with the chorus of birdsongs in my backyard, my front yard is serenaded by the sound of rumbling buses flying down the street.
By contrast, the Picasso is more vibrant and full of life.
The cats will often sleep the day away. The dogs, by contrast, never settle down.

Thursday, September 6, 2012

Canny Edge on Webcam



From StackOverflow

  1. Remember that OpenCV works with BGR, so when you convert, use the CV_BGR2GRAY
  2. Be careful with the threshold in Canny, they should be different and with a ratio of 2 or 3( recommended). Might try 100-200...
  3. Try to avoid printing in every loop, that slows down a little bit your code
  4. For filters, try not to use a big window. A size 3 0r 5 at most is usually fine (Depending on your application). A size 11 is probably not required.
  5. consider using cv::Mat. It is far more flexible than IplImage and in fact ( no more Release Image...)
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
using namespace cv;
int main(int, char**)
{
    namedWindow( "Edges", CV_WINDOW_NORMAL ); 
    CvCapture* capture = cvCaptureFromCAM(-1);

    cv::Mat frame; cv::Mat out; cv::Mat out2;

    while(1) {
        frame = cvQueryFrame( capture );

        GaussianBlur( frame, out, Size(5, 5), 0, 0 );
        cvtColor( out ,out2, CV_BGR2GRAY ); // produces out2, a one-channel image (CV_8UC1)
       Canny( out2, out2, 100, 200, 3 ); // the result goes to out2 again,but since it is still one channel it is fine

        if( !frame.data ) break;
        imshow( "Edges", out2 );

        char c = cvWaitKey(33);
        if( c == 'c' ) break;
    }
    return 0;
}

CvArr、Mat、CvMat、IplImage、BYTE转换


CvArr、Mat、CvMat、IplImage、BYTE转换(总结而来)

http://blog.csdn.net/wuxiaoyao12/article/details/7305848
 一、Mat类型:矩阵类型,Matrix。
    在openCV中,Mat是一个多维的密集数据数组。可以用来处理向量和矩阵、图像、直方图等等常见的多维数据。
    Mat有3个重要的方法:
         1、Mat mat = imread(const String* filename);            读取图像
         2、imshow(const string frameName, InputArray mat);      显示图像
         3、imwrite (const string& filename, InputArray img);    储存图像
    Mat类型较CvMat与IplImage类型来说,有更强的矩阵运算能力,支持常见的矩阵运算。在计算密集型的应用当中,将CvMat与IplImage类型转化为Mat类型将大大减少计算时间花费。
A.Mat -> IplImage
同样只是创建图像头,而没有复制数据。
例: // 假设Mat类型的imgMat图像数据存在
IplImage pImg= IplImage(imgMat); 
B.Mat -> CvMat
与IplImage的转换类似,不复制数据,只创建矩阵头。
例: // 假设Mat类型的imgMat图像数据存在
     CvMat cvMat = imgMat;

二、CvMat类型与IplImage类型:“图像”类型
       在openCV中,Mat类型与CvMat和IplImage类型都可以代表和显示图像,但是,Mat类型侧重于计算,数学性较高,openCV对Mat类型的计算也进行了优化。而CvMat和IplImage类型更侧重于“图像”,openCV对其中的图像操作(缩放、单通道提取、图像阈值操作等)进行了优化。
补充:IplImageCvMat派生,而CvMatCvArr派生即CvArr -> CvMat -> IplImage
            CvArr用作函数的参数,无论传入的是CvMatIplImage,内部都是按CvMat处理。
1.CvMat
A.CvMat-> IplImage
IplImage* img = cvCreateImage(cvGetSize(mat),8,1);
cvGetImage(matI,img);
cvSaveImage("rice1.bmp",img);
B.CvMat->Mat
与IplImage的转换类似,可以选择是否复制数据。
Mat::Mat(const CvMat* m, bool copyData=false);
在openCV中,没有向量(vector)的数据结构。任何时候,但我们要表示向量时,用矩阵数据表示即可。
但是,CvMat类型与我们在线性代数课程上学的向量概念相比,更抽象,比如CvMat的元素数据类型并不仅限于基础数据类型,比如,下面创建一个二维数据矩阵:
              CvMat* cvCreatMat(int rows ,int cols , int type);
这里的type可以是任意的预定义数据类型,比如RGB或者别的多通道数据。这样我们便可以在一个CvMat矩阵上表示丰富多彩的图像了。

2.IplImage
在类型关系上,我们可以说IplImage类型继承自CvMat类型,当然还包括其他的变量将之解析成图像数据。
IplImage类型较之CvMat多了很多参数,比如depth和nChannels。在普通的矩阵类型当中,通常深度和通道数被同时表示,如用32位表示RGB+Alpha.但是,在图像处理中,我们往往将深度与通道数分开处理,这样做是OpenCV对图像表示的一种优化方案。
IplImage的对图像的另一种优化是变量origin----原点。在计算机视觉处理上,一个重要的不便是对原点的定义不清楚,图像来源,编码格式,甚至操作系统都会对原地的选取产生影响。为了弥补这一点,openCV允许用户定义自己的原点设置。取值0表示原点位于图片左上角,1表示左下角。
dataOrder参数定义数据的格式。有IPL_DATA_ORDER_PIXEL和IPL_DATA_ORDER_PLANE两种取值,前者便是对于像素,不同的通道的数据交叉排列,后者表示所有通道按顺序平行排列。
IplImage类型的所有额外变量都是对“图像”的表示与计算能力的优化。
A.IplImage -> Mat
IplImage* pImg = cvLoadImage("lena.jpg");
Mat img(pImg,0); // 0是不複製影像,也就是pImgimgdata共用同個記憶體位置,header各自有
B.IplImage -> CvMat
1CvMat mathdr, *mat = cvGetMat( img, &mathdr );
法2CvMat *mat = cvCreateMat( img->height, img->width, CV_64FC3 );
  cvConvert( img, mat );
C.IplImage*-> BYTE*
BYTE* data= img->imageData;

CvMat和IplImage创建时的一个小区别:
1、建立矩阵时,第一个参数为行数,第二个参数为列数。
CvMat* cvCreateMat( int rows, int cols, int type );
2、建立图像时,CvSize第一个参数为宽度,即列数;第二个参数为高度,即行数。这 个和CvMat矩阵正好相反。
IplImage* cvCreateImage(CvSize size, int depth, int channels );
CvSize cvSize( int width, int height );

IplImage内部buffer每行是按4字节对齐的,CvMat没有这个限制

补充:
A.BYTE*-> IplImage*
img= cvCreateImageHeader(cvSize(width,height),depth,channels);
cvSetData(img,data,step);
//首先由cvCreateImageHeader()创建IplImage图像头,制定图像的尺寸,深度和通道数;
//然后由cvSetData()根据BYTE*图像数据指针设置IplImage图像头的数据数据,
//其中step指定该IplImage图像每行占的字节数,对于1通道的IPL_DEPTH_8U图像,step可以等于width

Wednesday, September 5, 2012

Resolving tbb_debug.dll in OpenCV 2.3.1


Resolving tbb_debug.dll in OpenCV 2.3.1

origin:

To resolve the tbb_debug.dll, for windows: 

Download tbb files at 
http://threadingbuildingblocks.org/download#stable-releases

You may choose to place the folder at ..\OpenCV2.3\build\common
 

Set up the following:

• Environment variables 
$(TBBROOT)bin\ia32\vc10

C/C++ Properties 
• General: add an additional include directory:
"$(TBBROOT)\include"

Linker Properties 
• General: add an additional library directory (shown for Visual
Studio 2010 32-bit library):
$(TBBROOT)lib\ia32\vc10

• Input: add an additional dependency 
tbb_debug.lib or tbb.lib


This should resolve the error message.


Sunday, September 2, 2012

04.10.10 - Installing OpenGL/Glut libraries in Ubuntu

from http://www.kiwwito.com
The first step is to install the development libraries of OpenGL/Glut in Ubuntu:
sudo apt-get install freeglut3 freeglut3-dev

For newer versions of Ubuntu (>= 11.10) you have to install another package because the linker does't link anymore

.
sudo apt-get install binutils-gold

Create a test file (test.c):


#include <GL/glut.h>

//Drawing funciton
void draw(void)
{
  //Background color
  glClearColor(0,1,0,1);
  glClear(GL_COLOR_BUFFER_BIT );
  //Draw order
  glFlush();
}

//Main program
int main(int argc, char **argv)
{
  glutInit(&argc, argv);
  //Simple buffer
  glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB );
  glutInitWindowPosition(50,25);
  glutInitWindowSize(500,250);
  glutCreateWindow("Green window");
  //Call to the drawing function
  glutDisplayFunc(draw);
  glutMainLoop();
  return 0;
}

Compile the file linking the OpenGL/Glut libraries:
gcc -lGL -lglut test.c -o test

Wednesday, August 29, 2012

Switch


#include "iostream"
#include "iomanip"
using namespace std;

void main()
{
// Code 3, test switch fuction
bool quit = false;
char response;
cout << "Please input a, b, c,or q" << endl;
cin >> response;
while(quit == false)
{
cin >> response;
switch(response)
{
case 'a': cout <<"You chose 'a'" << setw(3) << endl; break;
case 'b': cout <<"You chose 'b'" << setw(3) << endl; break;
case 'c': cout <<"You chose 'c'" << setw(3) << endl; break;
case 'q': cout <<"You chose 'q', Program Will quit" << setw(3) << endl; quit = true; break;
default : cout <<"Please choose only a b c q" << endl;
}
};
while (getchar())
{
if (getchar())  break;
}///
//return 0;
}

Tuesday, August 28, 2012

IF 。。。。


IF.....


IF you can keep your head when all about you
Are losing theirs and blaming it on you,
If you can trust yourself when all men doubt you,
But make allowance for their doubting too;

If you can wait and not be tired by waiting,
Or being lied about, don't deal in lies,
Or being hated, don't give way to hating,
And yet don't look too good, nor talk too wise:
If you can dream - and not make dreams your master;
If you can think - and not make thoughts your aim;
If you can meet with Triumph and Disaster
And treat those two impostors just the same;

If you can bear to hear the truth you've spoken
Twisted by knaves to make a trap for fools,
Or watch the things you gave your life to, broken,
And stoop and build 'em up with worn-out tools:

If you can make one heap of all your winnings
And risk it on one turn of pitch-and-toss,
And lose, and start again at your beginnings
And never breathe a word about your loss;

If you can force your heart and nerve and sinew
To serve your turn long after they are gone,
And so hold on when there is nothing in you
Except the Will which says to them: 'Hold on!'

If you can talk with crowds and keep your virtue,
' Or walk with Kings - nor lose the common touch,
if neither foes nor loving friends can hurt you,
If all men count with you, but none too much;
If you can fill the unforgiving minute
With sixty seconds' worth of distance run,
Yours is the Earth and everything that's in it,
And - which is more - you'll be a Man, my son!

Friday, August 17, 2012

False positive and False negative

Type I error

type I error, also known as an error of the first kind, occurs when the null hypothesis (H0) is true, but is rejected. It is asserting something that is absent, a false hit. A type I error may be compared with a so called false positive (a result that indicates that a given condition is present when it actually is not present) in tests where a single condition is tested for. Type I errors are philosophically a focus of skepticism and Occam's razor. A Type I error occurs when we believe a falsehood.[1] In terms of folk tales, an investigator may be "crying wolf" without a wolf in sight (raising a false alarm) (H0: no wolf).
The rate of the type I error is called the size of the test and denoted by the Greek letter \alpha (alpha). It usually equals the significance level of a test. In the case of a simple null hypothesis \alpha is the probability of a type I error. If the null hypothesis is composite, \alpha is the maximum (supremum) of the possible probabilities of a type I error.

False positive error

false positive error, commonly called a "false alarm" is a result that indicates a given condition has been fulfilled, when it actually has not been fulfilled. In the case of "crying wolf" - the condition tested for was "is there a wolf near the herd?", the actual result was that there had not been a wolf near the herd. The shepherd wrongly indicated there was one, by calling "Wolf, wolf!".
A false positive error is a Type I error where the test is checking a single condition, and results in an affirmative or negative decision usually designated as "true or false".

Type II error

type II error, also known as an error of the second kind, occurs when the null hypothesis is false, but it is erroneously accepted as true. It is missing to see what is present, a miss. A type II error may be compared with a so-called false negative (where an actual 'hit' was disregarded by the test and seen as a 'miss') in a test checking for a single condition with a definitive result of true or false. A Type II error is committed when we fail to believe a truth.[1] In terms of folk tales, an investigator may fail to see the wolf ("failing to raise an alarm"; see Aesop's story of The Boy Who Cried Wolf). Again, H0: no wolf.
The rate of the type II error is denoted by the Greek letter \beta (beta) and related to the power of a test (which equals 1-\beta).
What we actually call type I or type II error depends directly on the null hypothesis. Negation of the null hypothesis causes type I and type II errors to switch roles.
The goal of the test is to determine if the null hypothesis can be rejected. A statistical test can either reject (prove false) or fail to reject (fail to prove false) a null hypothesis, but never prove it true (i.e., failing to reject a null hypothesis does not prove it true).

False negative error

false negative error is where a test result indicates that a condition failed, while it actually was successful. A common example is a guilty prisoner freed from jail. The condition: "Is the prisoner guilty?" actually had a positive result (yes, he is guilty). But the test failed to realize this, and wrongly decided the prisoner was not guilty.
A false negative error is a type II error occurring in test steps where a single condition is checked for and the result can either be positive or negative.

Example

As it is conjectured that adding fluoride to toothpaste protects against cavities, the null hypothesis of no effect is tested. When the null hypothesis is true (i.e., there is indeed no effect), but the data give rise to rejection of this hypothesis, falsely suggesting that adding fluoride is effective against cavities, a type I error has occurred.
A type II error occurs when the null hypothesis is false (i.e., adding fluoride is actually effective against cavities), but the data are such that the null hypothesis cannot be rejected, failing to prove the existing effect.
In colloquial usage type I error can be thought of as "convicting an innocent person" and type II error "letting a guilty person go free".
Tabularised relations between truth/falseness of the null hypothesis and outcomes of the test:
Null hypothesis (H0) is trueNull hypothesis (H0) is false
Reject null hypothesisType I error
False positive
Correct outcome
True positive
Fail to reject null hypothesisCorrect outcome
True negative
Type II error
False negative

Understanding Type I and Type II errors

From the Bayesian point of view, a type I error is one that looks at information that should not substantially change one's prior estimate of probability, but does. A type II error is one that looks at information which should change one's estimate, but does not. (Though the null hypothesis is not quite the same thing as one's prior estimate, it is, rather, one's pro forma prior estimate.)
Hypothesis testing is the art of testing whether a variation between two sample distributions can be explained by chance or not. In many practical applications type I errors are more delicate than type II errors. In these cases, care is usually focused on minimizing the occurrence of this statistical error. Suppose, the probability for a type I error is 1% , then there is a 1% chance that the observed variation is not true. This is called the level of significance, denoted with the Greek letter \alpha (alpha). While 1% might be an acceptable level of significance for one application, a different application can require a very different level. For example, the standard goal of six sigma is to achieve precision to 4.5 standard deviations above or below the mean. This means that only 3.4 parts per million are allowed to be deficient in a normally distributed process