Saturday, November 23, 2013

Fixing : The Eclipse executable launcher was unable to locate its companion shared library

After upgrading from Ubuntu 12.10 to 13.04, I had this problem.

As it is usual case with eclipse "eclipse.ini" was the point of issue. 

This file can be found in /etc/eclipse.ini

Here are the contents my eclipse.ini file:

####################################################################
-startup
plugins/org.eclipse.equinox.launcher_1.2.0.dist.jar

--launcher.library
plugins/org.eclipse.equinox.launcher.gtk.linux.x86_1.1.100.dist

-showsplash
org.eclipse.platform

--launcher.XXMaxPermSize
256m

--launcher.defaultAction
openFile

-vmargs
-Xms1024m
-Xmx1600m
-XX:MaxPermSize=1024m
-Dorg.eclipse.equinox.p2.reconciler.dropins.directory=/usr/share/eclipse/dropins 

####################################################################

So first test was to check existance of org.eclipse.equinox.launcher_1.2.0.dist.jar

and org.eclipse.equinox.launcher.gtk.linux.x86_1.1.100.dist on system. 

Upgrade replaced these files with newer versions. 
  
So fixing this issue was as simple as changing names of these files to match newer version. 

New contents my eclipse.ini file

####################################################################  

-startup
plugins/org.eclipse.equinox.launcher_1.3.0.dist.jar

--launcher.library
plugins/org.eclipse.equinox.launcher.gtk.linux.x86_1.1.200.dist

-showsplash
org.eclipse.platform

--launcher.XXMaxPermSize
256m

--launcher.defaultAction
openFile

-vmargs
-Xms1024m
-Xmx1600m
-XX:MaxPermSize=1024m
-Dorg.eclipse.equinox.p2.reconciler.dropins.directory=/usr/share/eclipse/dropins 

######################################################################  

Wednesday, November 6, 2013

Configure apt-get to work from behind the proxy server

I have divided this tutorial in three parts.

In the first part we enable proxy authentication for all bash commands.
In the second part of this tutorial, I will describe the procedure for enabling proxy authentication for aptitude package manager or famously known as APT. 
The third part deals with bit of security and gives more insight of the chmod command. 

Part I: Edit bash.bashrc.

bash.bashrc is configuration file for the bash shell. There are lot of ways in which you can customize shell experience using this file. For editing bash.bashrc you need to be root. Run following command to open this file with root privileges

$ gksudo gedit
You will be asked to authenticate, enter password for the admin account. 
Now from gedit open /etc/bash.bashrc and add following lines at the end of this file

Export http_proxy = http://username:password@proxyserver:port/
Export https_proxy = http://username:password@proxyserver:port/
Export ftp_proxy = http://username:password@proxyserver:port/

where <username> is your username and <password> is your password. 
For example:

Export http_proxy = http://sumit:password@10.10.1.1:3128/
Export https_proxy = http://sumit:password@10.10.1.1:3128/
Export ftp_proxy = http://sumit:password@10.10.1.1:3128/
Save this file. 

Part II: Edit apt.conf 

As you might have guessed, apt.conf is configuration file for APT. Once again run gedit in root mode
using 

$ gksudo gedit

From /etc/apt/ open apt.conf file. 
[Depending on your Linux distribution this file may be absent in that directory, in which case you should create new file and save it as apt.conf in /etc/apt/ ].

Add following details to this file:

Acquire::http::proxy "http://username:password@proxyserver:port/";
Acquire::https::proxy "https://username:password@proxyserver:port/";
Acquire::socks::proxy "socks://username:password@proxyserver:port/";
This should get APT working on your system. But as you may have already noticed that these two files are stored as a plain text and anyone can open and read these files. To prevent this threat you can use chmod which stands for 'change mode'.

Friday, November 1, 2013

Repack packages [Generate installation files from installed applications]: Ubuntu [Debian]

There is a way to repack installed packages from Ubuntu, so that the same package can be used to install application on other systems as well. Packages are nothing but installation files. Usually we end up downloading these packages for every new installation, in this post we will discuss how to avoid that.  

1) First of all we need to install fakeroot.


"Fakeroot" simulates the root environment for execution of commands which require root privileges otherwise. 

2) Install dpkg. dpkg is a package manager for Debian.


3) Now next step is to repack the package.
This script requires 'package name' of application/library to repack. Usually name of packages and applications/libraries are same, but this is not true in every case. For example consider opencv which is collection of many libraries.

Package name can be confirmed using following command.


Having done that use following command to repack.



Entire Backup

The procedure explained above is good only if you need backup of select applications. To repack entire system you need better strategy since typing name of every single package is not that good idea. 

So to begin with, we first of all generate a list of installed packages and store that output to a text file.


The output file contains a list of packages. Every row begins with the name of package and the status of that package. We need to remove all the packages which are marked as deinstall from the list. For this you can use simple search and replace. 

Next step is to reformat this output file so that is can be as a bash script.  Delete all the occurrences of word "install" and remove all new-line characters from the file. Add "sudo fakeroot dpkg-repack " at the beginning of file and save this file as backup.sh . Change file permissions to make it executable and execute backup.sh from terminal. This will generate Debian packages for all the listed package names. 
The script should look like this,



Sunday, October 27, 2013

Backup your router settings: D-Link [ DSL-2730U] and Restore

BACKUP

1) Log In: [192.168.1.1] [DEFAULTS - username: admin , password: admin]

2) Click on the 'Management' tab:

3) Click on the backup settings and save this file. This config.xml file is snapshot of your current settings. You can use this snapshot to restore settings of your router.
Along with this config.xml file you should store your current admin password[192.168.1.1], current name of the wifi network and password for this wifi network.

To capture all this information you can use following template for naming backup-file.
<Name_of_wifi>_<password for admin>_<password for wifi>.xml
e.g. TC-45G_admin_default

So when you restore settings of router, you know that you should connect to network "TC-45G" using password as "default" and for configuration you should use [192.168.1.1] "admin" as a password.

I will suggest you to disable mac address filtering before taking backup.


    Disable Mac Address filtering:      1) Click on the advanced tab.

 
     2) Click on Mac Filtering, and disable Access Control Mode.

RESTORE 

1) Log in to 192.168.1.1 using current password.

2) Click on management.

3) In the section system update settings-> "choose file" and select you backup file.
    Say update settings.
    This will reboot you router, and restore settings from selected snapshot. Now you can use your old      password to connect to this router.  

Saturday, October 26, 2013

Image Filtering : Opencv Interface

In the previous post we have seen how to manually define custom filters.
We made use of filter2D function with Gaussian kernel and Blur operator to demonstrate working of this function.

Opencv provides predefined functions for most common operators like blur operator, Gaussian operator, in this post we are going to discuss how to make use of this interface.


  1. Blur operator
    We have already discussed this filter in this post.
  2. Gaussian Filter
    Gaussian filter is discussed here.
  3. Median Filter
    As the name suggests median operator takes median of all the elements covered by mask, and replaces center pixel with this median.
Code:
Results:

Sunday, October 20, 2013

Bash script: Volume and Brightness [Ubuntu 12.04]

1) Brightness.sh 

Allows you to set up brightness of your monitor using terminal.

Following command is used to set brightness level.

sudo sh -c 'echo <brightness> > /sys/class/backlight/<device>/brightness'

Here <brightness> is brightness level, and takes integer values starting from 0. Higher the value, higher the brightness.


2) Volume.sh 

Allows you to mute or unmute speakers.

Mute

pactl set-sink-mute 0 1

Enable speakers

pactl set-sink-mute 0 0

Here pactl stands for 'Pulse Audio Control'

3) Startup.sh

This script will run every bash script from given directory.

I use this script for switching profiles.

For example if I store brightness.sh and volume.sh in startup_scripts directory and run startup.sh then this startup.sh will run both brightness.sh and volume.sh for me.



Monday, October 14, 2013

Image Filtering : Gaussian Filter

First things first, what is Gaussian filter?

Gaussian filter is a kernel based on the values obtained by plotting Gaussian function.

In my previous post we have seen how to use filter2D function provided by opencv to perform correlation on the images with given kernel.

We also discussed an example of blur operator. This operator assigns equal weight to every element in the neighborhood. But it is quite natural to think that the pixels which are close to target pixel in image should have more weight assigned to them. This is exactly what we try to achieve using Gaussian filter.

Gaussian function is given by,

 The plot of this function looks like this,

Values of Gaussian function have been used to construct this kernel.
As you can see the center pixel has maximum weight of 0.159 and weight values decreases as the distance from center pixel increases. All the pixels which are at same distance from the center pixel have same weight value, are also known as contours.

Following image is formed using Gaussian kernel.

Lets compare results of blur operator in the previous post and


Original Image


Blur Operator


Gaussian Smoothing
As it is evident from the result that features of image are well preserved in case of Gaussian kernel than that of the blur operator.

Sample code for Gaussian Blurring:

Sunday, October 13, 2013

Image Filtering Basics: Convolution and Correlation - II

As we discussed in the previous post opencv allows us to perform convolution and correlations easily.
Actually opencv lets you perform correlation only. There is difference in correlation and convolution,
for performing convolution we first rotate mask chosen by 180 degree and then apply the procedure discussed in the part I of this post.

More formally correlation is defined as
whereas convolution is defined as
As you can see negative arguments in case of mask F are have negative sign. This corresponds to reflection against x and y axis or in other words rotation by 180 degrees. 
In standard literature mask is also known as kernel, we will follow this convention throughout this blog here onward.

The filter2D is a function provided by opencv to perform correlation
Signature of filter2D.

filter2D(srcdstddepthkernelanchordelta,Border_Type);    

Mat src : source image.
Mat dst : destination image.
ddepth : image depth of the destination.
kernel : Mask function.
Anchor : represents location of anchor/ origo w.r.t the kernel.
delta : a value to be added to each pixel during convolution.
Border_Type : Way to pad image.



Results:
Original Image

With blur operator of size 5x5




Friday, October 11, 2013

Image Filtering Basics: Convolution and Correlation.

Let's consider two images I and F. I is input image and F is mask.

Correlation

For convolution we keep center of mask matrix over every pixel of input image update that value with weighted sum of every other pixel covered by the mask.

As can be seen from the above image, in the 10 is the center of  area covered by mask in 'I'.
So in output image that value is updated by the the expression given in the image. This operation is repeated for every pixel of the input image and output image is constructed. 

As you might have guessed by now that given mask computes average values in the neighborhood and updates the center pixel with this new value. As a result we get a smoother image in output. Saying that output will be a smoother image is quite intuitive, clearly every pixel in the output image (o) will have a component from the neighboring pixels. This components decrease the difference in intensities values of neighboring pixels. Hence change in intensity while moving across new image is lesser or in other words smoother.   

If we change the mask we get different results. For example if change the value of the center pixel of the mask by 2. The the image obtained by taking convolution will have more weight to the current pixel being scanned. 

Lets see few example of this operation:

1) Here F has only center pixel as 1. Therefore contribution from neighbors is 0 and there is no change in image. 

2) Shift operator
 3) Blur operator which we discussed in the main part
In the next post we are going to discuss how to perform convolution with opencv.

Image Processing Basics : Intensity [Part II] _ Convert image into Binary Format

In this post we will study the effect of increasing number of bits used for storing each pixel.
[Basics of image representation are covered here]
[Github : Gist]


Result:
 Original Image
No intensity levels allowed = 2.
No of intensity levels = 4
No of intensity levels = 8

It is very clear from the results obtained that as no. of intensity levels or in other words bits associated with every pixel increases quality of image increases. 

Thursday, October 10, 2013

Image Processing Basics: Intensity

A digital image is nothing but an array of numbers. Every number represents intensity of corresponding pixel. We usually use 8 bits for storing intensity of a pixel i.e. we can store 0 - 255 discrete intensity values.

As we increase number of bits associated with each pixel total number of intensity levels increases and hence quality of the image. So a gray image which has only one type of intensity and has dimension NxM, will have size of 8*NxM bits or NxM bytes. Similarly a color image with 8 bit representation would consume 3*NxM bytes of memory space.

Typical range of N and M is around 1000~2000. As you can see with increase in every bit of the image representation, size of image increases significantly.

In this post we are going to discuss how to access elements of image using iterators.

But before that let's discuss few terms.

1) Iterators : Iterators are nothing but a way to access data from containers. C++ provides us a way to access elements from structures provided by standard template library like stack, queue and map. We are going to use iterators to access individual pixel of image.

2) typeof : typeof is a special keyword provided by c++ which returns type of current object.

Let's start with code.

Function saturate takes image, increase and channel no as an input.
As an output it generates new image with increased intensity for given channel.
Github : Gist

Result:

First one is the original image and the second one is output image. The dark part in output is because of overflow.






Installing OpenCV [Ubuntu 12.04 + Eclipse] : Part II

This post assumes that you have already installed opencv packages on your system. [If you haven't please check this post.]  

Having installed packages next step is to set up Eclipse.
  1. Open Synaptic Package manager. In quick filter box type 'Eclipse'. 
  2. Select 'eclipse' and 'eclipse-cdt' , select mark for installation and click apply. 
  3. Open Eclipse. This will ask you to select workspace. Select the location where you plan to save your source code.
  4. Select Flie->New->C++ Project.

  5. Name project as tutProjectSetup. From project type select Empty Project. Click Finish.
  6. This will create a new project. From the Project Explorer window select this new project.
  7. From toolbar select project->properties.
  8. Expand C/C++ build from the right pane. In settings box click on the tab Tool Settings. 
  9. Expand cross GCC Compiler select Includes. Type the include path for opencv here. To find out include path for your installation open terminal and type

    $ pkg-config --cflags opencv 

    This will output include path. 
    For example in my case output of pkg-config was -I/usr/include/opencv . Strip initial -I from the string and add this path to Include paths. In my case it is /usr/include/opencv .

  10. Select cross G++ Compiler and follow similar procedure mentioned in step 9. 
  11. Now select Cross G++ linker->Libraries.
    In  library search path section enter the path of opencv libraries. You can find out this path by typing following command on terminal

    $pkg-config --libs opencv

    This will generate output path and a list of libraries available in opencv package.
    Add this path in library search path. In my case this path is /usr/lib 
    In libraries section add following libraries. Adding first three of the list is usually sufficient.  

    opencv_core opencv_imgproc
    opencv_highgui
    opencv_ml opencv_video
    opencv_features2d
    opencv_calib3d
    opencv_objdetect
    opencv_contrib
    opencv_legacy
    opencv_flann

    Click ok.

  12. Lets test the configuration of our project. Right Click on project and add->new->folder. Name this folder as src. Right click on this folder and add new source file. Name this file as testConfig.cpp . 
  13. Add the code posted here to testConfig.cpp. 
  14. Again right click on project and create new folder. This time name this folder as res. Select a small jpg image from your computer and paste this image in res folder. Rename newly added image as download.jpg. 
  15. Right Click on tutProjectSetup and build. Again right click on project and select run as ->local c++ application.
  16. This will display your image in a new window.

Installing OpenCV [Ubuntu 12.04 + Eclipse] : Part I

  1. Open Synaptic package manager from dashboard.
    Note: Synaptic Package Manager can be installed from Ubuntu software center.

  2. Authenticate yourself.

  3. Type opencv in Quick Filter



  4. Select following packages from the list, select mark for installation.

    [It recommended to install all of the packages mentioned below, but min requirement is to install bold ones]

    libopencv-core2.3
    libopencv-contrib2.3, 
    libopencv-legacy2.3, 
    libopencv-gpu2.3, 
    libopencv-imageproc2.3
    libopencv-ml2.3
    libopencv-video2.3
    libopencv-calib3d2.3, 
    libopencv-objdetect2.3, 
    libopencv-features2d2.3, 
    libopencv-flann2.3, 
    libopencv-highgui2.3
    libopencv-core2.3, 
    libhighgui2.3, 
    libcvaux2.3, 
    libcv2.3

  5. Click apply.
  6. That is it. This should install opencv on your system.

    Part II

Tuesday, October 8, 2013

Hello OpenCV

Simple code for reading and displaying image.

Monday, September 30, 2013

Hello C++ : Explained.

1) Processor. 

#include <iostream > 

Iostream is one of the built in libraries provided by c++ to make input output easier.

As the name suggests, I-(Input) O - (Output) stream.

2) Namespace.

There are lot of libraries in c++. 

Even you can write your one of your own. 

To avoid confusion between name of different functions of different libraries the concept namespaces was introduced. 

std namespace defines all standard (inbuilt) functions.

3) 

Main code.
 
 

Sunday, September 29, 2013

Hello C++

Run Dev C++ from start menu.

Press ctrl+n.
[ctrl+n is standard command in for computer programs, which creates new instance, in our case new file]

Type this.

#include<iostream>

using namespace std;

int main()
{
   cout<<"Hello C++";
 
   int hold;
   cin>>hold;
 
   return 0;
}

Execute->Compile & Run. [Or you can press f11 (better way)]

Bingo!!


Introduction

This blog targets the audience with no or little programming background.

All the posts on this blog are very small.

Including this one.

Next 

Dirty Hands

Let's begin.

1)  Install Dev C++ [Windows]

     Download the setup: From Here

     Orwell Dev C++

     Install. Easy-Peasy, huh?

Next