How to compile opencv 2.4.3 x86 and x64 using Visual Studio 2012.

Share Button
  1. Download and extract opencv 2.4.3 for windows. (I extracted it to E:/Program Files/opencv)
  2. Download and install CMake for windows.
  3. I’ll show you how to build x86 version as following, but x64 version is almost the same steps. I’ll point out those steps different than x86.
  4. Open CMake and select source code directory as E:/Program Files/opencv and binary directory as E:/Program Files/opencv/build/x86/vc11. You may need to create this directory yourself. If you look into E:/Program Files/opencv/build directory, you will notice there are x86 and x64 which indicate different versions. In those directory, there are pre-builded vc9 and vc10 libs, but there are no vc11 corresponding to Visual Studio 2012, so we have to build it ourselves. At the end, what we need is the same as those in vc9/vc10 directory, which are bin and lib files.
  5. Click “Configure” and select “Visual Studio 11″.
  6. Select whatever you want to build and configure, or leave it by default, and click “Configure” again and then click “Generate”. You will see “Configuring done” and “Generating done” in the log.
  7. You can close CMake now. Go to your build directory, you will see a Visual Studio 2012 project named OpenCV, open it with Visual Studio 2012.
  8.  Wait until it says “Ready” on the lower left corner.
  9. We will build debug libs first, so select “Debug”, later we will build release libs.
  10. Select the solution and click “Build Solution”, and wait until it’s done. There should be no fails.
  11. Now we’ve built the libraries and binaries, let’s install them which means collect them into install directory later we will use. You can skip this step and move them into some directories by yourself. To install, by clicking “Build” on “INSTALL”. And you should not see fails.
  12. Now we’ve done building and installing debug version of opencv, let’s do the same with release version.
  13. Ok! Now we’ve built opencv using Visual Studio 2012 successfully! You can delete everything except install directory. In install directory, you should see at least bin and lib directories. Now let’s test it with hello world program. You need to add binaries into system path in order for windows to pick up those binaries while running program. For me I added “E:Program Filesopencvbuildx86vc11installbin” into my path.
  14. Create a new win console project and paste some opencv hello world programs, for example:
  15. Select “Property Manager” tab at the bottom, and click a property for example “Microsoft.Cpp.Win32.user”.
  16. Add additional include directories to “C/C++” -> “All Options” -> “Additional Include Directories”. In my case, I added “E:Program Filesopencvbuildx86vc11installinclude”, “E:Program Filesopencvbuildx86vc11installincludeopencv” and “E:Program Filesopencvbuildx86vc11installincludeopencv2″.
  17. In “Linker” -> “All Options” -> “Additional Library Directories”, add where your libraries are, in my case it’s “E:Program Filesopencvbuildx86vc11installlib”. In ”Linker” -> “All Options” -> “Additional Dependencies”, add libraries you use. In my case, I added all debug libraries. Libraries end with “d” are debug libraries, without “d” are release libraries.
  18. Build and run your program!

Most popular bond types.

Share Button
  • Callable bonds
    A callable (or redeemable) bond gives the issuer the right to buy back all or some of the issue prior to the stated maturity date. The bonds are redeemable by the issuer at a specified price (call price), which may be the par value of the bond or  a price higher than the par value. Callable bonds are particularly popular with corporate and municipal bond issues in the US. The most common scenario occurs when market interest rates fall below the interest rate on the bond. In such a situation, the issuer can benefit by redeeming the bond and issuing another bond at a lower interest rate (refunding). From an investor’s point of view, this may result in the surrendering of a high-coupon issue and reinvestment in a bond issue at a lower, less attractive interest rate. To compensate the investor, yields on callable bonds are generally higher than those on equivalent non-callable issues.
    Call features may provide for the following:

    • Optional redemption
      The issuer has the right, but no the obligation, to redeem the issue after a specified period of time.
    • Extraordinary redemption
      The issuer has the right to redeem the issue if certain specified events occur (for example, destruction or damage to a facility/project that was being financed by the bond issue). If the specified event occurs, redemption may be mandatory (extraordinary mandatory redemption) or at the issuer’s choice (extraordinary optional redemption).
    • Sinking fund redemption
      The issuer is required to redeem some bonds on a periodic basis to satisfy a sinking fund provision.
  • Floating rate notes (floaters)
    Floating rate notes (FRNs) are bonds with coupon rates that are reset periodically, based on a margin or spread over a reference rate. Popular reference rates include 3- or 6-month Libor (London Interbank Offered Rate), Euribor (Euro Interbank Offered Rate), and yields on short-term government securities. Typical interest reset periods are therefore every quarter or every six months.
    Some borrowers have issued bonds that combine the features of both fixed and floating rate issues. For example, the bond may have a fixed rate for the first year following its issue and then revert to a floating rate for the remainder of its term.
  • Zero-coupon bonds (zeros)
    A zero-coupon bond is a bond with no coupon rate. Investors in these securities do not receive any interest payments during the life of the bond. Instead, the bonds provide a return to investors by being sold at a discount to their redemption (par) value. At maturity, the holder receives the full redemption amount. This amount includes the initial investment amount plus the accrued interest over the life of the bond.
  • Inflation-linked bonds (linkers)
    Inflation- or index-linked securities (linkers) provide protection to investors against inflation. Linkers pay a fixed coupon plus an amount to compensate for inflation. The fixed coupon represents the real yield of the security, and the inflation amount is tied to a relevant price index.
  • High yield (junk) bonds
    High yield bonds are securities rated below investment grade, that is, rated below Baa3 (Moody’s) or BBB- (Standard & Poor’s). This form of debt carries a higher risk of default compared with other forms of debt, but compensates investors by paying a higher yield.
  • Covered bonds
    Covered bonds are bonds collateralized by commercial and/or residential mortgages and/or public sector assets. They represent the senior debt instrument of the issuer, with the bondholder having full recourse to a pool of assets ring-fenced from the issuer’s other assets. Covered bonds are similar in some ways to asset-backed securities; however, the pool of assets is not placed in a special purpose vehicle (SPV) but instead remains on the balance sheet of the issuer. Segregation of the pool assets has to be undisputed, otherwise a high rating for the pool may not be achieved. The credit strength of the issuer is the main driver.
  • Stepped-coupon bonds
    Stepped-coupon bonds are a variation of straight fixed rate bonds that have been issued by some borrowers. These are securities whose coupon rate increases during the life of the bond.
    For example, a 5-year ‘step-up’ bond might be issued with a coupon of 5% for the first year, 5.5% for the second year, 6% for the third year, and so on. After an initial non-callable period, step-up bonds are callable at each step-up date and are therefore attractive to issuers with a strongly held view that interest rates will fall – a replacement bond can then be issued at a lower rate.
  • Dual currency bonds
    Dual currency bonds are quite common in the international bond (Eurobond) market. They are bonds where coupon payments can be made in one currency and principal payments in another currency.
  • Securitized bonds
    Securitization is the term applied to the pooling and packaging of similar loans into marketable securities (such as bonds) to be sold to investors.
    A mortgage-backed security (MBS) represents a securitized interest in a pool of mortgages (usually residential mortgages), while an asset-backed security (ABS) represents a securitized interest in non-mortgage financial assets, such as credit card balances, car loans, equipment lease receivables, and so on.
  • Hybrid securities (hybrids)
    A hybrid is a security that combines the characteristics of two or more financial instruments, generally debt and equity characteristics.
    An example of a hybrid is the convertible bond (convertible), which is a bond that, at an agreed future date and price, can be converted into other securities (usually the common stock of the issuing company). The decision to convert is at the discretion of the investor.

Four main categories of bond issuers.

Share Button
  • Sovereign governments
    They issue bonds principally to cover a shortfall between taxation revenue and expenditure.
  • Government agencies, municipals, and local government authorities
    They issue bonds to fund their services and operations.
  • Various supranational authorities
    Such as the International Bank for Reconstruction and Development (IBRD, the original institution of the World Bank Group) and the International Finance Corporation (IFC, a member of the World Bank Group), engage in major bond issuance to fund lending to developing countries.
  • Corporations
    Corporations of all types and sizes use bonds as an important source of funding for their operations and activities.

Terminology of bond market.

Share Button
  • Principal
    The principal of a bond is the amount that the issuer borrows and agrees to repay the bondholder on the maturity date. It is also called par value, face value, nominal value redemption value or maturity value.
  • Coupon
    Coupon is just another name for interest which payed by bond issuer.
  • Price
    In the secondary market, bond price is not necessary equal to it’s par value. It depends on number of factors, including market interest rates, credit quality, maturity, and supply and demand.
  • Yield
    The yield of a bond is the rate of return received from investing in the bond, and is based on the price paid for the bond and the coupon payment. Current yield is the simplest measure of the tield on a bond, which relates the annual interest payment to the current market price.
    $latex Current,yield = frac{Annual,coupon}{Price} &bg=000000&fg=33cc00&s=4$
    There are a number of problems associated with current yield as a measure of the return on a bond. It considers only the coupon income, but no other source of return. For example, it ignores any capital gain or loss realized from the difference between the price paid for a bond and the redemption value. It also ignores the time value of money principle and the interest-on-interest that can be earned by reinvesting coupon payments.
    A more meaningful measure of the return on a bond is the yield to maturity (YTM).
  • Maturity
    The maturity of a bond is simply the length of time before it expires. A bond’s years to maturity – term or tenor – can be any length of time, although debt securities with a term of less than one year are generally classified as money market instruments. Bonds are generally issued with maturities up to 10 years, although bonds with 100-year maturities have also been issued. Bonds with maturities of less than 10 years are referred to as ‘notes’ in some markets.
  • Credit quality
    Good quality credits generally trade at a lower yield and therefore at higher prices than poorer quality credits. Issues with a high quality credit rating can command a higher price/lower yield in the market. Investors expect a higher yield for the greater risk they incur when investing in bonds that may not be repaid.

Effective C++ item 22: Declare data members private.

Share Button

It seems obvious you should always declare data members private. But sometimes you may violate this rule without realizing it. Defining data members private is all about encapsulation.

If you hide your data members from your clients, you can ensure that class invariants are always maintained, because only member functions can affect them. Further-more, you reserve the right to change your implementation decisions later. If you don’t hide such decisions, you’ll soon find that even if you own the source code to a class, your ability to change anything public is extremely restricted, because too much client code will be broken. Public means unencapsulated, and practically speaking, unencapsulated means unchangeable, especially for classes that are widely used.

Generally speaking, you should restrict as much as possible for accessing data members. Fewer public data members, better encapsulation it is.

“Effective C++” Third Edition by Scott Meyers.

Effective C++ item 21: Don’t try to return a reference when you must return an object.

Share Button

Once programmers grasp the efficiency implications of pass-by-value for objects (see Item 20), many become crusaders, determined to root out the evil of pass-by-value wherever it may hide. Unrelenting in their pursuit of pass-by-reference purity, they invariably make a fatal mistake: they start to pass references to objects that don’t exist. This is not a good thing. For example:

In the code above, we defined operator* returning a const reference of Rational instead of a const value of Rational which is what you should do. Because result is a local object  which is destroyed when the function exists.

The same rule applies to a pointer to a local stack object, a reference to a heap-allocated object or a pointer or reference to a local static object. Think twice before returning a reference of these objects, most of time it will give you trouble.

“Effective C++” Third Edition by Scott Meyers.

Effective C++ item 20: Prefer pass-by-reference-to-const to pass-by-value.

Share Button

By default, C++ passes objects to and from functions by value. Unless you specify otherwise, function parameters are initialized with copies of the actual arguments, and function callers get back a copy of the value returned by the function. These copies are produced by the objects’ copy constructors. This can make pass-by-value an expensive operation. If you use pass-by-reference-to-const instead of pass-by-value, it will save the overhead of making unnecessary copies.

Passing parameters by reference also avoids the slicing problem. When a derived class object is passed(by value) as a base class object, the base class copy constructor is called, and the specialized features that make the object behave like a derived class object are “sliced” off. This is almost never what you want. For example

“Effective C++” Third Edition by Scott Meyers.