Pages

Sunday, July 30, 2017

Installing Chrome on Ubuntu (16.04)

I recently installed Linux alongside Windows (dual boot). When I tried to install Chrome by downloading the latest installer from here, I got the following error:
$ sudo dpkg -i ./google-chrome-stable_current_amd64.deb
(Reading database ... 219479 files and directories currently installed.)
Preparing to unpack .../google-chrome-stable_current_amd64.deb ...
Unpacking google-chrome-stable (60.0.3112.78-1) over (60.0.3112.78-1) ...
dpkg: dependency problems prevent configuration of google-chrome-stable:
 google-chrome-stable depends on libappindicator1; however:
  Package libappindicator1 is not installed.

dpkg: error processing package google-chrome-stable (--install):
 dependency problems - leaving unconfigured
Processing triggers for desktop-file-utils (0.22-1ubuntu5.1) ...
Processing triggers for gnome-menus (3.13.3-6ubuntu3.1) ...
Processing triggers for bamfdaemon (0.5.3~bzr0+16.04.20160824-0ubuntu1) ...
Rebuilding /usr/share/applications/bamf-2.index...
Processing triggers for mime-support (3.59ubuntu1) ...
Processing triggers for man-db (2.7.5-1) ...
Errors were encountered while processing:
 google-chrome-stable
Thanks to the blog post from here, the solution is straightforward. To satisfy the dependencies, execute the following command and re-execute the dpkg command shown above.
$ sudo apt-get -f install
That's all :)

Monday, May 22, 2017

Tensorflow 1.1 (GPU) on Windows with cuDNN 6.0: No module named '_pywrap_tensorflow'

Short notes: if you got trouble importing tensorflow 1.1 (GPU) on Windows with cuDNN 6.0, try to use cuDNN 5.1 and ensure that the MSVC++2015 redistributable has been installed.

Reference: https://github.com/tensorflow/tensorflow/issues/7705

That's all :)

Saturday, May 13, 2017

Update Anaconda Navigator 1.5.0

I had trouble updating Anaconda Navigator from 1.5.0 to 1.5.2 in Windows 10. While there was a message indicating that the update was successful, the version remains. Gladly found the solution here: https://github.com/ContinuumIO/anaconda-issues/issues/1583 :
  1. Open command prompt
  2. Execute:
    C:¥> conda update --all --prefix <path_to_the_installed_conda>
That's all :)

Friday, December 19, 2014

Android Studio was unable to find a valid JVM

I obtained the following message when opening Android Studio 1.0.1 on Mac OSX Yosemite:
Android Studio was unable to find a valid JVM
Among some workarounds for the problem that I found in this Stackoverflow thread, I think the simplest one is by creating a small bash script that export the environment variable for the JVM and launch the Android Studio. For example, in my machine the JVM is located at /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk, so the script looks like this:
#!/bin/bash export STUDIO_JDK=/Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk open /Applications/Android\ Studio.app


That's all :)

Sunday, March 16, 2014

Kinect v2 developer preview + OpenCV 2.4.8: depth data

This time, I'd like to share code on how to access depth data using the current API of Kinect v2 developer preview using a simple polling, and display it using OpenCV. Basically the procedure is almost the same with accessing color frame.

In the current API, depth data is no longer mixed with player index (called body index in Kinect v2 API).

Disclaimer:
This is based on preliminary software and/or hardware. Software, hardware, APIs are preliminary and subject to change.
//Disclaimer:
//This is based on preliminary software and/or hardware, subject to change.

#include <iostream>
#include <sstream>

#include <Windows.h>
#include <Kinect.h>

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/contrib/contrib.hpp>

inline void CHECKERROR(HRESULT n) {
    if (!SUCCEEDED(n)) {
        std::stringstream ss;
        ss << "ERROR " << std::hex << n << std::endl;
        std::cin.ignore();
        std::cin.get();
        throw std::runtime_error(ss.str().c_str());
    }
}

// Safe release for interfaces
template
inline void SAFERELEASE(Interface *& pInterfaceToRelease) {
    if (pInterfaceToRelease != nullptr) {
        pInterfaceToRelease->Release();
        pInterfaceToRelease = nullptr;
    }
}

IDepthFrameReader* depthFrameReader = nullptr; // depth reader

void processIncomingData() {
    IDepthFrame *data = nullptr;
    IFrameDescription *frameDesc = nullptr;
    HRESULT hr = -1;
    UINT16 *depthBuffer = nullptr;
    USHORT nDepthMinReliableDistance = 0;
    USHORT nDepthMaxReliableDistance = 0;
    int height = 424, width = 512;

    hr = depthFrameReader->AcquireLatestFrame(&data);
    if (SUCCEEDED(hr)) hr = data->get_FrameDescription(&frameDesc);
    if (SUCCEEDED(hr)) hr = data->get_DepthMinReliableDistance(
        &nDepthMinReliableDistance);
    if (SUCCEEDED(hr)) hr = data->get_DepthMaxReliableDistance(
        &nDepthMaxReliableDistance);

    if (SUCCEEDED(hr)) {
            if (SUCCEEDED(frameDesc->get_Height(&height)) &&
            SUCCEEDED(frameDesc->get_Width(&width))) {
            depthBuffer = new UINT16[height * width];
            hr = data->CopyFrameDataToArray(height * width, depthBuffer);
            if (SUCCEEDED(hr)) {
                cv::Mat depthMap = cv::Mat(height, width, CV_16U, depthBuffer);
                cv::Mat img0 = cv::Mat::zeros(height, width, CV_8UC1);
                cv::Mat img1;
                double scale = 255.0 / (nDepthMaxReliableDistance - 
                    nDepthMinReliableDistance);
                depthMap.convertTo(img0, CV_8UC1, scale);
                applyColorMap(img0, img1, cv::COLORMAP_JET);
                cv::imshow("Depth Only", img1);
            }
        }
    }
    if (depthBuffer != nullptr) {
        delete[] depthBuffer;
        depthBuffer = nullptr;
    }
    SAFERELEASE(data);
}

int main(int argc, char** argv) {
    HRESULT hr;
    IKinectSensor* kinectSensor = nullptr;     // kinect sensor

    // initialize Kinect Sensor
    hr = GetDefaultKinectSensor(&kinectSensor);
    if (FAILED(hr) || !kinectSensor) {
        std::cout << "ERROR hr=" << hr << "; sensor=" << kinectSensor << std::endl;
        return -1;
    }
    CHECKERROR(kinectSensor->Open());

    // initialize depth frame reader
    IDepthFrameSource* depthFrameSource = nullptr;
    CHECKERROR(kinectSensor->get_DepthFrameSource(&depthFrameSource));
    CHECKERROR(depthFrameSource->OpenReader(&depthFrameReader));
    SAFERELEASE(depthFrameSource);

    while (depthFrameReader) {
        processIncomingData();
        int key = cv::waitKey(10);
        if (key == 'q'){
            break;
        }
    }

    // de-initialize Kinect Sensor
    CHECKERROR(kinectSensor->Close());
    SAFERELEASE(kinectSensor);
    return 0;
}
Results in my messy room:

If we modify the scaling, for example:
                nDepthMaxReliableDistance = 900;
                nDepthMinReliableDistance = 500;
                int i, j;
                for (i = 0; i < height; i++) {
                    for (j = 0; j < width; j++) {
                        UINT16 val = depthMap.at<UINT16>(i,j);
                        val = val - nDepthMinReliableDistance;
                        val = (val > nDepthMaxReliableDistance ? 
                            nDepthMinReliableDistance : val);
                        val = (val < 0 ? 0 : val);
                        depthMap.at<UINT16>(i,j) = val;
                    }
                }

                double scale = 255.0 / (nDepthMaxReliableDistance - 
                    nDepthMinReliableDistance);
                depthMap.convertTo(img0, CV_8UC1, scale);
                applyColorMap(img0, img1, cv::COLORMAP_WINTER);
                cv::imshow("Depth Only", img1);
It may look like this:
That's all :)

Thursday, March 13, 2014

Kinect v2 developer preview + OpenCV 2.4.8: grab the color frame to OpenCV Mat

I am quite lucky that I could participate in the Kinect V2 developer preview program. :) Here, I'd like to share a simple code to grab color frame from the Kinect v2 sensor and convert it to OpenCV Mat format.

Disclaimer:
This is based on preliminary software and/or hardware. Software, hardware, APIs are preliminary and subject to change.
//Disclaimer:
//This is based on preliminary software and/or hardware, subject to change.

#include <iostream>
#include <sstream>

#include <Windows.h>
#include <Kinect.h>

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>

inline void CHECKERROR(HRESULT n) {
    if (!SUCCEEDED(n)) {
        std::stringstream ss;
        ss << "ERROR " << std::hex << n << std::endl;
        std::cin.ignore(); 
        std::cin.get();
        throw std::runtime_error(ss.str().c_str());
    }
}

// Safe release for interfaces
template<class Interface>
inline void SAFERELEASE(Interface *& pInterfaceToRelease) {
    if (pInterfaceToRelease != nullptr) {
        pInterfaceToRelease->Release();
        pInterfaceToRelease = nullptr;
    }
}

IColorFrameReader* colorFrameReader = nullptr; // color reader

void processIncomingData() { 
    IColorFrame *data = nullptr;
    IFrameDescription *frameDesc = nullptr;
    HRESULT hr = -1;
    RGBQUAD *colorBuffer = nullptr;
 
    hr = colorFrameReader->AcquireLatestFrame(&data); 
    if (SUCCEEDED(hr)) hr = data->get_FrameDescription(&frameDesc);
    if (SUCCEEDED(hr)) {
        int height = 0, width = 0;
        if (SUCCEEDED(frameDesc->get_Height(&height)) && 
            SUCCEEDED(frameDesc->get_Width(&width))) {
            colorBuffer = new RGBQUAD[height * width];
            hr = data->CopyConvertedFrameDataToArray(height * width * sizeof(RGBQUAD),
                 reinterpret_cast<BYTE*>(colorBuffer), ColorImageFormat_Bgra);
            if (SUCCEEDED(hr)) {
                cv::Mat img1(height, width, CV_8UC4,
                    reinterpret_cast<void*>(colorBuffer));
                cv::imshow("Color Only", img1);
            }
        }
    }
    if (colorBuffer != nullptr) {
        delete[] colorBuffer;
        colorBuffer = nullptr;
    }
    SAFERELEASE(data);
}

int main(int argc, char** argv) {
    HRESULT hr;
    IKinectSensor* kinectSensor = nullptr;     // kinect sensor

    // initialize Kinect Sensor
    hr = GetDefaultKinectSensor(&kinectSensor);
    if (FAILED(hr) || !kinectSensor) {
        std::cout << "ERROR hr=" << hr << "; sensor=" << kinectSensor << std::endl;
        return -1;
    }
    CHECKERROR(kinectSensor->Open());

    // initialize color frame reader
    IColorFrameSource* colorFrameSource = nullptr; // color source
    CHECKERROR(kinectSensor->get_ColorFrameSource(&colorFrameSource));
    CHECKERROR(colorFrameSource->OpenReader(&colorFrameReader));
    SAFERELEASE(colorFrameSource);

    while (colorFrameReader) {
        processIncomingData();
        int key = cv::waitKey(10);
        if (key == 'q'){
            break;
        }
    }
 
    // de-initialize Kinect Sensor
    CHECKERROR(kinectSensor->Close());
    SAFERELEASE(kinectSensor);
    return 0;
}
That's all :)

Thursday, December 26, 2013

Files does not sync on shared folder VMWare Player

Since my Parallels software is not compatible with Mavericks, I decided to use Windows machine for virtualization. On Windows, I am using VMWare Player to run Linux occasionally. Recently, I often use the VMWare since the software that I am using is only available on Linux.

I found that using the latest VMWare tools (as this article is written), the files on shared folders are out of sync if they are modified from the host (Windows 7). After searching for the solutions, I found the discussions on the VMWare communities forum here: https://communities.vmware.com/message/2313778.

It seems that VMWare teams are still addressing the issues (as this article is written). Meanwhile, the solution is to revert back to older version of VMWare tools.

Here is the steps:
  1. Before turning on the VMWare, modify the VMWare file .vmx setting, otherwise, the downgrade can be overridden:
    tools.upgrade.policy = "manual"
  2. As super user, unmount the current shared folder. Example:
    # umount /mnt/hgfs
  3. Download the older version of the VMWare tool here (select the appropriate one based on the OS):
    https://softwareupdate.vmware.com/cds/vmw-desktop/fusion/6.0.1/1331545/packages/
    In my case, I downloaded com.vmware.fusion.tools.linux.zip.tar.
  4. Extract the file. If you are using linux, extract linux.iso file as well or just mount it.
  5. using super user, execute the vmware install script:
    # ./vmware-install.pl
  6. After completed, make sure the build version is build-1294478:
    root@ubuntu:~# vmware-toolbox-cmd -v
    9.6.0.26048 (build-1294478)
    

That's all :)

Thursday, October 10, 2013

Parallels 7 cannot install Ubuntu 13.04 with error: Soft lockup

Today I tried to install Ubuntu 13.04 on Parallels 7. But when booting using the installation disk, I got error message about Soft lockup.

Seems that the solution is very straightforward: remove the tick on the "Show battery in Linux" from the dialog of Options > Optimizations.

Credit to the thread from here. That's all :)

Monday, July 01, 2013

How to have a similar mouse acceleration on Mac OSX with Windows

Have you ever noticed that the movement of mouse pointer on Mac OSX is somewhat different from that of on Windows?

Before I started using Mac OSX around 3 years ago, I have been a heavy user of Windows and Linux for years. Probably this is just my personal preference, but I feel that the acceleration of mouse movement on Mac OSX is not as comfortable as on Windows. I have been looking for the solution to get the same acceleration "feel" ever since but found nothing comparable to Windows. I have tried several software that can control mouse acceleration on Mac OSX, but still not satisfied. Even there are lengthy discussion on Apple forum debating this matter.

Gladly, there are wonderful engineers that started to develop the promising solution: http://smoothmouse.com/

If anyone feel uncomfortable with the acceleration of mouse on Mac OSX, I would suggest to try this software. It surpasses any other softwares (includes the paid one) that I have tried to make my mouse movement on Mac OSX as similar as on Windows. I hope that Apple could notice this little yet important matter, especially for new users who were heavy users of Windows, and provide built-in solution on the next release of OSX. I could understand that not all users notice the difference. But It is somewhat a shame on Apple for not noticing this little matters for years.

That's all :)

Friday, March 15, 2013

WinShell cannot start AcrobatReader XI

When I tried to launch Acrobat Reader from WinShell, I got the following error message:
Cannot start AcrobatReader or open the document.
1. Please check on the exe file and cmd line of the PDFView options.
2. Please set correct Adobe DDE Version in registry key 'HKEY_CLASSES_ROOT\acrobat\shell\open\ddeexec\application'
Seems that the solution is quite straightforward:
  1. Make sure the Acrobat Reader is already running before calling it from WinShell (just run the Acrobat Reader from the start menu once, and keep it running).
  2. Edit the registry entry as mentioned in the error message. For example, in my case, I found that the value of my Acrobat Reader was set to AcroViewR10. Since I am using version 11, I have to change the value to AcroViewR11.
That's all :)

Wednesday, February 27, 2013

Change screen resolution of Ubuntu 12.10 on Parallels 7

When I installed Ubuntu 12.10 using Parallel 7 and installed the Parallels Tools, it seems that the screen resolution is fixed to 800 x 600 pixels only. Gladly that there is a workaround for this problem. It is by using the Parallels Tools from Parallels 8. Credit to the post here: http://forum.parallels.com/showpost.php?p=657046&postcount=53 The steps are as follows:
  1. Download the trial version of Parallels 8.
  2. Mount the dmg file of Parallels 8.
  3. Open terminal, go to the mounted dmg, for example in my system I did like this:
    $ cd /Volumes/Parallels\ Desktop\ 8/
  4. Copy the iso file of the Parallel Tools to my home directory (or any directory), example:
    $ cp ./Parallels\ Desktop.app/Contents/Resources/Tools/prl-tools-lin.iso ~/
  5. Mount the iso from the Ubuntu 12.10, and upgrade the Parallels Tools from Ubuntu 12.10 terminal, example:
    $ cd /media/{your-Ubuntu-user}/Parallels\ Tools $ sudo ./install
That's all :)

Saturday, September 29, 2012

Modifying PATH environment variable Windows 7 doesn't work?

For almost a week, I had trouble adding a directory to PATH environment variable in Windows 7 64bit. I was trying to add a path of "C:\Program Files (x86)\gs\gs9.05\bin" to the PATH environment variable, but it just didn't work. I even restarted the PC although it should be unnecessary, opened the command prompt and checked the content of the PATH, but I couldn't find anything wrong. Until finally... found the culprit.. It is the whitespace.

If you add a path, just make sure not to put any whitespace between the semicolon. As an example, the following second path may not work because there is a whitespace between the semicolon ';' and the letter 'C' :
C:\Program files\program 1\bin; C:\Program files\program 2\bin;
To make it work, remove the whitespace between semicolon ';' and the letter 'C':
C:\Program files\program 1\bin;C:\Program files\program 2\bin;

That's all :)

Thursday, July 26, 2012

OSX Mountain Lion workaround to enable web sharing

I have just upgraded to Mountain Lion. But I feel very disappointed that the web sharing feature is missing. I cannot access my local site, but somehow I still can get the default apache page when accessing http://localhost/.

Here is the workaround that I did to re-enable my own site. To make it safe, make sure to make a copy of /etc/apache2/httpd.conf before modifying anything.

(1) Open terminal, switch to root:
$ sudo su -
(2) Go to /etc/apache2/users/:
$ cd /etc/apache2/users $ ls
(3) I found one file Guest.conf. I copy the file into another file (in this case I am using my own user name: chn.conf), and edit the directory location to my Site location in "/Users/chn/Sites":
$ cp Guest.conf chn.conf $ vi chn.conf
It looks like this after the modification:
<Directory "/Users/chn/Sites/">
    Options Indexes MultiViews
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>
(4) Let apache load PHP module, by editing the httpd.conf:
$ vi /etc/apache2/httpd.conf
Search for the following line:
#LoadModule php5_module libexec/apache2/libphp5.so
and remove the remark "#" in the beginning of the line so it looks like this:
LoadModule php5_module libexec/apache2/libphp5.so
(5) Restart the apache service by the following command:
$ apachectl restart
Now I can access my own homepage again.

That's all :)

Monday, July 16, 2012

How to do screen capture in MacOSX in JPG instead of PNG

In MacOSX, we can easily do screen capture and save the image in PNG format to the desktop by the following keyboard shortcuts:
  • Comand+Shift+3 : capture the whole screen.
  • Comand+Shift+4 : capture a particular area by specifying the area using mouse, or by pressing spacebar to select a window.
Nevertheless, we may want to save the screen capture file in a different file format, such as JPG or maybe PDF. To do so, apply the following command in the terminal (the example is using JPG format):
$ default write com.apple.screencapture type jpg $ killall SystemUIServer

That's all :)

Sunday, May 08, 2011

Workaround for Lifehacker or gizmodo automatically redirect the browser from .com to .jp

I sometimes experienced that lifehacker.com or gizmodo.com do redirection automatically to lifehacker.jp or gizmodo.jp. Possibly that the website is either checking the ip address of the user or the browser's local language setting. This auto redirection is quite annoying when accessing the page from google search result, because instead of showing the correct page, it shows the front page of the Japanese version. To solve this annoying redirection, add subdomain "us." in front of the url of lifehacker.com or gizmodo.com page.

For example, if the original URL is:
http://lifehacker.com/5799574/top-10-fixes-for-the-webs-most-annoying-problems

it will become:
http://us.lifehacker.com/5799574/top-10-fixes-for-the-webs-most-annoying-problems

Once the us.lifehacker.com is loaded, it will stay in the English version although we omit the subdomain "us." until we delete the cookies.

That's all :)

Update 2013/4/30:
There are few changes at lifehacker and gizmodo, so that this tips is no longer working. You can check the new changes here:
http://lifehacker.com/welcome-to-the-new-lifehacker-472650381
http://gizmodo.com/welcome-to-the-new-gizmodo-481330297

That's all :)

Monday, February 28, 2011

How to hibernate instead of standby when closing the lid of macbook(pro|air)

Sometimes, we probably prefer to hibernate my mbp instead of make it standby when closing the lid. I am wondering why there is no GUI setting for this simple matter. The only way that I know is by using command pmset from the terminal window as follow:

(1) To enable the hibernate:
$ sudo pmset -a hibernatemode 5

(2) To switch back (standby):
$ sudo pmset -a hibernatemode 0

Or for more detail of pmset command, read the manual (man pmset).

That's all :)

Saturday, February 26, 2011

How to show full path in Mac OSX Finder window title bar

To show the complete path in the Finder title bar of Mac OSX (maybe only for OSX 10.5 and newer), type the following two commands in terminal:

$ defaults write com.apple.finder _FXShowPosixPathInTitle -bool YES
$ killall Finder

And to reverse:

$ defaults write com.apple.finder _FXShowPosixPathInTitle -bool NO
$ killall Finder

That's all :)

Friday, January 14, 2011

How to add shortcut to sidebar OSX

To add shortcut to the finder's sidebar on OSX:
  1. drag and drop the folder or,
  2. select the folder, press: Command+T

That's all :)

Friday, December 24, 2010

Windows could not start because the following file is missing or corrupt \windows\SYSTEM32\CONFIG\SYSTEM

Three days ago, a friend asked me to recover his laptop (winXP) from the following error which always appeared during booting:
Windows could not start because the following file is missing or corrupt \windows\SYSTEM32\CONFIG\SYSTEM

The solution is straightforward from Microsoft website (http://support.microsoft.com/kb/307545). In brief:
The first step is to gain access to windows OS by replacing the broken registry file with the default registry file (windows installation CD is required). The second step is to copy the latest system restore registry file (hopefully your system restore is enabled) to replace the default registry file.

To be more detail, those steps are done as follow:

  1. boot using the WinXP installation CD, select repair

  2. after entering the command prompt, manually copy (overwrite) the registry file (SYSTEM, SOFTWARE, SAM, SECURITY, DEFAULT) from C:\WINDOWS\REPAIR\ to C:\WINDOWS\SYSTEM32\CONFIG\ (you might want to backup the original files)

  3. restart to save mode.

  4. gain access to System Volume Information folder (http://support.microsoft.com/kb/309531/), inside the folder, find sub folder with name _restore {GUID}\RPx\snapshot. For example: C:\System Volume Information\_restore{D86480E3-73EF-47BC-A0EB-A81BE6EE3ED8}\RP1\Snapshot

  5. copy the following files from the Snapshot folder to any other folders: _REGISTRY_USER_.DEFAULT, _REGISTRY_MACHINE_SECURITY, _REGISTRY_MACHINE_SOFTWARE, _REGISTRY_MACHINE_SYSTEM, _REGISTRY_MACHINE_SAM. Rename each of the files to DEFAULT, SECURITY, SOFTWARE, SYSTEM, SAM, respectively.

  6. boot using WinXP installation CD, select repair

  7. after entering the command prompt, manually copy (overwrite) the file from step (5) to C:\WINDOWS\SYSTEM32\CONFIG\

  8. restart.

  9. finish, or according to the microsoft website, you should try to restore the setting to previous restore point (Start, All Programs, Accessories, System Tools, System Restore, Restore to a previous restore point).


That's all :)

Tuesday, June 29, 2010

Colored ls in MacOSX terminal

To have a colored ls in MacOSX terminal:
  1. edit or create ~/.profile
  2. add line:
    export CLICOLOR=1

That's all :)