Monthly Archives: March 2007

对PTgrey的camera编程

对ptgrey的camera进行编程还是比较painful的。想想以前自己写olympus和DH-400的程序也没这么麻烦呀,可能是应用相对简单吧。现在写ptgrey的程序真是头疼,没有人可以请教请教,API的doc也讲的很简单,提供的sample也比较少,有时候基本上全靠自己一个人在那瞎琢磨,简直就在挑战自己的想象力和排列组合能力。经过3天的排练组合,程序终于可以了修改frame rate和video mode了,但是改成任意大小显示还有点问题,不过应该可以将就着用了。

——————————–

下面是细节的东西,可能也就自己会看看:

程序是从timeSliceDemo这个例子该过来的,创建了单文档多视图的程序,还创建了CMultiDocTemplate。修改frame rate和video mode主要是修改startSync()和grabAndCheckSync()这两个函数,

grabAndCheckSync(), 其中grab image主要由两个函数实现flycaptureLockNext和flycaptureConvertImage。flycaptureConvertImage将arbitrary image type转成dst image,转换之前要设置dst image的格式,我试了一下,这里只能是FLYCAPTURE_BGRU,不然该程序就会报错,血的教训呀,2天时间。如果设置成FLYCAPTURE_BGRU的话,在startSync中创建buffer的时候就要为cols * rows * 4,因为4个channel嘛。

startSync(),这个函数里pixelFormat也要设置成FLYCAPTURE_BGRU,如果设置成FLYCAPTURE_MONO8, FLYCAPTURE_422YUV8, FLYCAPTURE_BGR, FLYCAPTURE_RGB8等都会出错。doc里没有说,显然ptgrey连明年版本里的功能都先写进doc里了,可把我害惨了。如果要改变图像的分辨率,要在这两个函数里改,flycaptureGetCustomImagePacketInfo和flycaptureStartLockNextCustomImagePacket。或者不用packet,直接用flycaptureStartLockNext,而不用flycaptureStartLockNextCustomImagePacket,这样就可以设置VIDEO_MODE和FRAME_RATE。比如设置成15Hz,省得server的workload太大。

刚刚配好了Fedora6

今天有点时间,装了一直期待中的Fedora6。这样写AI的hw,做research会方便很多。花了不少时间来配置fedora,整了一会中文输入,又装了Matlab2007,还又配了vncserver。但最为得意的是今天是用grub启动时的菜单来硬盘安装fedora的,感觉很爽。

装的时候,先把第一张cd里的isolinux解压出来,然后装个grub(这个grub不是我专门装的,在装dos硬盘版时产生的,就是因为dos引导不了,才到grub菜单下的),在grub菜单里依次输入

>kernel (sd0, 4)/boot/vmlinuz
>initrd (sd0,4)/boot/initrd.img
>boot

然后就开始装了,爽。

Setup Vncserver on Fedora6

1. configure firewall, add tcp ports 5900:5905

2. vi /etc/sysconfig/vncservers, uncomment the following 2 lines

VNCSERVERS=
VNCSERVERARGS[2]=

3. under the user mode (not root), run "vncserver", this will generate ".nvc" in the home directory. Revise the file "xstartup", and uncomment the following 2 lines

unset SESSION_MANAGER
exec /etc/X11/xinit/xinitrc

4. kill the vncserver by "vncserver -kill :1" and restart it. It would be OK now. Maybe you need to kill the vnc service during the configuration by "killall Xvnc".

http://fedorasolved.org/network-solutions/vncserver-setup/

How to Install Matlab R2006b on linux (Fedora Core 6)

First problem: matlab install requires libXp.so.6 library for xsetup and text-mode install does not work.

Solution: install xorg-x11-deprecated-libs rpm for fedora core from for instance rpmfind.net. This installs libXp.so.6 in /usr/X11R6/lib/libXp.so.6. In order for matlab to be able to find this library, add in directory /etc/ld.so.conf.d a file xorg-x11-deprecated-libs.conf with a single line containing /usr/X11R6/lib. Then run /sbin/ldconfig. After this the installation procedure itself did not report any more problems.

Second problem: When trying to run matlab, it does not want to start. Error message:
/usr/local/Matlab_R2006b/bin/glnx86/MATLAB: error while loading shared libraries: /usr/local/Matlab_R2006b/bin/glnx86/libmwlapack.so: cannot restore segment prot after reloc: Permission denied
Solution: I found the solution on comp.soft-sys.matlab:
chcon -t texrel_shlib_t /usr/local/matlab2006b/bin/glnx86/*.so

Alternative solution is disabling SELinux

http://www.nin.knaw.nl/~heimel/computers/HowToInstallMatlabR2006b.html

配置系统所支持的最大内存

lab买的server内存大了也麻烦,整个8G内存居然camera的驱动就不认了,只好拔掉4根内存条,或者将OS从windows2003server Enterprise转成winxp32bit,这时PTgrey的camera才能用(据说ptgrey做的camera还是最好的)。这些哥们设计驱动的时候估计压根就没有想到有人将这么多个camera同时连到一个server上,就算想到了估计也没有想到会在机子里装这么多内存,可是我们就是这么干的。搞得这一星期来我就不停的重起机子,在server,winxp64,winxp32之间不停的切换,感觉自己在无偿得为ptgrey做测试,到现在提交的问题一个也没有解决,郁闷不是一两星期了。

其中有一个问题得到了confirm,就是现在他们的驱动在32bit的OS下,只能支持小于4G的内存,大于4G的话程序就不能运行。今天那个Paul给我发邮件说,其实不用每次将内存拔下来的,只用这样这样那样就可以了。就是修改系统的BOOT.INI文件,在

[operating systems]
multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft Windows 2003 Server, Enterprise Edition" /fastdetect

后面加个/maxmem=3000就行了,3000指的是3000M内存。如果你的机子装了多OS,这里会有好几条信息,对应着系统启动时不同的选择信息,随便删掉一个,那个对应的系统就没法启动了。有时安装OS时会产生冗余的启动选择项,就可以跑到这里来,删掉就可以了。

RANSAC简单实用

最近经常看到RANSAC的字眼。最先是在使用dynamic silouette作multi-camera calibration的paper里看到的,他们使用改进的RANSAC算法来估计Epipolar Geometry的参数;后来又在vision的课上看到了RANSAC,用来做从两副图像生成paranoma image,后来看到RANSAC主要被用来估计fundamental matrix的7个参数;再后来就在各式各样的matlab工具箱里看到RANSAC。总之一句话,RANSAC是个很简单的但很有效的算法,以后要经常使用些。

“We approached the fitting problem in the opposite way from most previous techniques. Instead of averaging all the measurements and then trying to throw out bad ones, we used the smallest number of measurements to compute a model’s unknown parameters and then evaluated the instantiated model by counting the number of consistent samples.

—- RANSAC: An Historical Perspective, Bob Bolles & Marty Fischler

一个用RANSAC估计Homography的算法为:

How to use manifests and re-distributable assemblies?

http://www.codeguru.com/forum/showthread.php?t=408061


Q: I have an MFC application that runs on my computer, but when I try to run it on another PC I receive an error message that the application failed to initialize and I should re-install it. What should I do?
A: By default, Visual C++ 2005 builds all native C/C++ applications as isolated applications, i.e. self-describing applications that use manifest files to describe their dependencies to VC++ libraries. The problem occurs because your application doesn’t have a manifest, or it has dependencies to assemblies that don’t exist on the target PC, or they have a different version number. Basically you have to do two things to solve the problem:

  • Distribute a manifest resource file along with your application
  • Deploy the re-distributable assemblies that your application depends upon

Q: What is a manifest resource?
A: A manifest resource is an XML file that describes the dependencies of your application. Such dependencies can include the most current version of the Windows common controls, as well as library assemblies, such as MFC, ATL or CRT assemblies.
Your manifest should have the same name as the application and the extension "manifest" and should specify the version number of your assembly (executable or dynamic library), processor architecture, name of the assembly and platform type; a description of your assembly is also recommended.

Code:

<?xml version='1.0' encoding='UTF-8' standalone='yes'?> <assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'> <assemblyIdentity version="1.0.0.0" processorArchitecture="X86" name="CompanyName.ProductName" type="win32" /> <description>Description of your application.</description> </assembly>

Q: How do I specify dependencies?
A: You have to add a element to the XML-based manifest. For instance, if you want your application to use the Windows common controls with the XP-like style, add a dependency to the assembly called "Microsoft.Windows.Common-Controls":

Code:

<?xml version='1.0' encoding='UTF-8' standalone='yes'?> <assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'> <assemblyIdentity version="1.0.0.0" processorArchitecture="X86" name="CompanyName.ProductName" type="win32" /> <description>Description of your application.</description> <dependency> <dependentAssembly> <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="X86" publicKeyToken="6595b64144ccf1df" language="*" /> </dependentAssembly> </dependency> </assembly>

Q: I now understand what a manifest resource is, but what are re-distributable assemblies?
A: These are assemblies provided as dynamic link-libraries that you can deploy with your application, because they are required for the application to work. Assemblies are provided in several configurations, Release and Debug, but you can only re-distribute the release configurations (can be found in Visual Studio 8 installation folder, VC\redist).
Visual C++ 2005 supports a new deployment model for Windows client applications based on isolated applications and side-by-side assemblies. Basically, assemblies can be:

  • shared (they are globally registered in the system, installed in the Global Assembly Cache – GAC folder in Windows – and available to all applications) or
  • side-by-side, described with a manifest, distributed with the application and available only to that application

In Visual C++ 2005, library assemblies (such as MFC, ATL, CRT) have been rebuilt as shared side-by-side assemblies and installed in the native assembly cache, WinSxS folder in Windows. That means they are not globally registered in the system, but are globally available to the applications that specify a dependency with a manifest file.
The target machine where you run your application may already have the required dependencies installed. You can look-up for them in the WinSxS folder. Assemblies are grouped here on categories, each with its own folder. Folder names start with the platform name, followed by Microsoft, category (Windows, VC80, MSXML, Tools), assembly name, a token number, version and additional identifiers. The manifest files for these assemblies are located in the Manifest subfolder of WinSxS and have the same name as the folder of the assembly group they contain information about.
Q: How do I specify dependencies for my application in the manifest file?
A: Suppose your application uses MFC as a shared library, so it has at least a dependency on MFC and one on the C runtime library and C++ runtime library (these two part of the CRT assembly group). In this case your manifest file should look like this:

Code:

<?xml version='1.0' encoding='UTF-8' standalone='yes'?> <assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'> <assemblyIdentity version="1.0.0.0" processorArchitecture="X86" name="CompanyName.ProductName" type="win32" /> <description>Description of your application.</description> <dependency> <dependentAssembly> <assemblyIdentity type='win32' name='Microsoft.VC80.CRT' version='8.0.50727.42' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3b' /> </dependentAssembly> </dependency> <dependency> <dependentAssembly> <assemblyIdentity type='win32' name='Microsoft.VC80.MFC' version='8.0.50727.42' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3b' /> </dependentAssembly> </dependency> </assembly>

If the target machine already has these assemblies and the version info (process architecture, version, public key token) matches, you don’t have to redistribute anything, because your application will be able to use the assemblies from the native assembly cache (WinSxS). Since you cannot be sure of that you should distribute these assemblies with your application (in the same folder with the application). Windows will first looks-up for assemblies in the current folder and then in WinSxS and GAC, so distributing them in the working folder ensures those assemblies are used.
To distribute the correct assemblies after building the application, go to the Visual Studio 8 installation folder in VC\redist and select your target platform folder, i.e. x86 or amd64. Inside, you will see folders for ATL, MFC, CRT, MFCLOC and OPENMP.
The Microsoft.VC80.MFC folder contains 4 DLLS and a manifest file, called Microsoft.VC80.MFC.manifest. You must copy at least MFC80.DLL (or MFC80U.DLL if you built for UNICODE) to your application working folder. You must make sure that the version number of the MFC assembly specified in this manifest matches the one you put in your application manifest and the one of the DLL itself (this should be implicit, but should check that from the file properties, Alt + Enter > Version).
The Microsoft.VC80.CRT contains 3 DLLs and the manifest. Of these three DLLs you need at least msvcr80.dll (C runtime library) and msvcp80.dll (C++ runtime library). The same caution for the version number must be taken.
With all these taken care of, your application should correctly run on any target machine.