Howto: Install OpenCV + Apache + Mysql + WSGI with ffmpeg and QT support on Ubuntu 14.04

Posted on Updated on

Install java version “1.7.0_65” and Python 2.7.6 (default, Mar 22 2014, 22:59:56), follow any method
##Update the current installed packages

 sudo apt-get update && sudo apt-get -y upgrade

## To install OpenCV 2.4.2 or 2.4.3 on the Ubuntu 12.04 operating system, first install a developer environment to build OpenCV.

 sudo apt-get install build-essential cmake pkg-config
 sudo apt-get install curl qt-sdk unzip yasm checkinstall build-dep

##Install Image I/O libraries

 sudo apt-get install libjpeg62-dev libtiff4-dev libjasper-dev

##Install the GTK dev library

 sudo apt-get install libgtk2.0-dev

##Install Video I/O libraries

 sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev

##Optional – install support for Firewire video cameras

 sudo apt-get install libdc1394-22-dev

##Install video streaming libraries

 sudo apt-get install libxine-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev

##Install the Python development environment and the Python Numerical library

 sudo apt-get install python-dev python-numpy python-pip
 sudo apt-get install python-opencv python-software-properties python-mysqldb python-xml

##Install the parallel code processing library (the Intel tbb library)

 sudo apt-get install libtbb-dev

##Install the Qt dev library

 sudo apt-get install libqt4-dev

##Install OpenCV Additional support Video/Audio and SSL libraries

 sudo apt-get install zlib1g-dev libssl-dev libreadline-dev libyaml-dev libxml2-dev libxslt1-dev libcurl4-openssl-dev libopencv-dev libmp3lame-dev libopencore-amrnb-dev libtheora-dev libvorbis-dev libxvidcore-dev x264 v4l-utils

##Install Apache Server and dependencies

 sudo apt-get install libapache2-mod-wsgi apache2 apache2.2-common apache2-mpm-prefork apache2-utils libexpat1 ssl-cert

##Install Mysql Database Server

 sudo apt-get install mysql-server libmysqlclient-dev

##Installing Python Modules

pip install numpy
pip install pyopencv
pip install Django==1.7.3
pip install django-admin-tools==0.5.2
pip install django-debug-toolbar==1.2.2
pip install django-extensions==1.4.9
pip install ipython==2.3.1
pip install six==1.9.0
pip install sqlparse==0.1.13
pip install wsgiref==0.1.2
pip install MySQL-python==1.2.5

##Download and Extraction OpenCV package

curl "${OPENCV_VER}.zip" -o opencv-${OPENCV_VER}.zip
unzip "opencv-${OPENCV_VER}.zip" && cd "opencv-${OPENCV_VER}"
mkdir build && cd build

##Building OpenCV package from source


##Installing OpenCV Package

make -g2 && make install

## Providing Dummy Firewire Video camera device

sudo ln /dev/null /dev/raw1394

##Including Additional Library path

echo "/usr/local/lib" >> /etc/
sudo ldconfig

##SettingUp environmetn variables

echo "PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig

## Execution environment variables for the currnet shell

source /etc/profile.d/


python -c "import cv2; print(cv2.__version__)"
pkg-config --modversion opencv

#Add Vhost for Apache

root@ip-10-184-30-74:~# pip --version #will show the dist-packages path
pip 1.5.4 from /usr/lib/python2.7/dist-packages (python 2.7)
vi /etc/apache2/sites-available/

<VirtualHost *:80>
 DocumentRoot /opt/web-home/raspberrypi/facecount
 WSGIDaemonProcess rasberry-pi_demo user=anand group=www-data maximum-requests=10000 python-path=/opt/web-home/raspberrypi/facecount:/usr/lib/python2.7/dist-packages
 WSGIScriptAlias / /opt/web-home/raspberrypi/facecount/
WSGIScriptReloading On
WSGIPassAuthorization On
<Directory /opt/web-home/raspberrypi/facecount/>
 Require all granted
 <Location />
 WSGIProcessGroup rasberry-pi_demo
Alias /static /opt/web-home/raspberrypi/facecount/static-assets/
<Directory /opt/web-home/raspberrypi/facecount/static-assets/>
 Require all granted
ErrorLog /opt/web-home/raspberrypi/apache_logs/error.log
 # Possible values include: debug, info, notice, warn, error, crit,
 # alert, emerg.
 LogLevel warn
 CustomLog /opt/web-home/raspberrypi/apache_logs/access.log combined

Now Restart Apache

service apache restart

Error: ctypes error: libdc1394 error: Failed to initialize libdc1394

Posted on Updated on

Error while importing Open CV in python with django framework , While compiling the application , it thrown the error like below. libdc1394 is a library for controlling camera hardware. It is an optional installation for the OpenCV package which unable to load the hardware for this time

Error :

libdc1394 error: Failed to initialize libdc1394

We don’t need to use camera hardware, is there perhaps a way of compiling without that part of OpenCV or If the server is in VBox/Virtualization system simply enable USB controller.
If it is remote server and we don’t need camera hardware you can create the null link for the IO dev.

 sudo ln /dev/null /dev/raw1394

Error: Fatal Python error: PyEval_AcquireThread: NULL new thread state

Posted on

This might be cause of various issue.

1, mod_wsgi is compiled for a different Python version and/or a different Python installation than the Python virtual environment

2, Python installation it is trying to use at runtime

3, If mod_wsgi and mod_python are both enabled.

In my case, I figured out the third cause. for fixing disabled mod_python because I was running website under wsgi wrapper.

sudo a2dismod python
sudo service apache2 restart