Using cmake-gui to Create MinGW lib for OpenCV 2.4.13

Recently, I have tried to learn how to use OpenCV. Of course, the first thing is to install OpenCV. The version I tried to install is 2.4.13. The development tools I used is MinGW g++. After download and install all the tools (including cmake), I soon found out that there is no library for MinGW g++ in the distribution. This means I need to build my own if I want to use g++. The search is on…

There is not much information I can find for my environment which is Windows 10 and using g++ as my main c++ compiler. After putting the pieces together, I eventually hit the right path, the following is my procedure for building the MinGW lib for OpenCV 2.4.13:

  1. run cmake-gui as follows:
    cmake-gui -G "MinGW Makefiles"

    Setup the location for source (in my case is D:/WinApps/opencv/sources) and the binaries (D:/WinApps/opencv/build/x86/mingw). Add the following two entries as well:

    CMAKE_CXX_COMPILER <em>path_to_g++</em>
    CMAKE_C_COMPILER <em>path_to_gcc</em>
  2. Click Configure then with the default selection of components click Generate
  3. In cmd, change directory to D:/WinApps/opencv/build/x86/mingw and execute the command
    make all

    I encountered two errors during the make process:

    • A compile error for the file window_w32.cpp where the symbols ‘BTNS_AUTOSIZE‘ and ‘BTNS_BUTTON‘ were not declared. I fixed it by change them to 16 and 0 (where I found in one of the header file of g++).
    • Another error from the files in ‘nonfree’ module, for which I just deselect the ‘BUILD_opencv_nonfree’ from cmake and reclick Generate again, then make all again. This time, it went all the way to finish without serious error.
  4. Done!

I test drive the system by creating a c++ program loadimg.cpp which I copied from here.

g++ -I"D:\WinApps\opencv\build\include" -L"D:\WinApps\opencv\build\x86\mingw\lib" loadimg.cpp -lopencv_core2413 -lopencv_highgui2413 -o loadimg

The program compiled and run!


Error 1935 while try to upgrade blue tooth drive for lenovo X201

I recently tried to test my blue tooth stereo headset with my lenovo X201 and end up need to update the blue tooth driver in the computer. However, during the update process, the computer encountered an error 1935 and the update was not successful and rolled back. I tried a few times with the same result. I even tried to download and install the new driver manually, still without any luck. Reading the forums from web also gave me not much help. I finally do the following and magically it worked!

  1. In “Device Manager” (right-click Computer->property), right click the ThinkPad Bluetooth device and click “Uninstall”. The entire BT device will gone.
  2. In “Device Manager”, right click the top item (my notebook) and click “Scan for hardware changes”, wait a short while and it should find the BT device and start installing the most updated drivers!

Now, the device drivers are the most updated one!

Finding bit rate

I recently have a need to down-size of mp4 file in order to be able to upload it to a web page. The upload limit of the web page is 32M where the size of my mp4 file is about 200+M. I found out that I can use ffmpeg to re-compress the file with a smaller bit rate in order to down-size the file. The only problem is what bit rate to use. The command I used is as follows:

ffmpeg -i original.mp4 -b:v 126k -b:a 64k output.mp4

As you can see, I can control both the video bit rate and audio bit rate separately. After a few tests I eventually find our how to do the math. Given the length of my video is 22:49. The total bit rate is calculated as follows:

Total bit rate = (target file size / duration) * 8
               = (32 * 1024 * 1024) / (22 * 60 + 49) * 8
               = 196081
               = 191k

In other words, my maximum bit rate should be 191k, this is the combined total bit rate for both video and audio. Thus, I can select different combination of video and audio bit rate as long as they sum is within 191k. In the above example, I use 126k for video and 64k of audio, the result file is 33,414,347 bytes (of 31.9M) long. Good enough for me.

Footer/Icon stays at the bottom of screen

I were looking for ways to fix some icons to be shown at the bottom of the screen and came across the following code. I haven’t test the code yet but it should fit my need.

html {
  position: relative;
  min-height: 100%;
body {
  margin: 0 0 100px; /* bottom = footer height */
footer {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 100px;
  width: 100%;

animateTransform for a group of objects in SVG using InkScape

I recently try to do a presentation in SVG and wanted to do some simple animation on some of the components in the presentation. First of all, I am lucky to come across the Sozi extension for Inkscape. The extension makes Inkscape able to produce presentation very similar to Prezi.

With the framework setup, now it is time to do some element animation. Immediately, I encountered a problem, I used text editor (VIM) to edit the SVG file in order to insert the animation for the elements. The problem I encountered was that when I try to animate (e.g., rotating and scaling) a grouped objects, I cannot find the center. Even I calculate the center correctly, the rotation or scaling behave strangely.

After a few try and hacking, I eventually find a way create grouped object which can be moved or scaled without effecting the animation within the group.

Step 1. Create the component so that its center is at (0, 0) (upper left-hand coiner of Inkscape paper).

Step 2. Add the necessary animation code and put the code inside the group.

Step 3. Add an outer group to the group. In this way, When the group is moved, scaled or rotated, the transformation matrix will be add on the outer most group.

<g id="outer-group">
  <g id="inner-group">
    <path ... />
    <path ... />
      attributeName="transform" type="rotate"
      values="0; 360" dur="2s"
      repeatCount="indefinite" />

The idea is that the inner group cannot have transformation matrix in it, otherwise,

Sleeping and Wake up of Perl script

I am working on a system that requires a Perl script to sleep when it is idle and wake up when new “job” arrive. After some search, the following is what I end up with:

$SIG{ALRM} = sub { print "Alarm!\n"; };
while (1) { # process loop
  if ($therearejobs) {
    # process the job
else {
  print "No job, I am going to sleep now!\n";
  $st = sleep;
  print "Ok, after $st second, I am back to work.\n";

To communicate with the about script, one can send alarm signal to the script by issue a kill command as follows:

kill -14 pid

Where -14 is the signal number of ALRM (alarm).

Joining MP4 files with mp4box

Recently I need to join some mp4 files (parts of a movie) back into one single file.  The best result that I got was from a program called MP4Box.  Because what I need is just to join these files together into a single file without changing format, MP4Box did a very good job.  The voice and the picture are perfectly in sync in the final result.  The command I used is:

mp4box -cat 0.mp4 -cat 1.mp4 -cat 2.mp4 ... -new result.mp4

However, there is one small problem.  The duration information for the final result is not correct.  It is much longer than the actual duration of the movie.  This may not be a problem if you are going to watch the movie from begin to end.  It does become a problem when you want to seek to the middle of the movie. I tried many different options in mp4box without any luck. I finally decided to look into the raw data of the result mp4 file. After a few trial and error, I finally found out where the duration information is stored. It appeared in two places (at file offset 0x34 and 0xC1) in the header of the mp4 file. The number was stored as a 4-byte integer with the higher significant digit stored in lower offset. I then used a Hex editor to modify the number to correct duration. When the result file was opened in a player, the duration was correct and the problem was fixed.

For example, let’s say that the correct duration is 1:24:35.013 (scale is 1000), then the number I need to put in 0x34 and 0xC1 is

= 5075013 = 0x004D7045

Thus, the number 0x004D7045 will be placed into 0x34 and 0xC1 with higher significant digit first as follows:

Address: 34 35 36 37
Content: 00 4D 70 45

I am thinking of writing a simple program to automate the process whether than edit the file by hand.