Monday, September 17, 2018

How To Install OpenCV In Ubuntu Linux

How To Install OpenCV In Ubuntu Linux



Today, I'm going to show you how to install OpenCV in Ubuntu Linux (I'm using Ubuntu 18.04 for this tutorial)

First Download OpenCV and opencv_contrib

git clone https://github.com/opencv/opencv.git --depth=1

and

git clone https://github.com/opencv/opencv_contrib.git --depth=1

After completing the download extract the zip files and navigate to opencv directory

Then, create the directory named build inside the opencv directory and navigate to that newly created one..

cd opencv && mkdir build && cd build

Now run the cmake command from build directory...

cmake ../

It will take some time.. Please be patient... :)
At this time the output will look like this...

root@10a4bdccb67a:~/opencv/build# cmake ../ -- The CXX compiler identification is GNU 7.3.0 -- Check for working CXX compiler: /usr/bin/c++ -- Check for working CXX compiler: /usr/bin/c++ -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Detecting CXX compile features -- Detecting CXX compile features - done -- Could NOT find PythonInterp (missing: PYTHON_EXECUTABLE) (Required is at least version "2.7") -- Could NOT find PythonInterp (missing: PYTHON_EXECUTABLE) (Required is at least version "2.6") -- Could NOT find PythonInterp (missing: PYTHON_EXECUTABLE) (Required is at least version "3.4") -- Could NOT find PythonInterp (missing: PYTHON_EXECUTABLE) (Required is at least version "3.2") -- Looking for ccache - not found -- Performing Test HAVE_CXX_FSIGNED_CHAR -- Performing Test HAVE_CXX_FSIGNED_CHAR - Success -- Performing Test HAVE_C_FSIGNED_CHAR -- Performing Test HAVE_C_FSIGNED_CHAR - Success -- Performing Test HAVE_CXX_W -- Performing Test HAVE_CXX_W - Success -- Performing Test HAVE_C_W -- Performing Test HAVE_C_W - Success -- Performing Test HAVE_CXX_WALL -- Performing Test HAVE_CXX_WALL - Success -- Performing Test HAVE_C_WALL -- Performing Test HAVE_C_WALL - Success ......

Then run the make command..

make

The above commands output will looks like..

[ 0%] Generate opencv.pc [ 0%] Built target gen-pkgconfig Scanning dependencies of target zlib [ 0%] Building C object 3rdparty/zlib/CMakeFiles/zlib.dir/adler32.c.o [ 1%] Building C object 3rdparty/zlib/CMakeFiles/zlib.dir/compress.c.o [ 1%] Building C object 3rdparty/zlib/CMakeFiles/zlib.dir/crc32.c.o [ 1%] Building C object 3rdparty/zlib/CMakeFiles/zlib.dir/deflate.c.o [ 1%] Building C object 3rdparty/zlib/CMakeFiles/zlib.dir/gzclose.c.o [ 1%] Building C object 3rdparty/zlib/CMakeFiles/zlib.dir/gzlib.c.o [ 1%] Building C object 3rdparty/zlib/CMakeFiles/zlib.dir/gzread.c.o [ 1%] Building C object 3rdparty/zlib/CMakeFiles/zlib.dir/gzwrite.c.o [ 1%] Building C object 3rdparty/zlib/CMakeFiles/zlib.dir/inflate.c.o [ 1%] Building C object 3rdparty/zlib/CMakeFiles/zlib.dir/infback.c.o [ 1%] Building C object 3rdparty/zlib/CMakeFiles/zlib.dir/inftrees.c.o [ 1%] Building C object 3rdparty/zlib/CMakeFiles/zlib.dir/inffast.c.o [ 1%] Building C object 3rdparty/zlib/CMakeFiles/zlib.dir/trees.c.o [ 1%] Building C object 3rdparty/zlib/CMakeFiles/zlib.dir/uncompr.c.o [ 1%] Building C object 3rdparty/zlib/CMakeFiles/zlib.dir/zutil.c.o [ 2%] Linking C static library ../lib/libzlib.a [ 2%] Built target zlib Scanning dependencies of target libjpeg-turbo [ 2%] Building C object 3rdparty/libjpeg-turbo/CMakeFiles/libjpeg-turbo.dir/src/jcapimin.c.o [ 3%] Building C object 3rdparty/libjpeg-turbo/CMakeFiles/libjpeg-turbo.dir/src/jcapistd.c.o [ 3%] Building C object 3rdparty/libjpeg-turbo/CMakeFiles/libjpeg-turbo.dir/src/jccoefct.c.o [ 3%] Building C object 3rdparty/libjpeg-turbo/CMakeFiles/libjpeg-turbo.dir/src/jccolor.c.o [ 3%] Building C object 3rdparty/libjpeg-turbo/CMakeFiles/libjpeg-turbo.dir/src/jcdctmgr.c.o [ 3%] Building C object 3rdparty/libjpeg-turbo/CMakeFiles/libjpeg-turbo.dir/src/jchuff.c.o [ 3%] Building C object 3rdparty/libjpeg-turbo/CMakeFiles/libjpeg-turbo.dir/src/jcinit.c.o [ 3%] Building C object 3rdparty/libjpeg-turbo/CMakeFiles/libjpeg-turbo.dir/src/jcmainct.c.o [ 3%] Building C object 3rdparty/libjpeg-turbo/CMakeFiles/libjpeg-turbo.dir/src/jcmarker.c.o [ 3%] Building C object 3rdparty/libjpeg-turbo/CMakeFiles/libjpeg-turbo.dir/src/jcmaster.c.o [ 3%] Building C object 3rdparty/libjpeg-turbo/CMakeFiles/libjpeg-turbo.dir/src/jcomapi.c.o [ 3%] Building C object 3rdparty/libjpeg-turbo/CMakeFiles/libjpeg-turbo.dir/src/jcparam.c.o [ 3%] Building C object 3rdparty/libjpeg-turbo/CMakeFiles/libjpeg-turbo.dir/src/jcphuff.c.o [ 3%] Building C object 3rdparty/libjpeg-turbo/CMakeFiles/libjpeg-turbo.dir/src/jcprepct.c.o [ 3%] Building C object 3rdparty/libjpeg-turbo/CMakeFiles/libjpeg-turbo.dir/src/jcsample.c.o [ 3%] Building C object 3rdparty/libjpeg-turbo/CMakeFiles/libjpeg-turbo.dir/src/jctrans.c.o [ 4%] Building C object 3rdparty/libjpeg-turbo/CMakeFiles/libjpeg-turbo.dir/src/jdapimin.c.o [ 4%] Building C object 3rdparty/libjpeg-turbo/CMakeFiles/libjpeg-turbo.dir/src/jdapistd.c.o ..... [100%] Linking CXX executable ../../bin/opencv_annotation [100%] Built target opencv_annotation Scanning dependencies of target opencv_visualisation [100%] Building CXX object apps/visualisation/CMakeFiles/opencv_visualisation.dir/opencv_visualisation.cpp.o [100%] Linking CXX executable ../../bin/opencv_visualisation [100%] Built target opencv_visualisation Scanning dependencies of target opencv_interactive-calibration [100%] Building CXX object apps/interactive-calibration/CMakeFiles/opencv_interactive-calibration.dir/calibController.cpp.o [100%] Building CXX object apps/interactive-calibration/CMakeFiles/opencv_interactive-calibration.dir/calibPipeline.cpp.o [100%] Building CXX object apps/interactive-calibration/CMakeFiles/opencv_interactive-calibration.dir/frameProcessor.cpp.o [100%] Building CXX object apps/interactive-calibration/CMakeFiles/opencv_interactive-calibration.dir/main.cpp.o [100%] Building CXX object apps/interactive-calibration/CMakeFiles/opencv_interactive-calibration.dir/parametersController.cpp.o [100%] Building CXX object apps/interactive-calibration/CMakeFiles/opencv_interactive-calibration.dir/rotationConverters.cpp.o [100%] Linking CXX executable ../../bin/opencv_interactive-calibration [100%] Built target opencv_interactive-calibration Scanning dependencies of target opencv_version [100%] Building CXX object apps/version/CMakeFiles/opencv_version.dir/opencv_version.cpp.o [100%] Linking CXX executable ../../bin/opencv_version [100%] Built target opencv_version

After this.. run make install with sudo..

sudo make install

The output will look like below one..

root@10a4bdccb67a:~/opencv/build# make install [ 0%] Built target gen-pkgconfig [ 2%] Built target zlib [ 6%] Built target libjpeg-turbo [ 9%] Built target libtiff [ 17%] Built target libwebp [ 19%] Built target libjasper [ 20%] Built target libpng [ 25%] Built target IlmImf [ 27%] Built target ippiw [ 32%] Built target libprotobuf [ 32%] Built target ittnotify [ 32%] Built target opencv_test_core_pch_dephelp [ 32%] Built target opencv_core_pch_dephelp [ 32%] Built target opencv_ts_pch_dephelp [ 32%] Built target pch_Generate_opencv_ts [ 32%] Built target pch_Generate_opencv_core [ 38%] Built target opencv_core [ 39%] Built target opencv_imgproc_pch_dephelp [ 39%] Built target pch_Generate_opencv_imgproc [ 43%] Built target opencv_imgproc [ 43%] Built target opencv_imgcodecs_pch_dephelp [ 43%] Built target pch_Generate_opencv_imgcodecs [ 45%] Built target opencv_imgcodecs [ 45%] Built target opencv_videoio_pch_dephelp [ 45%] Built target pch_Generate_opencv_videoio [ 46%] Built target opencv_videoio [ 46%] Built target opencv_highgui_pch_dephelp [ 46%] Built target pch_Generate_opencv_highgui [ 46%] Built target opencv_highgui [ 47%] Built target opencv_ts [ 47%] Built target pch_Generate_opencv_test_core [ 49%] Built target opencv_test_core ...... -- Installing: /usr/local/share/OpenCV/haarcascades/haarcascade_licence_plate_rus_16stages.xml -- Installing: /usr/local/share/OpenCV/haarcascades/haarcascade_lowerbody.xml -- Installing: /usr/local/share/OpenCV/haarcascades/haarcascade_profileface.xml -- Installing: /usr/local/share/OpenCV/haarcascades/haarcascade_righteye_2splits.xml -- Installing: /usr/local/share/OpenCV/haarcascades/haarcascade_russian_plate_number.xml -- Installing: /usr/local/share/OpenCV/haarcascades/haarcascade_smile.xml -- Installing: /usr/local/share/OpenCV/haarcascades/haarcascade_upperbody.xml -- Installing: /usr/local/share/OpenCV/lbpcascades/lbpcascade_frontalcatface.xml -- Installing: /usr/local/share/OpenCV/lbpcascades/lbpcascade_frontalface.xml -- Installing: /usr/local/share/OpenCV/lbpcascades/lbpcascade_frontalface_improved.xml -- Installing: /usr/local/share/OpenCV/lbpcascades/lbpcascade_profileface.xml -- Installing: /usr/local/share/OpenCV/lbpcascades/lbpcascade_silverware.xml -- Installing: /usr/local/bin/opencv_traincascade -- Installing: /usr/local/bin/opencv_createsamples -- Installing: /usr/local/bin/opencv_annotation -- Installing: /usr/local/bin/opencv_visualisation -- Installing: /usr/local/bin/opencv_interactive-calibration -- Installing: /usr/local/bin/opencv_version root@10a4bdccb67a:~/opencv/build#

One more step.. just link and cache the required files with following commands

sudo /bin/bash -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf' sudo ldconfig

Now you can check the installation by running below command.. it will print out the version of opencv in stdout

pkg-config --modversion opencv

Here's the small shell script to automate the process... :)

That's it for now.. If you like.. don't forget to share it guys.. You can follow us on fb.com/opensourceinside and also subscribe our channel on Youtube..


Saturday, September 15, 2018

Getting Started With RabbitMQ in 10 Minutes (On Ubuntu)

Getting Started With RabbitMQ in 10 Minutes



RabbitMQ is one of the most popular opensource message broker/Queuing engine available in the market.. It has been used as communication(Message Oriented) bridge in many software architectures.. Communication between Microservices is one of the obvious use case where we can use MQ to make things simple .. RabbitMQ makes communication between services easy with it's simple messaging system.. Rabbit MQ supports multiple protocols like AMQP

In one of our projects, We've used it to delegate the heavy processing things to worker process written in python form single threaded NodeJs process.. thus it makes easy to scale our services and opened the doors to polyglot architecture for our services... we enjoyed it a lot.. So I thought to write a simple article which will help people to get start with RabbitMQ in 10 minutes..

Installing RabbitMQ (In Ubuntu based systems)

First update source-list and add signing key

sudo apt update wget -O - 'https://dl.bintray.com/rabbitmq/Keys/rabbitmq-release-signing-key.asc' | sudo apt-key add -

Now add repository to source list

echo "deb https://dl.bintray.com/rabbitmq/debian $(lsb_release -cs) main erlang" | sudo tee /etc/apt/sources.list.d/bintray.rabbitmq.list

Now update the source list and install the RabbitMQ ....

sudo apt update sudo apt install rabbitmq-server -y

The server is started as a daemon by default when the RabbitMQ is installed.

Verify the installation.. with the following command...

sudo systemctl status rabbitmq-server.service
shivaraj@shivaraj-Aspire-A315-21:~$ sudo systemctl status rabbitmq-server.service [sudo] password for shivaraj: ● rabbitmq-server.service - RabbitMQ broker Loaded: loaded (/lib/systemd/system/rabbitmq-server.service; enabled; vendor preset: enabled) Active: active (running) since Sat 2018-09-15 15:25:31 IST; 1h 29min ago Main PID: 1217 (beam.smp) Status: "Initialized" Tasks: 86 (limit: 4486) CGroup: /system.slice/rabbitmq-server.service ├─1217 /usr/lib/erlang/erts-9.2/bin/beam.smp -W w -A 64 -P 1048576 -t 5000000 -stbt db -zdbbl 1280000 -K true -- -root /usr/lib/erlang -progname erl -- -home /var/lib/rabbitmq -- -p ├─1333 /usr/lib/erlang/erts-9.2/bin/epmd -daemon ├─1572 erl_child_setup 1024 ├─1624 inet_gethost 4 └─1625 inet_gethost 4 Sep 15 15:25:26 shivaraj-Aspire-A315-21 rabbitmq-server[1217]: ## ## Sep 15 15:25:26 shivaraj-Aspire-A315-21 rabbitmq-server[1217]: ## ## RabbitMQ 3.7.7. Copyright (C) 2007-2018 Pivotal Software, Inc. Sep 15 15:25:26 shivaraj-Aspire-A315-21 rabbitmq-server[1217]: ########## Licensed under the MPL. See http://www.rabbitmq.com/ Sep 15 15:25:26 shivaraj-Aspire-A315-21 rabbitmq-server[1217]: ###### ## Sep 15 15:25:26 shivaraj-Aspire-A315-21 rabbitmq-server[1217]: ########## Logs: /var/log/rabbitmq/rabbit@shivaraj-Aspire-A315-21.log Sep 15 15:25:26 shivaraj-Aspire-A315-21 rabbitmq-server[1217]: /var/log/rabbitmq/rabbit@shivaraj-Aspire-A315-21_upgrade.log Sep 15 15:25:26 shivaraj-Aspire-A315-21 rabbitmq-server[1217]: Starting broker... Sep 15 15:25:31 shivaraj-Aspire-A315-21 rabbitmq-server[1217]: systemd unit for activation check: "rabbitmq-server.service" Sep 15 15:25:31 shivaraj-Aspire-A315-21 systemd[1]: Started RabbitMQ broker. Sep 15 15:25:32 shivaraj-Aspire-A315-21 rabbitmq-server[1217]: completed with 3 plugins. shivaraj@shivaraj-Aspire-A315-21:~$

And also I'll show you small how to with NodeJS and RabbitMQ.. for this you need to have Node installed in your system.. If you haven't installed NodeJs you can check the instructions here..

First you need to install amqplib.. it's RabbitMQ client for NodeJs..

npm install amqplib

Then create two files named.. sender.js and receiver.js

Now you can run the receiver.js and and publisher.js and you can see the output like one shown below...

node sender.js
shivaraj@shivaraj-Aspire-A315-21:~/mqtest$ node sender.js Connected Published New Task Published New Task Published New Task
node receiver.js
shivaraj@shivaraj-Aspire-A315-21:~/mqtest$ node receiver.js Connected Do Something.... Do Something.... Do Something.... Do Something.... Do Something....

If you want to use it with other languages.. please check official guide.. https://www.rabbitmq.com/getstarted.html

That's it for now.. If you like.. don't forget to share it guys.. You can follow us on fb.com/opensourceinside and also subscribe our channel on Youtube..