Wednesday, June 24, 2015

My very first XBMC addon 
Hi guys, please check out my very first XBMC add on. It plays all the best movies from the online source Please visit my github and download the source code and install into your xbmc server. If you don't know how to install, just drop me an email I will let you know.

I have tested with XBMC on Ubuntu desktop and on my tiny raspberry pi. Both work fine. 
It's very initial version, still very stupid so that please give it a try and let me know your opinions. I'd be very happy to improve it to serve you more. 

Saturday, March 14, 2015

Replace your Kindle 3 screen in 5 minutes

You have been too busy to read for a few months. Your kindle has been left in your cabinet for long time. And one morning, suddenly you feel like missing your reading hobby, searching for your Kindle 3 and found out that your reader's screen is somehow spoiled, few lines on top are totally white. Maybe you still can read but it's very disgusting. Yes, this is exactly my case.

Have you tried hard reset? Keep volume "+" button and slide the power key. Do you think that it's because of empty battery, try to charge it few times. Have it solved the issue. Nope? You may think of writing to Amazon to complain, if your Kindle is still under warranty then definitely they will send you a replacement but if not, an email can't help you.
What to do with your reader now? If you are fed of it, then just close your browser tab, open a new one and type, a new baby is on the way to your house. But if you have been in love with yours, just don't want to throw it away then please continue reading you may find interesting and worth a try.

I did some google search and found out that there are quite a few people out there looking for ways to keep. Many have decided to go with a new chic, new and shiny, but quite many still want to give a try to keep their loves alive. Which group are you belong to?

If you are in the second, let me know. We are starting right away. Your reader's life is few clicks + 5 minutes in a Saturday morning away from you.

Let's go to and type kindle 3 screen, you may find quite a few sellers from China and Hong Kong shipping these all around the world. Choose one that you find it's a good deal. I purchase mine at round 30 bucks(including shipping cost). Please make sure that the screen is for Kindle 3, serial number is D00901 as photo below

 Ok, Done. Your baby will arrive in a week or two, properly packed and light as a piece of paper

If you are too itchy, just start right away but if you are still busy with many other things, why not wait until a beautiful Saturday morning to play with this. Enjoy and cup of coffee, slowly open the box, get a screw driver and sit down to your table and enjoy it. It will not take you more than 10minutes, but I have no idea if you have never used a screw driver :)

Firstly, use something slim to lift out the back cover, a small knife should be ok if you don't have professional tool box. If you don't have anything, why not just use your daddy finger's nail. I bet it's quite easy.

Secondly, use a screw driver, take out the battery.

 Lift all the screws in the bottom and the edges,

Ok, you are almost there already. Many guys out there try to lift out the whole circuit board. But it's quite tough to dis-assemble the bottom part as there are many buttons connected to the case. I suggest you just stop there and gently lift up the board as in picture below.

There will be enough space to lift your screen out and put in the new one. Do remember to do it slowly and gently. Take note about the data cable too.

That's all about it. Put the board back down, put back all screws perfectly. It's recommended that you take picture before you get screws out so that you won't get confused how to put them back. Put back the battery, fix it up and tin tin tin tin ...... Your baby is here, fresh and close.

Is there any coffee left in the cup? Why not that throw everythings there, go to garden, enjoy morning sun light with an interesting book. Enjoy your reading!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Sunday, August 24, 2014

OpenCV 3 Alpha version.

So finally, after 5 years of OpenCV2, Version 3 is expected to come out around festive season this year. Much improvement of performance by GPU and IPP is highlighted together with various new functions: pose estimation and TLD are major points that we can expect.

For the time being, I will try to figure out these new points and share with you. I will mainly focus on computation performance improvement. Please stay tune.

Tuesday, July 15, 2014

Live Streaming Box with 50 bucks

(Relax a bit-watch World Cup)

If World Cup subscription fee is ridiculously expensive as mine (100+ bucks), wondering why we need to pay that much money for an event that should be free to everyone- (and still have to watch commercial contents), you may consider this solution.

All you need is a Raspberry Pi board(40+ bucks), a good network bandwidth and some Linux skills to port related software to the board. It works insanely well for me.
You can expect h.264 stream at 1.5Mbps, HD size at 30fps. So far I haven't encountered any lagging and disruption. Really enjoy watching it freely.

For Vietnamese, there is a very good add-on to watch quite a few Vietnamese channels(VTV, SCTV, VOV,...), it really works as your smart TV. Thanks to all the geeks out there spending time developing this brilliant application.

You have your Raspberry Pi board ready. Please following this guideline to install raspbmc to the board.

After that, follow this to install sopcast add-on. So simple, right? If you face any issues, drop me an email.

Monday, July 14, 2014

OpenCV on Carma - My First Example.

Let's start OpenCV-GPU with a sample application. Source code is listed as below:

 #include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/gpu/gpu.hpp>
using namespace cv;
using namespace std;

int main (int argc, char* argv[])

        Mat src_host;(Size(640,480),CV_8UC3);
        Mat dst_host;(Size(640,480),CV_8UC1);
        gpu::GpuMat  src(Size(640,480),CV_8UC3);
        gpu::GpuMat  tmp(Size(640,480),CV_8UC1);
        gpu::GpuMat  dst(Size(640,480),CV_8UC1);
        VideoCapture capture(0);

                capture >>src_host;

                if(waitKey(5)==27) break;
        return 0;
There are few things you need to take care:
  • Define necessary buffer in GPU side, it's simply done by: 
    • gpu::GpuMat  src(Size(640,480),CV_8UC3);
  • After you capture image from webcam, you need to copy this data from cpu side to gpu side, by:
    •  src.upload(src_host);
  • Process in GPU by using all GPU functions, in this example, they are color conversion and Canny filter
    •    gpu::cvtColor(src,tmp,CV_BGR2GRAY);
    •    gpu::Canny(tmp,dst,50,100);
  • After GPU completes processing, you need to copy processed image back to CPU side in order to display or save to file.
Compile the example(you can cross compile or compile using compiler on board):
arm-linux-gnueabi-g++ -I/usr/local/include src/cuda_sample.cpp -g -o cuda_sample -L/usr/local/cuda/lib -lcudart -lnpp -lcublas -lcufft -L/usr/local/cuda_opencv_libs/ -lopencv_gpu -lopencv_highgui -lopencv_calib3d -lopencv_core
 Here we go, our first example is ready to run. You can see something like this when you run the sample.

You may encounter long delay at the beginning, it's because system needs time to initialize GPU. So that to compare performance of CPU and GPU functions, you just ignore this phase, run the function many times(put inside a loop) and compare average processing time.

Sunday, July 13, 2014

OpenCV On Carma Board.

Let's try somethings more interesting with our new toy Carma. Image processing is good example how your GPU monster can help to accelerate your application compared to pure CPU solution.

To start quickly, OpenCV maybe a good solution( Actually implementing function by yourselves should be more optimized - but let's play with this in the next topic). In this topic I assume that you are familiar with OpenCV, at least in your PC environment. If you aren't, please spend sometimes reading these tutorial firstly to get some ideas what OpenCV is and how to use it:
Ok, let's start our journey.

  • Prepare our Carma Board for OpenCV
    •  Install required third party libraries into your Carma board. You can simply use sudo apt-get to install with the network connected. 
    • Install essential tools for buidling OpenCV.
    sudo apt-get install build-essential cmake pkg-config
    • Install required Image I/O libraries.
    sudo apt-get install libjpeg62-dev libtiff4-dev libjasper-dev
    •   Install UI libraries for highgui
    sudo apt-get install libgtk2.0-dev libqt4-dev

    • Install required video input/output libraries.
    sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
    • After installing all required libraries for OpenCV into the Carma board, you need to copy all these library files into your development PC, the location should be in: /usr/arm-linux-gnueabi/lib/ and /usr/lib/arm-linux-gnueabi/. Dont miss this step, otherwise you may face troubles when you build OpenCV later.
  • OpenCV Cross Compilation.
    • Download OpenCV latest source code from the following location
    • Extract the source code package: tar -xvf opencv-2.4.9.tar.gz
    •  Go to opencv-2.4.9, make a directory call carma_build, go to this folder.
    • Edit a config file named with the following content:
    •  Depend on your third party libraries, you can modify accordingly. However, please note few important points: cross compiler version, arm-linux configuration file, cuda toolkit path and cmake toolchain file.
    • After this,  just simply execute: make
    • Copy all libopencv-*.so downto your Carma board, normally into /usr/local/lib
    • Ok, now you can start using OpenCV in your Carma board with GPU enabled.
    • You can test your environment by testing all default test-cases, copy "bin" folder downto your board, execute opencv_perf_gpu

Wednesday, July 9, 2014

Image Processing Applications with NVIDIA Carma Dev Kit

I got my Carma board last year, but was to busy to touch. Recently, I have sometimes playing with this, and have a lot of fun to share with you guys.

NVIDIA released this development kit (with middle end tablet CPU but quite powerful GPU) targeting HPC applications for server stack. However, I want to use it to accelerate my Image Processing Application and it has done pretty well. I will post few topics from development environment setting up, OpenCV installation and some simple image processing applications with performance benchmarking information.

And here are the specification information:
  • Tegra3 ARM A9 CPU( Dual core)
  • Quadro 1000M GPU (96 CUDA Cores)
  • 2GB system RAM, 2GB GPU RAM
  • 4x PCIe Gen1 CPU to GPU link
  • 1000Base-T networking support
  • HDMI and Display ports
  • 2USB 2.0 ports
  • 1 SATA port. It's highly recommend that you prepare a SSD disk since default storage may not be enough for your image processing applications.
About software, Carma support:
  • Ubuntu version 11.04 is pre-installed.
  • Cuda version 4.2(So sad that it doesn't support OpenCL)
  • gcc-4.5-arm-linux-gnueabi
For details, you may look into SECO website.

Cross compile environment setting up.

  • Start with a clean installation of Ubuntu Desktop
    • You are recommended to have  a X86_64 Linux development machine, running Ubuntu 11.04, with GCC version 4.5.X.Since it will be synchronized with Ubuntu on Carma board and you won't face much trouble with library version conflicts later on. However, it still works well in my Ubuntu 12.04 laptop.
    • Since Ubuntu 11.04 is quite an outdated version,  and not supported by Ubuntu anymore you may need to go to this site to download:
  • In order to install applications downto your board, please update your repositories  in your Carma board also. In your Carma board terminal, execute following commands:
    • Back up your sources.list file
      sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup
    • Add following line into sources.list file
      deb natty main restricted universe multiverse
      deb natty-updates main restricted universe multiverse
      deb natty-security main restricted universe multiverse  
    •  From now on, you can use your "sudo apt-get" in Carma board. (It will be very useful when you want to install OpenCV into the board.)
  • Installing ARM compiler
    • A gcc ARM cross compiler needs to be installed. This compiler will be invoked by nvcc as part of the cross compilation. Currently, only gcc 4.5.X is supported.
    • The following command, when executed on the development machine, can be used to obtain a gcc 4.5.X cross compiler for ARM:
      • sudo apt-get install gcc-4.5-arm-linux-gnueabi g++-4.5-arm-linux-gnueabi
      • The default cross compiler files folders will be/usr/bin/arm-linux-gnueabi-gcc and /usr/bin/arm-linux-gnueabi-g++.
  • Installing the CUDA toolkit 
    • Download Cuda Toolkit from SECO website. Once you have dow nloaded it, just simply execute the .run file on your Ubuntu machine. Follow the instructions given by the installer.
  • Adding Libraries on the CARMA machine If you need to use other libraries for ARM, you will also need to copy the libraries and corresponding header files from CARMA to your development PC. Copy all libraries from /usr/lib/arm-linux-gnueabi/ and /usrarm-linux-gnueabi/ from your Carma board to coresponding folders in your Ubuntu PC.
  •  That's it. You have done the development environment and now it's time to try some simple application to have some fun 

Your very first Cuda sample on Carma board. 

Let's start with some very simple and stupid application, multiply a number in GPU domain and get back to CPU and print out:
Edit a file call "", put in the following source code:

#include "stdio.h"

__global__ void kernel(int w, float *d_n)
*d_n *= 1.02f;

int main(){
float n = 1.0f, *d_n;
float n_ref = 1.0f;
int i;
cudaMalloc((void **)&d_n, sizeof(float));
for(i = 1; i <= 10; i++)
cudaMemcpy(d_n, &n, sizeof(float), cudaMemcpyHostToDevice);
kernel <<< 1, 1 >>> (i, d_n);
cudaMemcpy(&n, d_n, sizeof(float), cudaMemcpyDeviceToHost);
printf("%d\t\t%42.41f\t%42.41f\n", i, n,n_ref*=1.02f);
return 1;
And edit a Makefile with following content:

# Makefile for Carma cross-compile #
all : test_cuda


NVCC=$(CUDA_HOME)/bin/nvcc -target-cpu-arch ARM --compiler-bindir /usr/bin/arm-linux-gnueabi-gcc-4.5 -m32

test_cuda :

$(NVCC) -o test_cuda

rm test_cuda

Well done, copy you binary file to Carma board, hit the keyboard button and enjoy your fun. From now, you can play with you new toy.