Compiling OpenCV 2.4 on RHEL/CentOS 5

OpenCV (Open Source Computer Vision) is a library of programming functions for real time computer vision.

At present, prebuilt binaries/packages are not available for OpenCV on Centos/RHEL 5. Here are the notes from my attempts to get it compiled.

Please make sure you have latest cmake installed from

To Install OpenCV python modules, you will need python-numpy modules to be installed.

easy_install numpy

Then compile OpenCV using(assuming, your latest python is installed in /usr/local/python-2.7):

cmake -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=/usr/local -DBUILD_EXAMPLES=ON -DBUILD_NEW_PYTHON_SUPPORT=ON -DINSTALL_PYTHON_EXAMPLES=ON -DPYTHON_EXECUTABLE=/usr/local/python-2.7/bin/python -DPYTHON_INCLUDE_DIR=/usr/local/python-2.7/include -DPYTHON_LIBRARY=/usr/local/python-2.7/lib/ -DPYTHON_NUMPY_INCLUDE_DIR=/usr/local/python-2.7/lib/python2.7/site-packages/numpy/core/include/ -DPYTHON_PACKAGES_PATH=/usr/local/python-2.7/lib/python2.7/site-packages/

Using BUILD_NEW_PYTHON_SUPPORT fixes the issue seen below:

CMake Warning:
   Manually-specified variables were not used by the project:


If you get the following Error:

CMake Error at apps/haartraining/CMakeLists.txt:39 (set_target_properties):
set_target_properties called with incorrect number of arguments.

CMake Error at apps/traincascade/CMakeLists.txt:29 (set_target_properties):
set_target_properties called with incorrect number of arguments.

it can be fixed in both files by enclosing ${EXECUTABLE_OUTPUT_PATH} with double quotes (“${EXECUTABLE_OUTPUT_PATH}”)

Then, run make


Now, make will throw an error when it tries to compile freak.cpp. To get this compiled, compile it manually (without using any optimization )

cd /home/ram/OpenCV-2.4.3/modules/features2d ; 
/usr/bin/c++ -Dopencv_features2d_EXPORTS -DHAVE_CVCONFIG_H \ 
-DCVAPI_EXPORTS -W -Wall -Wformat -Wundef -Winit-self \
-Wpointer-arith -Wshadow -Wsign-promo -fdiagnostics-show-option \
-Wno-long-long -pthread -fomit-frame-pointer -msse -msse2 -msse3 \
-ffunction-sections -DNDEBUG -DNDEBUG -fPIC \
-I/home/ram/OpenCV-2.4.3/modules/features2d/perf -I/home/ram/OpenCV-2.4.3/modules/features2d/include \
-I/home/ram/OpenCV-2.4.3/modules/highgui/include -I/home/ram/OpenCV-2.4.3/modules/flann/include \
-I/home/ram/OpenCV-2.4.3/modules/imgproc/include -I/home/ram/OpenCV-2.4.3/modules/core/include \
-I/home/ram/OpenCV-2.4.3/modules/ts/include -I/home/ram/OpenCV-2.4.3/modules/features2d \
-I/home/ram/OpenCV-2.4.3/modules/features2d/src -I/home/ram/OpenCV-2.4.3/modules/features2d/test \
-I/home/ram/OpenCV-2.4.3 -o CMakeFiles/opencv_features2d.dir/src/freak.cpp.o \
-c /home/ram/OpenCV-2.4.3/modules/features2d/src/freak.cpp

This should build freak manually, so make will not bother recompiling it anymore. Continue build:

cd /home/ram/OpenCV-2.4.3/
make install

This completes OpenCV installation. To build the samples:

export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
cd /home/ram/OpenCV-2.4.3/samples/c
chmod +x

Can’t configure Google Analytics Reports – “Invalid Token” message

When behind a proxy, Google Analytics Reports module in apache throws a “invalid token” message.


The drupal_http_request does not handle corporate proxies well. Here is the custom function that I wrote to fix this exact issue:


function curl_http_request($url, $headers, $method, $data)
$result = new stdClass();
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL,$url);
curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_COOKIEJAR, $gacookie);
curl_setopt ($ch, CURLOPT_COOKIEFILE, $gacookie);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt ($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt ($ch, CURLOPT_PROXY, "");
curl_setopt ($ch, CURLOPT_PROXYPORT, 80);
curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, $method);
$fetched = curl_exec ($ch);
$result->code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$result->data = $fetched;
$result->error = curl_errno($ch);

Replace drupal_http_request in, with this function curl_http_request. It works for me. YMMV

Note: This can be used in place of drupal_http_request


Compiling Varnish/Varnishtop: Issue with do_curses

When compiling varnishtop (and other tools) on RHEL/CentOS 5, I came across the following issue:

varnishtop.o: In function `do_curses':
/tmp/varnish-2.1.4/bin/varnishtop/varnishtop.c:223: undefined reference to `initscr'
/tmp/varnish-2.1.4/bin/varnishtop/varnishtop.c:224: undefined reference to `raw'
/tmp/varnish-2.1.4/bin/varnishtop/varnishtop.c:225: undefined reference to `noecho'
/tmp/varnish-2.1.4/bin/varnishtop/varnishtop.c:226: undefined reference to `nonl'
/tmp/varnish-2.1.4/bin/varnishtop/varnishtop.c:227: undefined reference to `stdscr'
collect2: ld returned 1 exit status
make: *** [varnishtop] Error 1

The issue seems to be with the ncurses library that comes with the standard distribution. So, I installed the ncurses-5.7 libs from source, using:
./configure --with-shared --with-debug --enable-overwrite --with-termlib

and then recompiling/building varnish/varnishtop.

CPU/Processor information in Linux

Finding Physical Processors:
$ grep 'physical id' /proc/cpuinfo | sort | uniq | wc -l

Finding Virtual Processors
$ grep ^processor /proc/cpuinfo | wc -l

Finding CPU cores
$ grep 'cpu cores' /proc/cpuinfo

“2″ indicates the two physical processors are dual-core, resulting in 4 virtual processors.
If “1″ was returned, the two physical processors are single-core.

If the processors are single-core, and the number of virtual processors is greater than the number of physical processors, the CPUs are using hyper-threading.

Finding CPU Arch
$ grep flags /proc/cpuinfo | uniq | egrep -o -w "rm|tm|lm"

Under “Flags” section in /proc/cpuinfo, you will find any of the flags “tm” or
“rm” or “lm”

  • rm (Real Mode) means it is a 16 bit processor
  • tm (Transparent Mode) means it is a 32 bit processor
  • lm (Long Mode) means it is a 64 bit processor

Piwik Mediawiki Extension

Piwik( is open source self-hostable web analytics tool (like omniture orĀ  google analytics). To integrate piwik with mediawiki, I customized the existing Google Analytics mediawiki plugin ( to work with piwik. To include the extension in your wiki,
unzip the file, and deploy the piwik.php extension file into WIKI_INSTALL_DIR/extensions/. Then include the file in your LocalSettings.php, using:


Download piwik extension