Thursday, April 11, 2013

Force opencv image window to always on top

Recently I needed to make an opencv(Open Source Computer Vision) image window always on top of any other windows. I followed the answers in Stackoverflow but couldn't make it really work. The solution proposed by it was to use setWindowPos API to make the image window TOPMOST.

I have to say today is my lucky day. I finally found if we set the parent of that image window to TOPMOST, then it works like a charm.
        HWND cvHwnd = (HWND )cvGetWindowHandle("window");
        HWND cvParent = ::GetParent(cvHwnd);
        ::ShowWindow(cvParent, SW_MINIMIZE);
        ::ShowWindow(cvParent, SW_RESTORE);
        ::SetWindowPos(cvParent, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);

Monday, March 23, 2009

[Wireless] Three kingdoms in China mobile market

If you recently watched the movie "Red Cliff" directed by John Woo, you would know it is a story about a battle of the Three Kingdoms period in the history of China. Although this period is relatively short, it has been greatly romanticised in the cultures of China. Any Chinese people knows a bunch of legends of those three kingdoms (Cao Wei, Shu Han, and Dong Wu). By coincidence, currently there are three big mobile communication companies in China, they are China Mobile, China Unicom and China Telcom. Those three companies compete one another for the China mobile market, which is very similar to those three kingdoms combated for the territory.

Previously, only China Mobile and China Unicom own the operating license for 2G mobile systems in China. At that time, although China Unicom was considered as a competitor of China Mobile, it was still too weak to jeopardize China Mobile's dictatorial control of the mobile market. And China Telecom only has the largest wiring system and has been wishing for the mobile license for a very long time. In order to expediate the development of 3G systems, and to change the unbalanced competition pattern as well, in Jan 2009 China's Ministry of Industry and Information Technology issued 3G licenses to those three companies. China Mobile got TD-SCDMA, China Unicom will develop WCDMA and China Telecom has the grant for CDMA2000.

Technically, China Unicom benefits a lot from 3G license since WCDMA is the most mature system; China Telecom also got they desired - the mobile license; and China Mobile will face a fiercer competition from the other two companies since TD-SCDMA is still "weaker" in the view of development.

However, you have to take good with bad. China Unicom needs to spend a longer time and more efforts to integrate the WCDMA system into its own development. China Telecom lacks of mobile operating experience and cdma2000 has a dim future in 3G long term evolution. Although TD-SCDMA has no technology advantage, China Mobile has the largest 2G system in the world and has accumulated abundant operating experiences over years.

It seems that 3 licenses for 3G is a good choice for competition pattern change. However, my question is, why 3? From the view of history, three kingdoms period is one of the most "bloody" period in China. In the pointview of market, competition of two is the most stable pattern. Because when you have two opponents, you may select one as your ally to combat the strongest. However, this confederation may be variant along with time. When the strongest becomes weak, it may ally with another opponent to conterwork you. This will fluctuate the market and may not be good for the whole industry's developing. Just my two cents. :-)

Saturday, November 1, 2008

[Software] Install VMware Tools on Fedora 9

I bought a new PC with Window XP operating system. Like what I did on my old computer, I decided to install VMware workstation on Windows XP since I also need Linux/Unix environment for software development. I downloaded Fedora 9 ISO image from and used it to build the linux guest OS on the VMware workstation. Everything for Fedora 9 installation went smoothly. After that, I began to install VMware Tools as usual (you can find a guide from VMware):

1) Select "Install VMware tools" on VMware, it will mount VMware Tools to "/media/VMware Tools" of the guest Linux OS,
2) start a terminal, type in "su", enter the root password,
3) rpm -Uhv /media/VMware\ Tools/VMware*.rpm, install the VMware Tools using RPM (or you can use extract the gz file using tar). Note, there's a space between VMware and Tools, so you need a backslash,
4) after installation, you should have a script file installed: /usr/bin/
5) run, it will ask you several questions, such as "which compile command to use", "kernel headers directory" etc.

However, when it goes to "kernel headers directory", it complained that the default directory /usr/src/include/linux does not exist or the kernel headers are not matched to the kernel you are running. In order to solve this problem, start a new terminal and run "rpm -qal | grep kernel", it will tell you what kernels have been installed on your guest OS and where they are located (for my case, it's under /lib/modules/

After changing the directory, it still doesn't work and continues complaining "mismatch" messages. The reason is that I upgraded the kernel but didn't reboot it. So the running kernel and the header files installed are not "synchronized" yet. Restart the OS and re-run, now it's ok.

The last step of vmware configure is to set the dispaly resolution. After that, you need to restart X as it suggests. Unfortunately, another problem emerged: the mouse position messed up. I clicked the menu but it's not selected. I googled this problem, and found it's a xorg-x11-drv-vmmouse driver bug for Fedora 9 only. A work around is given in this link:

Edit /etc/X11/xorg.conf in the guest machine. Create the section if necessary:

Section "ServerFlags"
Option "NoAutoAddDevices"

Restart X, everything goes well! Now you can enjoy the features provided by VMware, such as copy&paste between host and guest OSs, share files and folders etc.

Monday, August 25, 2008

Embedded C programming - for beginners (1)

Here the beginner is me. :-) If you never touched embedded C programming before and want to learn it, join me. I have some experiences to share with you. We can teach and learn ourselves.

Embedded programming is always hardware related. You may at least need to buy a develop kit or emulator. The price is not that cheap (usually costs you several hundred bucks, with those bucks you can send roses to your GF everyday for two months). Can we save those bucks and still learn the fundamentals of embedded C programming? Congratualtion, you got it!

Thanks to Keil - An ARM company. If you never heared about Keil, congratulation again! you are the beginner and this article is right for you! Keil provides a great Evaluation Software supporting different paltforms but with very few limitations. It includes the assembler, compiler, linker, debugger, and IDE. Everything you need for embedded C learning is here. How to get it? Go to this webpage of Keil ( and you can get it free (you just need to fill out a simple form)!

Ok, next I'll show you how to write your first embedded C program.

Sunday, July 6, 2008

Run Javascript under Windows using Mozilla's interpreter - SpiderMonkey

Javascript is widely used in Web programming. Microsoft's Internet Explorer and Mozilla's Firefox both include its Javascript interpreter in the browsers. However, they also limit your capability of running Javascript in a web-only environment.

The good news is, Mozilla's interpreter was released as an open source. You can find it from It has two versions, one is written in C and is called SpiderMonkey. The other is written in Java and called Rhino.

Today, I installed SpiderMonkey on a windows xp computer. The installation is very simple:
1) Install Mozilla Developer Center - MozillaBuild
2) Go to SpiderMonkey's website to get the latestest version and build it under MozillaBuild.

After installation, you will get the executable interpreter js.exe in a directory whose name depends on the system you're building on (you can find this direcotry under mozilla/js/src/ with a suffix .OBJ).

If you are not accustomed to the MozillaBuild environment (unix-like) and is comfortable with Windows/Dos, you can modify the system environment by adding the path of js.exe into the PATH variable (right click "My computer" in Windows Explorer, and then select Advanced -> Environment Variables). Then under the DOS prompt environment (in Windows, Start -> Run -> cmd) , you can use "js file.js" to run your javascripts.