Google Ads

Linux and Software: News, Reviews, Tutorials

August 8, 2016

Ubuntu synchronise Google calendar and contacts and view & edit google drive files with GNOME applications

If you are using Ubuntu 16.04 then you can easily integrate Google apps experiences into your Ubuntu Desktop by using GNOME desktop applications. Which means you can easily view and edit your Google account calendars and contacts books right from your Ubuntu desktop without needing to open-up a web browser and sign-in to google account every-time you have to amend something.

Now fire up a terminal and put the following command into to install GNOME control center, Calendar, and Contact applications and GNOME online accounts package:

sudo apt-get install gnome-control-center gnome-contacts gnome-calendar gnome-online-accounts


If everything is installed properly, you should be able to find corresponding applications icons into Dash applications tab. Now, in the Dash search for Settings icon and click to launch All Settings window like shown below:


Now goto Online Accounts and click on the plus sign which will open Add Account dialog. Select Google and sign into your google account. Finally, click Allow button to give GNOME applications access to your Google services. Now you should see which Google services will be synchronised with the GNOME applications like shown below:


From here you can easily toggle the services you do not like to be synchronised with the Desktop applications. Turn on Calender, Contacts and Files which will in turn let you access Google Calender, Contacts and Drive from GNOME Calender, Contacts and File applications.

Accessing Google Calendar:

Search for Calendar icon in the Dash and open it. Click on the Manage your Calendar icon and select Calendar Settings from the popup menu. Now in the Calendar Settings dialog window click add button and select from web if your Google account calendars are not showing in the Calendars list like shown below:






Every time you change calendars you have to click Synchronize from the GNOME Calender application.

Accessing Google Contacts:

Search for Contacts icon in the Dash and open it. From Change Address Book dialog window select your Google account, like shown below:


The application will automatically synchronise your contacts upon change.

Accessing Google Drive files:

When you open Nautilus file manager (GNOME Files), you should be able to see your Google account email with other storage drives like shown below:


With GNOME Files, you will be able to access Google Drive files just like any other local disk partitions. To reflect any changes to the Google Drive do not forget to Unmount from the GNOME Files application.

Cheers,
Imam

October 5, 2015

Using OpenCV in GTK+ applications

Although OpenCV comes with it's own windowing system for displaying any OpenCV images, for fully functional applications with user interface elements such as buttons, menus, and radio buttons, maybe you would find it useful to use widget libraries such as GTK+ or QT. Drawing OpenCV image surfaces in GTK+ applications is not much of a difficult task than adding a couple of extra lines in your existing GTK+ applications. And again there are plenty of ways to accomplish the same results, but here I will show how I have achieved it. The sample program here is written using GTK+ C++ binding GTKmm, but the technique and functions should be same across all the GTK+ bindings.

As usual we create a GTK+ top level window by creating a MainWindow object. MainWindow, which is itself a GtkWindow widget contains one GtkFrame and one GtkDrawingArea widgets. The class definition of MainWindow is shown below:
class MainWindow : public Gtk::Window
{
  protected:
    Gtk::Frame video_frame;
    VideoArea video_area;
  public:
    MainWindow ();
    virtual ~MainWindow();
};
In the above code, VideoArea is the GtkDrawingArea widget object defined as follows:
class VideoArea : public Gtk::DrawingArea
{
  protected:
    cv::VideoCapture cv_cap;
    bool cv_opened;
    virtual bool on_draw (const Cairo::RefPtr<Cairo::Context> &cr);
    bool on_timeout ();
  public:
    VideoArea ();
    virtual ~VideoArea();
};
We are going to use GtkDrawingArea widget for the purpose of displaying OpenCV image surface. To do that, we have to put OpenCV related functions in the GtkDrawingArea on_draw function. This on_draw function will be called every time draw signal is emitted from GtkDrawingArea widget. As can be seen from the VideoArea object definition, we also have a timer function on_timeout to call on_draw function in a regular manner by invalidating GtkDrawingArea widget. So when a VideoArea object is created in the MainWindow object OpenCV is initialized like shown in the code below:
VideoArea::VideoArea() : cv_opened(false)
{
  cv_cap.open(0);
  
  if (cv_cap.isOpened() == true) {
    cv_opened = true;
    Glib::signal_timeout().connect(sigc::mem_fun(*this, &VideoArea::on_timeout), 50);
  }
}
Here, we connect a glib timeout signal, which will call on_timeout function every 50 milliseconds interval. The functions for on_timeout and on_draw are shown below:
bool VideoArea::on_timeout()
{
  Glib::RefPtr<Gdk::Window> win = get_window();
  
  if (win) {
    Gdk::Rectangle r(0, 0, get_allocation().get_width(), get_allocation().get_height());
    win->invalidate_rect(r, false);
  }
  
  return true;
}

bool VideoArea::on_draw(const Cairo::RefPtr<Cairo::Context> &cr)
{
  if (!cv_opened) return false;
  
  cv::Mat cv_frame, cv_frame1;
  cv_cap.read(cv_frame);
  if (cv_frame.empty()) return false;
  
  cv::cvtColor (cv_frame, cv_frame1, CV_BGR2RGB);
  Gdk::Cairo::set_source_pixbuf (cr, Gdk::Pixbuf::create_from_data(cv_frame1.data, Gdk::COLORSPACE_RGB, false, 8, cv_frame1.cols, cv_frame1.rows, cv_frame1.step));
  cr->paint();
  
  return true;
}
In the on_draw function, we convert OpenCV surface to RGB channel by using cvtColor, since GTK widgets uses RGB format. Finally, we use Gdk::Pixbuf::create_from_data to fill Cairo surface with OpenCV surface pixel buffers.
Download the complete program source code and test it by yourself!

gtkcv.zip

To compile the files in gtkcv.zip, you need to have OpenCV and gtkmm development files installed on your operating system. On Ubuntu just follow the instructions below:

Installing OpenCV:

Downloading OpenCV and creating compile directory,

From http://opencv.org/ grab opencv-3.0.0 and extract the opencv-3.0 archive file. Then, create a folder named build inside the opencv-3.0.0 folder. Then, open a terminal into the build folder. Then, in the terminal put the following commands:

First, setup compile environment for OpenCV
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr -D WITH_OPENMP=ON -D WITH_CUDA=OFF .. 

Now, compile sources in 4 threads
make -j 4 

Now, install OpenCV
sudo make install

Installing gtkmm:

sudo apt-get install libgtkmm-3.0-dev

That's it!, now extract the gtkcv.zip file and open a terminal in the gtkcv folder and execute the following command:

g++ -o gtkcv main.cpp MainWindow.cpp VideoArea.cpp `pkg-config --cflags --libs gtkmm-3.0 opencv`

This will produce gtkcv executable file.

Cheers,
Imam