Monday, February 3, 2014

Tutorial: Build imageclipper on Mac OS X 10.9

In object detection using cascade classification you will get better results the more images you have to train your classifiers. But for the training it is necessary to prepare images that contain examples of the object you want to detect. More clearly, you have to crop loads of images that only the desired object is visible without much background. But cropping hundreds or thousands of images may be a lengthy process. For exactly this purpose Naotoshi Seo created a small, fast, multi platform software, named imageclipper.


Although the application still works, there are some problems we have to face:

--> He only provides a executable file for Windows. Unix users have to compile it themselves.

I searched a lot how to do this and found someone who uploaded a compiled version for Mac here - just to face another, for me already well known problem.

--> The software is outdated and it was compiled with an older version of OpenCV (here: version 2.1). Since then the links to the libraries and headers have changed. When trying to start imageclipper with a new Version of OpenCV you will get the following error:

dyld: Library not loaded: libopencv_core.2.1.dylib

So you will have to compile it for yourself if you want to use the speed advantage of imageclipper.

Preparation

Download the imageclipper source code

Get it from here: https://github.com/noplay/imageclipper
It is a fork of the original imageclipper with some Mac specific updates. Unpack it and navigate to the folder /src inside. There is all what you need.

Install boost

To compile the imageclipper source code you need the boost C++ source libraries. You can install it easily using MacPorts - just like you installed cmake. Just open the Terminal and enter this command:
 sudo port install boost   
After entering your password boost will be downloaded and installed.

Configure Xcode

1. Create a new project - a C++ Command Line Tool - and name it "imageclipper".

2. Copy all the files of the /src folder of the imageclipper fork in the folder of your project, that you just created.

3. Copy the content of the "imageclipper.cpp" in your "main.cpp".

4. Now we have to include the libraries:

4.1 Include the OpenCV libraries like I explained here in point 5 of "Configure Xcode": Tutorial: Configure Xcode for OpenCV programming

4.2 In the same manner add the boost libraries. They are located in /opt/local/lib. Just add all the .dylib-files named something with "libboost".

5. Configure search paths:

5.1 Add following Header Search Paths:
/usr/local/include
/usr/local/include/opencv
/usr/local/lib
/opt/local/include
/opt/local/include/boost

and the path to your project where you copied the imageclipper source files inside, for example:
/users/christian/documents/programming/imageclipper

It should look like this:

5.2 Add following Library Search Paths:
/usr/local/lib
/opt/local/lib

6. Compile imageclipper.

That's it. You can now compile imageclipper. You find the executable file in
/Users/USER-NAME/Library/Developer/Xcode/DerivedData/PROJECT-NAME/Build/Products

I have already done this. Has long as you followed my instructions of installing OpenCV and your libraries are located in the same path, you can just download my executable file and use it.

Download imageclipper executable for Mac

In another post, I explain how to use imageclipper.

Program versions:
OS: Mac OS X 10.9.1
Xcode: 5.0.2
OpenCV: 2.4.8.0
MacPorts: 2.2.1
boost: 1.55.0

2 comments:

  1. Hello!

    I forked the project and created a new CMake project instead. This allows you to generate Makefiles/XCode project/Visual studio project, all from one project file. (See http://www.cmake.org for details)

    I have tested it on Windows, Linux and OSX. A lot easier than having to create your own project file + adding system specific paths that might not be in the same place on another persons system.

    Here you can download my fork:
    https://github.com/JoakimSoderberg/imageclipper

    ReplyDelete
    Replies
    1. Nice! This should be helpful for some people :)

      Delete