# Blepo Download

## Downloading the library

Latest Blepo version available for download:

- Version 0.6.8 (23 Aug 2011) (22 MB)

Previous versions

## Setting up your system

Once you have downloaded the code and unzipped it, you will need to do the following to set up your system.

1. The DLLs in the `external/bin` directory must be in your path. This can be accomplished on WindowsXP / Windows7 by selecting `Start Menu -> Control Panel -> System -> Advanced -> Environment Variables -> Path -> Edit`. In the edit box, append the full path to that directory, preceded by a semicolon with no extra spaces, for example, "`;c:/blepo/external/bin`" (without the quotes). (If you already have Visual Studio running, then close and restart it in order to load the new path.)

In addition, if you wish to capture images from a camera (e.g., USB webcam, Data Translation DT3120, or IEEE 1394), you will need to install the appropriate driver(s). For IEEE1394, you need to set it to use the CMU driver by following the instructions in `Capture/CaptureIEEE1394.h`. If you have any trouble, see the help in `blepo/external/doc/IEEE1394`. After installing the driver, you may test your camera using Blepo code or the CMU test application in `blepo/external/bin/1394CameraDemo.exe`

## Getting started with Visual Studio 2008/2010

Once you have performed these steps, open `demo/Demo.sln` in Visual Studio, compile the code, and run. This solution is a good starting point for learning how to build an executable using the library.

To create a new project to use Blepo,

1. Create a project with `File -> New -> Project`. Enter the name of the project, then
   - Either `Visual C++ -> Win32 Console Application` (click `Application settings` and check `MFC`), or
   - `Visual C++ -> MFC Application` (click `Application Type` and select `Dialog based`, which is the simplest choice)
2. Make the project use the Blepo library.
   - In the Solution Explorer, right click on `'Solution' -> Add -> Existing project`. Select `blepo/src/blepo.vcproj` (VS2008) or `blepo/src/blepo.vcxproj` (VS2010)
   - Make your project dependent upon (and link with) Blepo
     - VS2008: `Project -> Dependencies`, check the box next to `Blepo`
       (Note: In VS2008, project dependencies affect build order and linking.)
     - VS2010: `Project -> Properties -> Common Properties -> Frameworks and References -> Add New Reference`. Select Blepo.
       (Note: In VS2010, project dependencies only affect build order. Adding a reference sets the dependency and enforces linking also. See here.)
3. Change the project properties
   (Be sure that you are changing the properties of your project, not of Blepo: look in the title bar of the `Property Pages` dialog)
   (Also, be sure that your changes affect both Debug and Release modes: To do this, `Configuration -> All Configurations`):
   - `Project -> Properties -> Configuration Properties -> General -> Character set.` Set to `"Use Multi-Byte Character Set"` (This will remove the compilation errors related to character strings.)
   - `Project -> Properties -> Configuration properties -> Linker -> Input -> Ignore specific library.` Add `LIBCMT.lib` (While this appears not to be necessary for console-based applications, it is for MFC applications.)
4. Include the Blepo header file (`#include "blepo.h"`). For the compiler to find this file, you will need to do one of the following:
   - Add the `blepo/src` path to your project include path (`Project -> Properties -> C/C++ -> General -> Additional include directories`), or
   - add the path to your VC++ list of include directories (`Tools -``> Options -> Projects and solutions -> VC++ Directories -> Show directories for 'Include` files'), or
   - put the path into the `#include` statement.
5. Now build the project and run.
   - If you're using a Win32 Console application, then add your code in the `else` clause of `_tmain`.
     (Do not forget to call `EventLoop()`, as mentioned in the Blepo tutorial.)
   - If you're using an MFC Application, then
     1. doubleclick `Resource files -> *.rc -> Dialog -> IDD_*_DIALOG`, where `*` is the name of your project, to see the dialog
     2. Hover over the `Toolbox` on the right Click `Button`, then click inside the dialog to place a new button in the dialog
     3. Click then right-click the button, `Add event handler, 'Add and edit'`
     4. Now insert Blepo code in the function. When you run the program and click the button, this code will be called.
     5. Note that you will not be able to use `printf`, so instead pass a string to `AfxMessageBox`. Use `CString::Format` if you need to format a string. Example:

        > CString str;
        > int x;
        > str.Format("variable x = %d", x);
        > AfxMessageBox(str);

        Of course, for viewing variables the debugger is much more efficient.

Some common errors in VS2008/2010:

1. Errors with project:
   1. 'nasmw.exe' is not recognized as an internal or external command, operable program or batch file.
      - Did you remember to copy nasmw.exe to `c:/windows/system32`? Of course, it should also work if you add `c:/blepo/external/bin` to your path (Be sure to restart Visual Studio), but sometimes this does not work for some unknown reason.
   2. error LNK2005: _sprintf already defined in msvcrtd.lib(MSVCR90D.dll)
      - You forgot to tell Visual Studio to ignore LIBCMT.lib
   3. error C2664: 'void ATL::CStringT<BaseType,StringTraits>::Format(const wchar_t *,...)'
      - You forgot to set the project to `"Use Multi-Byte Character Set"`
   4. LINK : fatal error LNK1000: Internal error during IncrBuildImage
      - This also seems to be cause by forgetting to use multi-byte character set.
   5. mt.exe : general error c101008a: Failed to save the updated manifest to the file ".\Debug\Foo1.exe.embed.manifest". The parameter is incorrect.
      - The cause of this error is unknown; try `Rebuild All`.
   6. LINK : fatal error LNK1000: Internal error during IncrBuildImage
      - This is caused by a bug in the VS2008 linker. Either of these two solutions should work:
        1. disable incremental linking: `Project -> Properties -> Configuration properties -> Linker -> General -> Enable incremental linking -> No.`
        2. install VS2008 Service Pack 1
   7. nasm: error: more than one input file specified
      - Your Blepo path has a space in it (e.g., "My Documents"). This should be fixed now (as of version 0.6.8).
   8. afx.h(24) : fatal error C1189: #error : Building MFC application with /MD[d] (CRT dll version) requires MFC shared dll version. Please #define _AFXDLL or do not use /MD[d]
      - ?
   9. error LNK2001: unresolved external symbol "public: virtual __thiscall blepo::Figure::~Figure(void)"
      error LNK2001: unresolved external symbol "public: __thiscall blepo::Figure::Figure(char const *,int,int,bool,bool)"
      fatal error LNK1120: 2 unresolved externals
      - You are not linking with Blepo. Perhaps in VS2010 you made your project dependent on Blepo but forgot to add Blepo as a reference.
   10. !!!!!!!!!!!!!!! more than one input file specified
       - After version 0.6.8, this problem should not occur. The `Blepo.vcxproj` file should have quotes around the input filename, e.g., `"%(FullPath)"`. However, in one case, using VS2010 on Windows 7, the Blepo.vcxproj file the quotes had been removed somehow.
2. Errors with Blepo (should not occur unless you have made changes to the Blepo project):
   1. "Unable to load Haar classifier cascade" from `FaceDetector.cpp`
      - Solution: Right click Blepo, then `Properties -> Configuration Properties -> C/C++-> Command Line`, Add `/FC`. (This causes `__FILE__` to store the absolute path of the filename.)
   2. WINVER not defined. Defaulting to 0x0600 (Windows Vista)
      - Solution: Right click Blepo, then `Properties -> Configuration Properties -> C/C++-> Preprocessor ->
        Preprocessor definitions`. Add `_WIN32_WINNT=0x500;`
   3. warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead.
      - Solution: Right click Blepo, then `Properties -> Configuration Properties -> C/C++-> Preprocessor ->
        Preprocessor definitions`. Add `_CRT_SECURE_NO_WARNINGS`
   4. cv.lib(cv100.dll) : warning LNK4006: __NULL_IMPORT_DESCRIPTOR already defined in 1394camera.lib(1394camera.dll); second definition ignored
      cv.lib(cv100.dll) : warning LNK4221: no public symbols found; archive member will be inaccessible
      ...
      - Solution: Right click Blepo, then `Properties -> Configuration Properties -> Librarian ->
        Command line -> Additional options.` Add `/ignore:4006,4221`
   5. c:\program files\microsoft visual studio9.0\vc\atlmfc\include\afxv_w32.h(169) : fatal error C1083: Cannot open include file: 'windows.h': No such file or directory
      - This error means the Windows SDK has not been installed properly. This error occurred on an IBM Thinkpad with WinXP. The solution was to run the installer again, check/uncheck any arbitrary feature, then click update. This forces the installer to notice that the SDK is missing and therefore install it. (Note: The Windows SDK is in c:\program files\microsoft sdks\windows\v6.0a)
   6. c:\program files\microsoft sdks\windows\v6.0a\include\winnt.h(237) : error C2146: syntax error : missing ';' before identifier 'PVOID64'
      c:\program files\microsoft sdks\windows\v6.0a\include\winnt.h(237) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
      c:\program files\microsoft sdks\windows\v6.0a\include\winnt.h(7819) : error C2146: syntax error : missing ';' before identifier 'Buffer'
      c:\program files\microsoft sdks\windows\v6.0a\include\winnt.h(7819) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
      c:\program files\microsoft sdks\windows\v6.0a\include\winnt.h(7819) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
      - This problem occurred once on a 32-bit XP machine (same error was reported on a 64-bit machine). The cause of the error is not known, but the workaround was to manually insert the line
        #define POINTER_64 __ptr64
        in c:\program files\microsoft sdks\windows\v6.0a\include\winnt.h just before line 237:
        typedef void * POINTER_64 PVOID64;

## Getting started with VS6.0

Once you have performed the steps in "Setting up your system" above, you should be able to open `Demo/Demo.dsw` in Visual C++ 6.0, compile the code, and run. This workspace will be a good starting point for learning how to build an executable using the library. However, you may first have to add the gsl (GNU scientific library) path to your include directory:

- In Visual C++ 6.0, `Tools -> Options -> Directories -> Include files -> add blepo\external\WinGsl`, where `blepo` is the path to your Blepo directory.

In addition,

- The NASM assembler, which is used to compile the assembly code, must be in your executable path. The name of this file is `nasm.exe` and it resides in the `external/bin` directory. For some inexplicable reason the step above to modify your environment path does not solve this problem for VS6.0, so you have to copy the `nasm.exe` file to an existing directory on your path, such as `C:/Windows/System32`.

To create a new project to use Blepo,

1. Create a project with `File -> New -> Project`
   - Either `Win32 Console Application -> An application that supports MFC`, or
   - `MFC App Wizard` (Dialog based is the simplest, but the other application types should work as well)
2. Make the project use the Blepo library.
   - The simplest option is to add Blepo to the workspace and make the project dependent upon Blepo. More specifically,
     1. `Project -> Insert Project into Workspace`
     2. Select `blepo/src/blepo.dsp`
     3. Set your project to the active project again (`Project -> Set Active Project`)
     4. Make your project dependent upon Blepo (`Project -> Dependencies`, check the box next to `Blepo`)
   - Alternatively, you can compile Blepo separately and just add the .lib files to the project (the `blepo.lib` file as well as all the other `.lib` files in the Blepo project).
3. Include the Blepo header file (`#include "blepo.h"`). For the compiler to find this file, you will need to do one of the following:
   - Add the `blepo/src` path to your project include path (`Project -> Settings -> C/C++ -> Additional include directories`), or
   - Add the path to your VC++ list of include directories (`Tools -> Options -> Directories -> Include directories`), or
   - Put the path into the `#include` statement.
4. Since OpenCV (as of version 2.0) is no longer compatible with VS6.0, you will have to tell Blepo to use the old version of OpenCV. Either
   - manually uncomment the line #define BLEPO_I_AM_USING_VISUAL_CPP_60__ in blepo.h, or
   - insert the constant into the compiler directives using `Project -> Settings -> C/C++ -> Preprocessor definitions`
5. Now build the project and run.

Some common errors in VS6.0:

1. Errors with project:
   1. 'nasmw.exe' is not recognized as an internal or external command, operable program or batch file.
      - Did you remember to copy nasmw.exe to `c:/windows/system32`? Of course, it should also work if you add `c:/blepo/external/bin` to your path (Be sure to restart Visual Studio), but sometimes this does not work for some unknown reason.
      - Are you using multiple partitions? Visual Studio has been known to be unable to find nasmw even when it is in the `c:/windows/system32` directory. The cause appears to be that the project files were on a different partition from the C: drive. A workaround is to compile all the .asm files by hand, outside Visual Studio. A batch script to make this easy can be found in the Quick directory.
   2. c:\stb\cvs-local\research\code\vc6\alpha1\external\opencv-2\cxoperations.hpp(190) : error C2556: 'int __cdecl cv::saturate_cast(float)' : overloaded function differs only by return type from 'unsigned short __cdecl cv::saturate_cast(float)'
      - This only occurs if you are using Visual C++ 6.0. The problem is that you are using OpenCV 2.1, which is incompatible with VC6.0. Solution:
        1. Select Project.Settings. Select your project (not Blepo), and select 'All configurations'.
        2. Then go to the C/C++ tab and select Preprocessor. Under Preprocessor definitions, append to the end a comma followed by BLEPO_I_AM_USING_VISUAL_CPP_60__
   3. fatal error C1083: Cannot open precompiled header file:
      - Do Rebuild All. As long as you have stdafx.h in your program, it should compile. However, it is recommended that you turn off precompiled headers: Project.Settings.All Configurations.C/C++.Precompiled Headers.Not using precompiled headers.
   4. LINK : fatal error LNK1104: cannot open file
      - Usually this occurs because your program is still executing, and therefore Visual Studio cannot write to the .exe file. Stop execution and try again.
      - On Windows 7, this strange behavior has been observed: The new program is stored in C:\Program Files (x86)\Microsoft Visual Studio\, but the subdirectory with the project name does not exist. What VS thinks it exists is a mystery. Solution: Save your project somewhere else.

Enjoy!