How to make linux kernel to 2.6.28.4

Step 1:
$apt-get install build-essential kernel-package
$apt-get install make
$apt-get install gcc
Step2:
$wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.28.4.tar.gz
$tar zxvf linux-2.6.28.4.tar.gz

Step3:
$make defconfig
$make -j2
$make modules
$make modules_install
$make install

Step4:
$cd /boot/grub
$vim ./menu.lst
title       KiDiWi GNU/Linux, kernel 
root (hd0,0)
kernel /boot/vmlinuz-2.6.28.4 root=/dev/sda1 ro
quiet

How to build linux kernel on KiDoWi Linux

1. $make defconfig
2. $make -j2
3. $make install
4. $make modules_install --> Create module library in it

How to build chromium OS on Ubuntu 9.04

Ref:

1. Download the Chromium depot tools
$svn co http://src.chromium.org/svn/trunk/tools/depot_tools
$export PATH=`pwd`/depot_tools:"$PATH"

2. Download the gitpackage

$apt-get install git

3. Get a copy of the Chromium OS repository

$mkdir [chromiumos]
$cd [chromiumos]
$gclient config http://src.chromium.org/git/chromiumos.git
$gclient sync


Linux Driver : Hello World (part 1)

Ref:

http://www.tldp.org/LDP/lkmpg/2.6/html/x121.html


1. Coding program : hello1.c


/*

* hello1.c - The simplest kernel module.

*/

#include <linux/module.h> /* Needed by all modules */

#include <linux/kernel.h> /* Needed for KERN_INFO */


int init_module(void)

{

printk(KERN_INFO "Hello world - GW1.\n");


/*

* A non 0 return means init_module failed; module can't be loaded.

*/

return 0;

}


void cleanup_module(void)

{

printk(KERN_INFO "Goodbye world - GW1.\n");

}


2. Coding program : Makefile


obj-m += hello1.o


all:

make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules


clean:

make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean


3. Fixed try


$make

$insmod hello1.ko

$rmmod hello1

$dmesg






Linux Driver : /proc file system (Part1)

Ref:

http://www.wangcong.org/articles/lkmpg_cn/index.htm#AEN602



1. chardev.c

/*

* chardev.c: Creates a read-only char device that says how many times

* you've read from the dev file

*/


#include <linux/kernel.h>

#include <linux/module.h>

#include <linux/fs.h>

#include <asm/uaccess.h> /* for put_user */


/*

* Prototypes - this would normally go in a .h file

*/

int init_module(void);

void cleanup_module(void);

static int device_open(struct inode *, struct file *);

static int device_release(struct inode *, struct file *);

static ssize_t device_read(struct file *, char *, size_t, loff_t *);

static ssize_t device_write(struct file *, const char *, size_t, loff_t *);


#define SUCCESS 0

#define DEVICE_NAME "gw-chardev" /* Dev name as it appears in /proc/devices */

#define BUF_LEN 80 /* Max length of the message from the device */


/*

* Global variables are declared as static, so are global within the file.

*/


static int Major; /* Major number assigned to our device driver */

static int Device_Open = 0; /* Is device open?

* Used to prevent multiple access to device */

static char msg[BUF_LEN]; /* The msg the device will give when asked */

static char *msg_Ptr;


static struct file_operations fops = {

.read = device_read,

.write = device_write,

.open = device_open,

.release = device_release

};


/*

* This function is called when the module is loaded

*/

int init_module(void)

{

Major = register_chrdev(0, DEVICE_NAME, &fops);


if (Major < 0) {

printk(KERN_ALERT "Registering char device failed with %d\n", Major);

return Major;

}


printk(KERN_INFO "I was assigned major number %d. To talk to\n", Major);

printk(KERN_INFO "the driver, create a dev file with\n");

printk(KERN_INFO "'mknod /dev/%s c %d 0'.\n", DEVICE_NAME, Major);

printk(KERN_INFO "Try various minor numbers. Try to cat and echo to\n");

printk(KERN_INFO "the device file.\n");

printk(KERN_INFO "Remove the device file and module when done.\n");


return SUCCESS;

}


/*

* This function is called when the module is unloaded

*/

void cleanup_module(void)

{

unregister_chrdev(Major, DEVICE_NAME);

printk(KERN_ALERT "cleanup_module - GW\n");

}


/*

* Methods

*/


/*

* Called when a process tries to open the device file, like

* "cat /dev/mycharfile"

*/

static int device_open(struct inode *inode, struct file *file)

{

static int counter = 0;


if (Device_Open)

return -EBUSY;


Device_Open++;

sprintf(msg, "I already told you %d times Hello world!\n", counter++);

msg_Ptr = msg;

try_module_get(THIS_MODULE);

return SUCCESS;

}


/*

* Called when a process closes the device file.

*/

static int device_release(struct inode *inode, struct file *file)

{

Device_Open--; /* We're now ready for our next caller */


/*

* Decrement the usage count, or else once you opened the file, you'll

* never get get rid of the module.

*/

module_put(THIS_MODULE);


return 0;

}


/*

* Called when a process, which already opened the dev file, attempts to

* read from it.

*/

static ssize_t device_read(struct file *filp, /* see include/linux/fs.h */

char *buffer, /* buffer to fill with data */

size_t length, /* length of the buffer */

loff_t * offset)

{

/*

* Number of bytes actually written to the buffer

*/

int bytes_read = 0;


/*

* If we're at the end of the message,

* return 0 signifying end of file

*/

if (*msg_Ptr == 0)

return 0;


/*

* Actually put the data into the buffer

*/

while (length && *msg_Ptr) {


/*

* The buffer is in the user data segment, not the kernel

* segment so "*" assignment won't work. We have to use

* put_user which copies data from the kernel data segment to

* the user data segment.

*/

put_user(*(msg_Ptr++), buffer++);

length--;

bytes_read++;

}


/*

* Most read functions return the number of bytes put into the buffer

*/

return bytes_read;

}


/*

* Called when a process writes to dev file: echo "hi" > /dev/hello

*/

static ssize_t

device_write(struct file *filp, const char *buff, size_t len, loff_t * off)

{

static int w_count = 0;

printk(KERN_INFO "You write message %d times.\n", w_count++);

return -EINVAL;

}


2. Makefile


obj-m += chardev.o

KERNELDIR := /lib/modules/$(shell uname -r)/build

PWD := $(shell pwd)


default:

$(MAKE) -C $(KERNELDIR) M=$(PWD) modules

clean:

$(RM) *.o *.mod.c *.ko *.symvers


3. Fixed try


$make


#掛載driver module

$insmod chardev.ko


#建立裝置檔案節點

# mknod 裝置檔名 [bcp] [Major] [Minor]

#選項與參數:

#裝置種類:

# b :設定裝置名稱成為一個周邊儲存設備檔案,例如硬碟等;

# c :設定裝置名稱成為一個周邊輸入設備檔案,例如滑鼠/鍵盤等;

# p :設定裝置名稱成為一個 FIFO 檔案;


# Major :主要裝置代碼;

# Minor :次要裝置代碼;

$mknod /dev/gw-chardev c 250 0


#Testing1 - write message

$echo "Hello World" > /dev/gw-chardev


#Testing2 - read message

$cat /dev/gw-chardev


#卸載 driver module

$rmmod chardev



Linux Driver : Hello World (part 2)

Ref:


1. Coding program : hello2.c


/*

* hello2.c - Demonstrating the module_init() and module_exit() macros.

* This is preferred over using init_module() and cleanup_module().

*/

#include <linux/module.h> /* Needed by all modules */

#include <linux/kernel.h> /* Needed for KERN_INFO */

#include <linux/init.h> /* Needed for the macros */


static int __init hello2_init(void)

{

printk(KERN_INFO "Hello, world - GW2\n");

return 0;

}


static void __exit hello2_exit(void)

{

printk(KERN_INFO "Goodbye, world - GW2\n");

}


module_init(hello2_init);

module_exit(hello2_exit);


2. Makefile

obj-m += hello2.o

all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

3. Fixed try

$make
$insmod hello2.ko
$rmmod hello2
$dmesg


Enable Flash support for Google Chrome Dev Build on Ubuntu 9.04

喜歡嘗鮮的網路宅宅應該多多少少都知道
Google Chrome 有 Debian/Ubuntu 的開發中版本可以安裝
http://dev.chromium.org/getting-involved/dev-channel
目前官方釋出開發中版本的最新版已經可以使用中文輸入了
不過一直都沒有看到有 Flash 的支援
剛剛看到一篇 Flash player in Google Chrome for Linux 有提到解決方法
於是在 Ubuntu 9.04上面嘗試了一下

1. 首先要找到 libflashplayer.so 的位置
$ locate libflashplayer.so
/usr/lib/adobe-flashplugin/libflashplayer.so
2. 在 Google Chrome 的目錄下建立一個 symbolic link
$ cd /opt/google/chrome/
$ sudo ln -s /usr/lib/adobe-flashplugin/libflashplayer.so .
3. 最後啟動 Google Chrome 時要多加一個參數
$ google-chrome --enable-plugins
還真的可以用耶~ :D
放了一張 YouTube 上的日蝕影片來當真象~ ^w^

Remove error message in udev 141

1. Download source code "141"
http://www.icewalkers.com/Linux/Software/527980/udev.html

2. Compiler & Build
$./configure --prefix=/home/gary/udev/setup
$make
$make install

3. Modify


Howto build ntfsprog into xPUD

1. Download ntfsprog-2.0.0.tar

$wget http://sourceforge.net/projects/linux-ntfs/files/NTFS%20Tools%20and%20Library/2.0.0/ntfsprogs-2.0.0.tar.gz/download

$tar xvf ntfsprog-2.0.0.tar

$./configure --prefix=/home/gary/ntfsprog/setup

$make

$make install


「轉載」淺談影像監控之背景建立技術

偵測移動物件是智慧型監控系統內含的一個極為重要的步驟,任何監控系統必定含有此一步驟,相關的研究論文也非常多,目的都在於能夠更準確、快速的偵測到移動物件,其後續的工作如:移動物件的追蹤、辨認…等程序都高度依賴移動物件偵測的準確與否,偵測移動物件的正確性甚至足以決定整個系統的可靠度與精確性,是評估一個監控系統好壞的決定性因素。

以影像處理的方法偵測移動物件主要有兩種方法:1.連續影像相減(Temporal differencing)、2.背景相減法(Background subtraction)。

連續影像相減(Temporal differencing)原理是利用再時間上連續的影像做一對一的像素相減,若是兩者差異為零,就表示此像素不屬於移動物件像素,反之,則此像素為移動物件像素。此法對於環境的改變適應性佳,但是偵測出的移動物件常常會發生內部破碎的情形,如此一來,移動物件的形狀較不完整,對於後續的移動物件追蹤與辨識將無法提供完整的資訊。

背景相減法(Background subtraction)不會有物件內部破碎的問題,原因是背景相減法會先建立一背景模型,再將新影像與此背景模型作一對一的像素亮度值相減,藉此偵測出移動物件像素,最後偵測出完整的物件形狀。

上述兩種方法,又以背景相減法(Background subtraction)是目前較受歡迎的方法,主因除了可以擷取出移動物件的完整形狀,對雜訊也有相對較好的容忍度,也可以減輕移動物件造成的陰影所產生的影響。

在背景相減法的基礎底下,又有很多類的方法,不同的地方在於背景影像產生的方式以及更新的方法,大部分的方法可以約略分為三個種類:1.靜態攝影機之非迭代式的方法(Non-recursive approaches with stationary camera)、2. .靜態攝影機之迭代式的方法(Recursive approaches with stationary camera)、3.非靜態攝影機的背景模型(Panorama background image with non-stationary camera)。

靜態攝影機之非迭代式的方法通常使用滑動視窗(Sliding window)的方法更新背景模型,把一段影像的每個頁面儲存在此滑動視窗中,藉此分析視窗中頁面的每個像素值在時間軸上的變化量,估測出背景影像,使用滑動視窗的原因是保持背景模型在最新的狀態,藉由捨去舊的像素資訊,納入新的像素,然而,若是要處理移動速度較慢的物件時,自然需要長度較長的滑動視窗,也因此對儲存空間的需求將會變得巨大,這個問題可以藉由降低儲存頁面的頻率,也就是每隔數個頁面存入一個頁面,可以獲得部分的改善。幾個常見的靜態攝影機非迭代式的方法,在以下說明:

時間軸上的中間值法(Temporal median),是最常見的建立背景影像的方法,背景影像選取方法為取一段時間內視窗中像素值的中間值,也就是假設真正的背景像素會停留超過視窗長度的一半時間(頁面數),R. Cucchiara et al. [1]把此方法推展到彩色影像;計算出像素中間直的複雜度為 ;B. Shoushtarian et al. [2]比較了三種非迭代式建立背景影像的方法,分別為非前景像素更新法(Selective update using non-foreground pixels)、時間軸上的平均值法(Selective update using temporal averaging)與時間軸上的中間值法(Selective update using temporal median),其中非前景像素更新法(Selective update using non-foreground pixels)就是前景偵測後之背景像素更新為新的背景像素,其餘前景像素部分則用之前的背景像素替代,此法在戶外環境效果會比較不理想,因為戶外光線變化劇烈時,此更新法會使得背景影像無法隨著光線變化更新成符合現狀的背景影像;時間軸上的平均值法(Selective update using temporal averaging)取滑動視窗中的像素值的平均值,以此值作為新的背景像素值,此法會出現錯誤的情形在於存入滑動視窗的像素若包含移動物件,取平均值將會造成新的背景像素失真的現象;時間軸上的中間值法(Selective update using temporal median)取滑動視窗中每個頁面所有像素之中間值,形成新的背景影像,此法再偵測移動物件有較正確的效果,不過在計算出中間值的計算複雜度頗高,且需要的儲存空間也來得大。

非參數式的統計模型(Non-parametric model),不像之前使用單一背景模型的方法,Elgammal et al. [3]利用一段時間內( )的像素值資訊形成一非參數式的機率密度函數 ,公式如下所示:

(1)

函數K是基底函數,選定為高斯函數,若是目前的像素值 不屬於此分佈函數,則此點認定為前景像素,也就是說,當 之機率值小於事先定意義好的門檻值時,此點就會被分類為前景像素;使用機率密度函數的好處是可以處理較複雜的多重背景模式,如反覆搖晃的樹影等等。

靜態攝影機之迭代式的方法不需要儲存一段影像的像素值資訊,而是以迭代的方式在每個頁面進行更新背景模型的各項參數,因此,在很久以前的頁面也影響到目前的背景模型;與非迭帶式的方法比較,迭代式的方法需要較少的儲存空間,但是若是出現誤判的情形,將會導致錯誤持續一段時間。目前的方法採用指數型的權重來去除過去的資訊,並只選用正確的背景像素進行參數的更新估測,具代表性的方法在以下加以說明:

Kalman filter是一種追蹤移動物件很常見的遞迴式方法,目前有許多以Kalman filter為中心建立背景模型的方法,不同處主要為所使用的狀態空間有所差異。最簡單的方法為僅使用亮度值,C. Wren et al. [4]就是其中很經典的例子。

高斯混合(Mixture of Gaussians)(MoG),不同於Kalman filter僅追蹤單一高斯分佈,MoG可以同時追蹤多個高斯分佈,目前MoG是在建立背景模型各種方法裡廣受普遍採用的方法;由於MoG是參數式模型,所以不需另外的空間儲存一段影像資訊,而可以動態的更新背景磨型的各個重要參數,C. Stauffer et al. [5]以K個高斯分佈建立像素點的分佈模型:

(2)

其中 是第 個高斯分佈,平均值為 ,標準差 是第 個高斯分佈的權重值。大致上,K值約在3到之間,K值愈大,所需的記憶容量也愈大。

對於新的像素 ,第一個步驟先找出與其最接近的高斯分佈,判定為相符的條件式為 ,其中T為一個小的正數,相符的高斯分佈模型各個參數的更新方法(3)如下:

(3)

其中 是事先定義好的學習率, 的定義(4)如下所示:

(4)

目前的MoG方法的發展主要為參數對環境敏感度的分析、運算複雜度的改進、背景模型更新速度調整,與將其延伸到全景影像(Panoramic background)。

P. KaewTraKulPong et al. [6]針對[5]提出了改進的方法,利用兩種模式的參數估測方法,系統運作初期利用較花時間但是正確性高的估測(Expected sufficient statistics),可以建立一個穩固的基礎,到達指定的時間後,使用較不花運算時間的估測方式,如此一來可以有效改善[5]的運算時間與增加背景參數的準確度。

I. Haritaoglu et al. [7]使用兩個高斯模型建立背景模型,而隨機變數有三個,分別為訓練期間(Training period)的各個像素的最小值、最大值與亮度值的最大變化量,利用訓練期間建立背景模型分為兩個階段,在前20至40秒利用中間值法抽取出靜態的像素點,因為此一特性,[7]的訓練期間並不需要一段完全靜止的影像序列;另外[7]建立了一張表記錄每個像素的變化情形以決定更新的方法,以像素為基礎的更新方式(Pixel-based update)週期性的更新每個像素以適應環境的緩慢光線變化;另外,有移動物件出現或者原先靜止的背景物件開始移動時,以物件為基礎的更新方法可以針對此部分處理。

非靜態攝影機的背景模型也是目前監控系統的一個大研究方向,把受監控的完整環境建構成一大全景背景模型,全景影像取得方法主要有兩種:1. 使用廣角的攝影機,不過由於價錢昂貴,在遠離焦點的部分影像失真情況嚴重,因此通常比較少被使用。2.使用普通攝影機擷取的影像,經過處理建立全景影像,如此一來,解析度高而且不會發生失真的狀況,這樣的特性可以滿足影像處理的各個應用,S. E. Chen et al. [8]架設固定位置的攝影機,以不同的側擺(Panning)角度拍攝,利用軟體的方法比對建立360度的全景影像。Y. Ren et al. [9]使用空間上的高斯分佈(Spatial distribution of Gaussian)處理攝影機受到風吹的微小震動,其2D轉換公式(5)對像素做座標轉換。

(5)

其中分別為攝影機側擺、仰(俯)的角度,(, )、(,)分別為原始攝影機擷取之影像座標與經過轉換後全景影像座標。

S. Kang et al. [10]使用鑲嵌式的方法(Mosaic technique)將單一角度的影像投射出攝影機各種不同仰(俯)角、側擺方向的影像,運用各種角度的搭配計算出相似的矩陣(Homogeneous matrix),以比對出相對應的位置,此法的好處是無須知道攝影機的內部參數,如焦距等等,缺點則是若攝影機轉動後,擷取到的影像不是事前定義好的連續有交疊的影像時,需要重新更新才能繼續偵測移動物件,解決之道可採用廣角的攝影機,不過也會有影像失真的問題。

後續的步驟如移動物件的追蹤、辨認在一個智慧型監控系統中也是很重要的,舉例來說,智慧型監控系統若內建十大槍擊要犯的各種特徵與資訊,某日若在某台攝影機偵測到的移動物件的特徵經過辨認器的比對發現與某逃犯的特徵非常類似,則追蹤的機制就可以持續追蹤嫌疑犯並於同一時間發出警訊,達到我們預期中理想的智慧型監控系統應該具備的功能。

隨著公共安全的需求日益增加,智慧型監控系統成為目前電腦視覺相關研究領域中非常活躍的一個部分,其中的困難與挑戰雖然很多,不過從事相關研究的人員投注莫大的心力,部分的困難都可以找到很好的解決方案,由於投入的研究學者越來越多,相信與人類一樣聰明而且永不倦怠的智慧型監控系統就在前方的不遠處。

 


 

參考資料
 

[1] R. Cucchiara, C. Grana, M. Piccardi, and A. Prati, “Detecting moving objects, ghosts, and shadows in video streams,” IEEE Transactions on Pattern Analysis and Machine Intelligence, Vol. 25, No. 10, pp. 1337-1342, 2003.

[2] B. Shoushtarian, and H. E. Bez, “A practical adaptive approach for dynamic background subtraction using an invariant colour model and object tracking,” Pattern Recognition Letters, Vol. 26, No. 1 pp. 5-26, 2005.

[3] A. Elgammal, R. Duraiswami, D. Harwood, and L. S. Davis, “Background and foreground modeling using nonparametric kernel density estimation for visual surveillance,” Proc. IEEE, Vol. 90, No. 7, pp. 1151-1163, 2002.

[4] C. R. Wren, A. Azarbayejani, T. Darrell, and A. P. Pentland, “Pfinder: Real-time tracking of the human body,” IEEE Transactions on Pattern Analysis and Machine Intelligence, Vol. 19, No. 7, pp. 780-785, 1997.

[5] C. Stauffer, and W. E. L. Grimson, “Adaptive background mixture models for real-time tracking,” IEEE Computer Society Conference on Computer Vision and Pattern Recognition, Vol. 2, pp. 246-252, 1999.

[6] P. KaewTraKulPong, and R. Bowden, “An improved background mixture model for real-time tracking with shadow detection,” Proc. 2nd European Workshop on Advanced Video Based Surveillance Systems, Vol. 25, 2001.

[7] I. Haritaoglu, D. Harwood, and L. S. Davis, “: Real-time surveillance of people and their activities,” IEEE Transactions on Pattern Analysis and Machine Intelligence, Vol. 22, No. 8, pp. 809-830, 2000.

[8] S. E. Chen, “QuickTime VR – An image based approach to virtual environment navigation,” Proc. SIGGRAPH 95, pp. 29-38, 1995.

[9] Y. Ren, C. S. Chua, and Y. K. Ho, “Statistical background modeling for non-stationary camera,” Pattern Recognition Letters, Vol. 24, pp. 183-196, 2003.

[10] S. Kang, J. Paik, A. Koschan, B. Abidi, and M. A. Abidi, “Real-time video tracking using PTZ cameras,” Proc. of SPIE 6th International Conference on Quality Control by Artificial Vision, Vol. 5132, pp. 103-111, 2003.

虹光大成就-密教灌頂(一)