2014年1月27日星期一

Emgu CV使用1

最近开始使用Emgu CV,也就是在.NET可以使用的OpenCV,Emgu CV是一个.Net的wrapper。使用从C++转到C#中写OpenCV代码,开始时候还真的很不习惯,以下将简单整理一下最近的一些笔记。

如何将Grayimage转换到Matrix<float>,注意rows cols和height width的关系

Image<Gray, float> img = new Image<Gray, float>("c:\\test_image.jpg");
int rows = img.Height;
int cols = img.Width;
Matrix<float> tmp_matrix= new Matrix<float>(rows, cols);
CvInvoke.cvConvert(img, tmp_matrix);
       

如何显示图

//The name of the window
String win1 = "Test Window";
//Create the window using the specific name
CvInvoke.cvNamedWindow(win1);
Image<Bgr, Byte> img = new Image<Bgr, Byte>("c:\\test_image.jpg");
CvInvoke.cvShowImage(win1, img.Ptr);
//Wait for the key pressing event
CvInvoke.cvWaitKey(1);
//Destory the window
CvInvoke.cvDestroyWindow(win1);
           

如何画一个正方形在图上

Rectangle box = new Rectangle(121, 57, 75, 97);
Image<Bgr, Byte> img = new Image<Bgr, Byte>("c:\\test_image.jpg");
img.Draw(box, new Bgr(Color.DarkOrange), 2);

如何计算一个积分图integral image,在C++中我们可以使用integral(frame, imageIntegral, CV_32F),在C#中可以这样做:

Image<Gray, double> cvImageIntegral = null;
cvImageIntegral = frame.Integral();

如何计算标准差,标准差就是方差的算术平方根,反映组内个体间的离散程度,标准差与期望值之比为标准离差率。

Matrix<float> mat = ... // your input matrix
MCvScalar average = new MCvScalar();
MCvScalar std = new MCvSaclar();
CvInvoke.cvAvgSdv(mat, ref average, ref std, IntPtr.Zero);

2014年1月8日星期三

优化网卡用于machine vision

以下设定最好是使用Intel network chipset的网卡,并确保使用最新的驱动

我们要做的就是optimize bandwidth,improve efficiency

在Win7下选择Local Area Connection → 鼠标右键,点选Properties → 点击Configure → 选择Advanced Tab

1. set interrupt moderation rate to extreme

2. set maximize jumbo packets

3. maximize number of receive buffers

4. disable power saving on the network card