Posted on 11-08-2016
Filed Under (Technology) by bigbang

The library versions using in this article: OpenCV2.4.13, FFMpeg 2.8.7, CMake 3.5.

First of all, you need to install FFMpeg on Mac OSX first. The step is very easy just like doing it on other Unix/Linux platform.

Then download OpenCV 2.4.13 and unzip it to a folder. Enter this folder from terminal and here are basic steps for OpenCV 2.4.13 compilation under Mac:

mkdir build
cd build
cmake -G "Unix Makefiles" ..
make -j8
sudo make install

According to OpenCV version and FFMpeg dependency, you might meet some compilation errors.

Error 1: not generating corresponding makefile

Here is an example error message:

In file included from /Users/collins/Documents/temp/opencv-2.4.13/3rdparty/zlib/zlib.h:34:

/Users/collins/Documents/temp/opencv-2.4.13/release/3rdparty/zlib/zconf.h:426:14: fatal error:

      'sys/types.h' file not found

#    include <sys/types.h>      /* for off_t */

	     ^
1 error generated.

Try to generate correct makefile on Mac, you should use following parameters in cmake command:

cmake -G "Unix Makefiles" ..

So your final OpenCV project generating cmake parameters should be something like this:

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -G "Unix Makefiles" ..

Error 2: link CoreMedia, VideoToolBox frameworks or something else on Mac

An example error message is as following:

[ 33%] Building CXX object modules/highgui/CMakeFiles/opencv_highgui.dir/src/bitstrm.cpp.o

[ 33%] Linking CXX shared library ../../lib/libopencv_highgui.dylib

Undefined symbols for architecture x86_64:

  "_CMBlockBufferCreateWithMemoryBlock", referenced from:

      _videotoolbox_common_end_frame in libavcodec.a(videotoolbox.o)

  "_CMSampleBufferCreate", referenced from:

      _videotoolbox_common_end_frame in libavcodec.a(videotoolbox.o)

  "_CMVideoFormatDescriptionCreate", referenced from:

      _av_videotoolbox_default_init2 in libavcodec.a(videotoolbox.o)

  "_SSLClose", referenced from:

      _tls_open in libavformat.a(tls_securetransport.o)

      _tls_close in libavformat.a(tls_securetransport.o)
  "_SSLCopyPeerTrust", referenced from:

The reason of above error message is that some FFMpeg version under Mac is depended on VideoToolBox & CoreMedia Frameworks.

The solution is to modify and add following code into opencv-x.x.x/modules/highgui/CMakeLists.txt file:

find_library(CORE_MEDIA CoreMedia)
if (NOT CORE_MEDIA)
    message(FATAL_ERROR "CoreMedia not found")
endif()

find_library(VIDEO_TOOL_BOX VideoToolBox)
if (NOT VIDEO_TOOL_BOX)
    message(FATAL_ERROR "VideoToolBox not found")
endif()

find_library(SECURITY Security)
if (NOT SECURITY)
    message(FATAL_ERROR "Security not found")
endif()

target_link_libraries(${the_module} ${CORE_MEDIA} ${VIDEO_TOOL_BOX} ${SECURITY})

So at the compilation time, it will link VideoToolBox, CoreMedia, Security frameworks under System/Library/Frameworks folder.

Another solution is not to compile highgui library, you can do this such kind of thing like this:

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_opencv_highgui=OFF -G "Unix Makefiles" ..

Adding CoreMedia & VideoToolBox libraries is not enough, You might still get following errors:

ld: warning: directory not found for option '-L/usr/local/lib/Debug'
ld: warning: directory not found for option '-L/usr/local/Cellar/x264/r2601/lib/Debug'
ld: warning: directory not found for option '-L/usr/local/Cellar/libvpx/1.5.0/lib/Debug'
ld: warning: directory not found for option '-L/usr/local/Cellar/opus/1.1.1/lib/Debug'
ld: warning: directory not found for option '-L/usr/local/Cellar/freetype/2.6_1/lib/Debug'
ld: warning: directory not found for option '-L/usr/local/Cellar/fdk-aac/0.1.4/lib/Debug'
ld: warning: directory not found for option '-L/usr/local/Cellar/libass/0.13.1/lib/Debug'
Undefined symbols for architecture x86_64:
  "_SSLClose", referenced from:
      _tls_open in libavformat.a(tls_securetransport.o)
      _tls_close in libavformat.a(tls_securetransport.o)
  "_SSLCopyPeerTrust", referenced from:
      _tls_open in libavformat.a(tls_securetransport.o)
  "_SSLCreateContext", referenced from:
      _tls_open in libavformat.a(tls_securetransport.o)
  "_SSLHandshake", referenced from:
      _tls_open in libavformat.a(tls_securetransport.o)
  "_SSLRead", referenced from:
      _tls_read in libavformat.a(tls_securetransport.o)
  "_SSLSetCertificate", referenced from:

That’s the reason why I need to add security.framework to CMakeLists.txt file.

According to different OpenCV & FFMpeg version, you might try to link other frameworks this way by your self to make sure you can install OpenCV successfully.

(0) Comments    (24) Views    Read More   
Posted on 11-08-2016
Filed Under (Technology) by bigbang

While writing program on Mac, sometimes we need to link framework and libraries under OSX folder System/Library/Frameworks. There are so many frameworks like CoreMedia & VideoToolBox, which you will use in FFMpeg or something else someday.

In this situation, we have to use find_library as it includes some special handling for frameworks on OSX.

Also, don’t use link_directories, CMake use full paths to libraries and it’s not needed.

Here’s some simple example with CoreMedia:

find_library(CORE_MEDIA CoreMedia)
if (NOT CORE_MEDIA)
    message(FATAL_ERROR "CoreMedia not found")
endif()

add_executable(program ${program_SOURCES})
target_link_libraries(program ${CORE_MEDIA})
(0) Comments    (21) Views    Read More   
I have had both VS2008 and VS2015 installed on my machine for a while, and VS2015 was installed after VS2008.
Now I notice that whenever I click on a VS2008 solution to open it, it won’t ask me anything but to use VS2015 to open it. I have no idea what this is but the same happens with VS2015. This is only whenever I double click on a solution file to open it. If I right click on the .sln file and give it the version to open with (like VS2008 for example),  it is still opened with VS2015 without asking this question. Then only thing I can open VS2008 .sln file with VS2008, is to open VS2008 manually and drag the VS2008 .sln file into it.
If you are in this situation, two things you need to check the registry entry for the file extension. One is for .vcproj file extension, and the other is for .sln file extension.
Make sure following two registry entry is like this:
1) check .vcproj file extension
HKEY_CLASSES_ROOT\
  .vcproj\
  (default)=”VisualStudio.vcproj.9.0″
  OpenWithList\
  devenv.exe
Here is the picture:
vcproj
2) check .sln file extension
HKEY_CLASSES_ROOT\
   .sln\
   OpenWithProgids\
   VisualStudio.sln.9.0
Here is the picture:
sln
(0) Comments    (48) Views    Read More   
Posted on 06-01-2016
Filed Under (Technology) by bigbang

We can build OpenCV under Visual Studio by using CMake under Windows7. It is very easy to do this job using edition OpenCV 2.4.X with Visual Studio 2008.

But when I try to build OpenCV 3.1.0 under Visual Studio 2008, there are some errors!

The first error is :

Error   131     fatal error C1083: Cannot open include file: 'stdint.h': No such file or directory      g:\setup_files\opencv\windows\opencv-3.1.0\sources\modules\imgcodecs\src\jpeg_exif.hpp  51

To fix this error, just google the stdint.h file and put it under the build path of OpenCV.

The second error is:

Error   1       error C2039: 'data' : is not a member of 'std::vector<_Ty>'     g:\setup_files\OpenCV\Windows\OpenCV-3.1.0\sources\modules\videoio\src\cap_mjpeg_decoder.cpp    793

This error is generated by \modules\videoio\src∩_mjpeg_decoder.cpp line 793, the origin code is:

m_file_stream.read(result.data(), chunk.m_size);

To fix this error, just change the code into following:

m_file_stream.read(&result[0], chunk.m_size);

OpenCV 3.1.0 uses C++11 code but Visual Studio 2008 doesn’t support this feature.

By done these, re-compile your solution then you will get the OpenCV 3.1.0 libraries from Visual Studio 2008.

(0) Comments    (267) Views    Read More   
Posted on 06-05-2015
Filed Under (Technology) by bigbang

In Android jni folder, we will always add some C/C++ header file folders. Basically, there are two ways to do this job.

Option 1:

Add one of the following lines to your Android.mk inside a module of your choice:

LOCAL_C_INCLUDES := /path/to/your/includes # ignore previous includes
                                           # OR
LOCAL_C_INCLUDES += /path/to/your/includes # preserve previous includes

If necessary you could create an environment variable pointing at ‘/path/to/your/includes’ and include it like this:

LOCAL_C_INCLUDES := $(MYLIB_INCLUDES_PATH) # ignore previous includes
                                           # OR
LOCAL_C_INCLUDES += $(MYLIB_INCLUDES_PATH) # preserve previous includes

If you write following code but there is no effect:

LOCAL_C_INCLUDES := ../example/include
LOCAL_C_INCLUDES += ../example/include2

please add $(LOCAL_PATH) to them, which will be:

LOCAL_C_INCLUDES := $(LOCAL_PATH)../example/include
LOCAL_C_INCLUDES += $(LOCAL_PATH)../example/include2

Option 2:

  1. Copy the complete folder with all header-files in it (mylib) into the ‘jni’ folder of your project.
  2. Add the following line to your Android.mk inside a module of your choice:
LOCAL_C_INCLUDES := $(LOCAL_PATH)/mylib

or

LOCAL_C_INCLUDES += $(LOCAL_PATH)/mylib

Depending on whether there are previous includes or not. If the include is the first one, use the first examle which use := as keyword. If has previous includes, use latter which is += as keyword.

(0) Comments    (305) Views    Read More   

When we put the jni folder under projects and compile it using command line tool ndk-build, we will get libs & obj folders like this:

|--jni
|--libs
|----armeabi-v7a
|--obj

But under Android Studio develop environment, android studio can’t find the so files under libs folder.

We can do it by using following folder structure under Android Studio:

|---app
|------jni
|------libs
|------obj
|------src
|---------androidTest
|---------main

We can use this folder structure to compile JNI. When we compile the JNI file, ndk-build will generate libs & obj folders.

Finally, we add following to android part in build.gradle to let Android Studio finds the so files generated by jni folder:

sourceSets.main {
    jniLibs.srcDirs = ['libs']
}

Finally, the build.gradle should look like this:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "org.waterlin.mediatester"
        minSdkVersion 15
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    sourceSets.main {
        jniLibs.srcDirs = ['libs']
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.1.1'
}

By this way, Android Studio can let you use local jni code to generate so library and integrated into your Android project.

(0) Comments    (254) Views    Read More   
Posted on 08-04-2014
Filed Under (Technology) by bigbang

If you are under Windows, you may need to config golang develop environment manually.

Get Emacs go-mode from misc/emacs/, there are two files: go-mode-load.el and go-mode.el.

Put them into your Emacs load-path, then add following code to .emacs:

;; golang mode
(add-to-list 'load-path "~/emacs/site-lisp/go-mode")
(require 'go-mode-load)
(require 'go-mode)

Then you can open go source file with syntax highlight now.

If you are under Ubuntu/Debian, the easiest way to install golang-mode is by:

sudo apt-get install golang-mode

After this installation, retart your Emacs then you can edit go source file with syntax highlight.

Posted on 08-04-2014
Filed Under (Technology) by bigbang

If you have a keyboard with two Alt keys (e.g. a US Keyboard), you will find that PuTTY doesn’t recognize the one on the right side. It is a fatal problem if you are using Emacs in putty on Windows to editing files on a remote computer.

After doing some reasearching on it, I think there are two soluctions for this problem.

  1. Easily fixed the problem with a simple registry edit

    The putty topic Right Alt Key Broken shows an easy solution for it by add following registry code:

    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
    "Scancode Map"=hex:00,00,00,00,00,00,00,00,02,00,00,00,38,00,38,e0,00,00,00,00
    
  2. Use AutoHotkey to cheat Putty right Alt as left Alt

    Right click on AutoHotkey icon and click ‘Window Spy’ in the menu, you can get Putty class name in AutoHotkey. Then add following setting in current script in AutoHotkey:

    #IfWinActive ahk_class PuTTY
    RAlt::LAlt
    #IfWinActive
    

    Reload the script and you can use right Alt to invoke Emacs M-x key bindings in Putty.

I prefer the second way to fix the Right Alt Key Broken problem in Putty under Windows.

Posted on 01-04-2014
Filed Under (Technology) by bigbang

Django-Chartit looks like a good tool for drawing some data charts under Python Django framework.

But it is a little hard to get it ready for work. Here I remind of two key steps while using Chartit:

  1. add chartit to your INSTALLED_APPS.
  2. install simplejason if you get ‘use_decimal’ error.

    The error message is something like:

    TypeError at /charts/
    __init__() got an unexpected keyword argument 'use_decimal'
    

I don’t think Chartit is the best choice current now, and I prefer Chart.js instead if you just want to draw some basic charts.

(0) Comments    (848) Views    Read More   
Posted on 01-04-2014
Filed Under (Technology) by bigbang

While I make my cpp source files linking ZeroMQ under Ubuntu, I got following error:

/usr/bin/ld: test_server.o: undefined reference to symbol 'zmq_strerror'
/usr/bin/ld: note: 'zmq_strerror' is defined in DSO /usr/local/lib/libzmq.so.3 so try adding it to the linker command line
/usr/local/lib/libzmq.so.3: could not read symbols: Invalid operation

The ZeroMQ library has already installed. By checking the man:

Libraries have been installed in:
   /usr/local/lib

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,-rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.

I get rid of the error by following steps:

  1. install libtool;
  2. add the library path to LD_LIBRARY_PATH;
  3. use root to make.

I think the last one, using root to make, is the key point. Why?