“symbol(s) not found for architecture x86_64 error” when compiling OpenCV example program in Mac OS X 10.12

I just completed the installation of OpenCV 3 in my Mac (running OS X 10.12) after a long search of various installation methods.  However, when I tried to compile a sample C++ program, the following error was resulted:

Undefined symbols for architecture x86_64:
  "cv::imread(cv::String const&, int)", referenced from:
      _main in DisplayImage-6f69a1.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [DisplayImage] Error 1

So, once again, the search is on. After searching for the entire morning for solutions, I came across many “solution posts” that did not work!

Finally, I reached a post that mentioned “imread has been moved in the opencv_imgcodecs library.” and should “Try to add -lopencv_imgcodecs to your linker flags.” This solved my problem.

This case made me wonder how many people who posted “incorrect solution” had actually tried to replicate the error and actually solved the problem? Or did they just “think” what may be the problem and provide “guesses” about the possible solutions?

I am not saying that try ones best to provide information to the other is a bad thing. But providing too many “unproven” information in the web not only not able to help, it also makes the searching for true solution more difficult!

Advertisements

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!

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 ... />
    <animateTransform
      attributeType="xml"
      attributeName="transform" type="rotate"
      values="0; 360" dur="2s"
      repeatCount="indefinite" />
  </g>
</g>

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

(((1*60)+24)*60+35)*1000+13
= 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.

Softwares I Used

In the past, I tried many different software (mostly freeware) in search for some that suit my purposes.  Sometimes, I found one, downloaded and used.   But after I switch computers, I forgot what was the software and where to find it.  So, here I try to list out most of the hand-picked useful software that I am using now. Continue reading “Softwares I Used”