Matrox Imaging Library from(同串口)

Matrox Imaging Library       

分类:            图像采集卡769人阅读评论(2)收藏举报

Matrox Imaging Library

(2006-01-10 15:05:56)
 
------------------------------------------------------------------- Matrox Imaging Library
-------------------------------------------------------------------
The Matrox Imaging Library (MIL) is a high- level 'C' library with an extensive set of optimized functions for image processing (point-to-point, statistics, filtering, morphology and geometric transforms), pattern matching, blob analysis, gauging, OCR, bar and matrix code recognition, and calibration. OEMs and integrators use MIL to accelerate the development of machine vision, medical imaging, and image analysis applications.
Device-independent Matrox Imaging Library (MIL) uses the power of today's Intel CPUs incorporating MMX technology if present or, if your application requires dedicated or additional processing power, MIL works with the Matrox Genesis family of image processors.
To start with MIL:
- Try your target Matrox board:
Use the INTELLICAM interactive program to grab and experiment with your board before compiling the MIL examples.
- Compile and run the MIL examples:
If you are using VISUAL C++, you can use the Matrox Imaging Library
examples group and click on the read.me, Compile examples and Run examples icons. You can also go in the \MIL\EXAMPLES directory. This directory contains everything you need to compile and run the examples. Look in this directory and study the examples to get started quickly with MIL.
If you are using VISUAL C++ and MFC, check the MdispMFC project in the \MIL\EXAMPLES\MFC directory for a quick start with MFC and MIL.
- Check the MIL documentation:
For more information on MIL see the MIL manuals (paper or on-line) and the MIL on-line help. Note that the MIL on-line help can also be used directly inside Visual C++ for context sensitive help on the MIL commands (by pressing Ctrl-F1).
- Context-sensitive help under Microsoft Visual C/C++:
In order to get MIL context-sensitive help using (CTRL-F1) key inside Microsoft Visual C/C++, you need to activate the MIL VC++ Add-In. This Add-In is automatically installed with the Matrox Imaging Library but is not enabled by default. To enable the Matrox MIL VC++ Add-In in Visual C/C++, go in the 'Tools\Customize\Add-ins and Macro files' menu. When MIL context sensitive help is enabled, simply place your cursor on any MIL command in your code and press <CTRL-F1> to get on-line help on that command.
   above  from(http://blog.sina.com.cn/s/blog_54088019010001dy.html)

MIL即为Matrox Imaging Library 的缩写,是加拿大Matrox公司提供的图像处理函数库,主要是针对其公司生产的Matrox系列图像采集卡。我使用的是一个Matrox Morphis四通路图像采集卡,需要使用MIL开发自己的视觉系统。

几个常用的函数如下:

MappAllocDefault();一个默认的配置,Application、System、DigitizerDisplayBuffer都是按照默认的情况进行配置。

MappAlloc();分配一个MIL应用,该函数要在使用其它MIL函数之前使用。

MsysAlloc();配置一个硬件环境,指定使用得板卡类型,使用板卡序号。该函数要在分配buffer,display,digitizer前使用。

MdigAlloc();配置一个抽象的图像采集卡,指定可以使用的采集卡通道数,然后才能使用图像采集卡的函数。

MdispAlloc();配置一个display,把摄像机采集的图像使用该抽象进行显示。

MbufAlloc2d();分配一个2维的内存区。

MbufAllocColor();分配彩色内存区。

MappControl();改变指定的MIL应用的属性。

MsysControl();改变指定的系统的属性。

MdigControl();改变指定的图采卡属性。

MdispControl();改变指定的显示属性

MappInquire();获取指定的应用配置情况

MsysInquire();获取指定的应用系统情况

MdigInquire();获取指定的采集卡配置情况

MdispInquire();获取指定的显示配置情况

MbufInquire();获取指定内存块的配置情况

我使用的Matrox Morphis有四个通路,现在有两个摄像机需要采集数据。黑白摄像机在插在0通路,为CCIR机制;彩色摄像机插在1通路,为PAL机制。

目前最广泛的标准视频是

黑白:RS—170,使用在北美、日本、台湾等地区; CCIR,使用在欧洲、中国等地区。

彩色:NTSC,使用在北美、日本、台湾等地区; PAL,使用在欧洲、中国等地区。

下面分别采集两个摄像机视频数据程序的核心地方

0通路的黑白摄像机

MIL_ID MilApplication ; MIL_ID MilSystem ; MIL_ID MilDigitizer ; MIL_ID MilDisplay ; MIL_ID MilImageDisp ; MIL_ID MilImage ;

MappAlloc(M_DEFAULT,&MilApplication); MsysAlloc(M_SYSTEM_MORPHIS,M_DEV0,M_COMPLETE,&MilSystem); MdigAlloc(MilSystem,M_DEV0,"M_DEFAULT" ,M_DEFAULT,&MilDigitizer); MdispAlloc(MilSystem,M_DEFAULT,"",M_DEFAULT,&MilDisplay); g_BufSizeX = ((unsigned int) MdigInquire( MilDigitizer, M_SIZE_X, M_NULL)); g_BufSizeY = ((unsigned int) MdigInquire( MilDigitizer, M_SIZE_Y, M_NULL)); MbufAlloc2d( MilSystem, ImageWidth, ImageHeight,8+M_UNSIGNED, M_IMAGE+M_GRAB+M_PROC,&MilImage); MbufAlloc2d( MilSystem, ImageWidth, ImageHeight,8+M_UNSIGNED, M_IMAGE+M_DISP,&MilImageDisp); MbufClear( MilImageDisp, 0 );

int n=100;

while(n--) { MdigGrab(MilDigitizer, MilImage8[0]); MbufCopy(MilImage8[0], MilImageDisp);

}

MdispDeselect(MilDisplay, MilImageDisp); MbufFree(MilImageDisp); MbufFree(MilImage); MdispFree(MilDisplay); MdigFree(MilDigitizer); MsysFree(MilSystem); MappFree(MilApplication);

 

1通路的彩色摄像机

MIL_ID ColorMilApplication ; MIL_ID ColorMilSystem ; MIL_ID ColorMilDigitizer ; MIL_ID ColorMilDisplay ; MIL_ID ColorMilImageDisp ; MIL_ID ColorMilImage ;

MappAlloc(M_DEFAULT,&ColorMilApplication); MsysAlloc(M_SYSTEM_MORPHIS,M_DEV0,M_COMPLETE,&ColorMilSystem);

MdigAlloc(ColorMilSystem,M_DEV0, "C:\\Program Files\\Matrox Imaging\\Drivers\\Morphis\\dcf\\PAL.DCF" , M_DEFAULT,&ColorMilDigitizer); MdigChannel(ColorMilDigitizer,M_CH1);//默认的通路为0,改为1通路 MdispAlloc(ColorMilSystem,M_DEFAULT,"",M_DEFAULT,&ColorMilDisplay);

long SizeBand = MdigInquire(ColorMilDigitizer, M_SIZE_BAND, M_NULL); long SizeX = MdigInquire(ColorMilDigitizer, M_SIZE_X, M_NULL); long SizeY = MdigInquire(ColorMilDigitizer, M_SIZE_Y, M_NULL);

MbufAllocColor(ColorMilSystem, SizeBand, SizeX, SizeY, 8L+M_UNSIGNED, M_IMAGE + M_DISP + M_NON_PAGED, &ColorMilImageDisp); MbufClear(ColorMilImageDisp, M_BLACK);MbufAllocColor(ColorMilSystem, SizeBand, SizeX, SizeY, 8L+M_UNSIGNED, M_IMAGE + M_GRAB + M_ON_BOARD, &ColorMilImage);

int k=100; while(k--) { MdigGrab(ColorMilDigitizer, ColorMilImage); MbufCopy(ColorMilImage8[0], ColorMilImageDisp);

}

MbufFree(ColorMilImageDisp); MbufFree(ColorMilImage); MdispFree(ColorMilDisplay); MdigFree(ColorMilDigitizer); MsysFree(ColorMilSystem); MappFree(ColorMilApplication);

今天学习了如何对图像采集卡采集的每一帧图像进行图像处理,主要是从MIL的数据结构中读出图像的具体到像素的数据。SizeX为图像的长度,SizeY为图像的宽度,SizeBand为图像的颜色通道数。从读出的数据分析可以知道,具体图像像素数据是从上到下,从作到右存储的。

unsigned char *data=new unsigned char[SizeX*SizeBand*SizeY]; unsigned char red=0,green=0,blue=0; int k=10;//连续采集的10帧图像 int i,j; while(k--) { MdigGrab(ColorMilDigitizer, ColorMilImage8[0]);

MbufGetColor(ColorMilImage8[0],M_PACKED +M_BGR24,M_ALL_BANDS,data); for(i=0;i<SizeY/2;i++) for(j=0;j<SizeX*SizeBand;j+=SizeBand) { blue=*(data+i*SizeX*SizeBand+j+0); green=*(data+i*SizeX*SizeBand+j+1); red=*(data+i*SizeX*SizeBand+j+2); } MbufPutColor(ColorMilImage8[0],M_PACKED +M_BGR24,M_ALL_BANDS,data);

MbufCopyColor(ColorMilImage8[0],ColorMilImageDisp,M_ALL_BANDS );

} delete data;

 

设定两个线程分别采集两个摄像机的信号,同时主线程控制两个线程的运行。这个双摄像机同步弄了好久,终于调出来了,好高兴啊 大笑

//dialog.cpp

BOOL CTryMulDlg::OnInitDialog() { CDialog::OnInitDialog();

// Add "About..." menu item to system menu.

// IDM_ABOUTBOX must be in the system command range. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000);

CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) {   CString strAboutMenu;   strAboutMenu.LoadString(IDS_ABOUTBOX);   if (!strAboutMenu.IsEmpty())   {    pSysMenu->AppendMenu(MF_SEPARATOR);    pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);   } }

// Set the icon for this dialog.  The framework does this automatically //  when the application's main window is not a dialog SetIcon(m_hIcon, TRUE);   // Set big icon SetIcon(m_hIcon, FALSE);  // Set small icon
// TODO: Add extra initialization here MilCreate();
return TRUE;  // return TRUE  unless you set the focus to a control }

 

extern BOOL work; CWinThread *Thread1,*Thread2; void CTryMulDlg::OnStart() { // TODO: Add your control notification handler code here

work=TRUE;

    Thread1=AfxBeginThread(Thread_One,NULL,THREAD_PRIORITY_IDLE);

Thread2=AfxBeginThread(Thread_Two,NULL,THREAD_PRIORITY_IDLE);
}

void CTryMulDlg::OnPause() { // TODO: Add your control notification handler code here work=FALSE;
}

void CTryMulDlg::OnStop() { // TODO: Add your control notification handler code here if(work) {   AfxMessageBox("请先暂停"); } else {   MilDestroy(); } }

//mul.cpp

#include "stdafx.h" #include "MIL.h" #include "li.h"

MIL_ID   MilApplication       ; MIL_ID   MilSystem            ;

MIL_ID   MilDigitizer         ; MIL_ID   ColorMilDigitizer    ;

MIL_ID   MilDisplay           ; MIL_ID   ColorMilDisplay      ;

MIL_ID   MilImageDisp         ; MIL_ID   ColorMilImageDisp    ;

MIL_ID  MilImage             ; MIL_ID  ColorMilImage        ;

BOOL work=FALSE;

long SizeBand,SizeX,SizeY,ColorSizeBand,ColorSizeX,ColorSizeY;

void MilCreate() { //分配资源 MappAlloc(M_DEFAULT,&MilApplication); MsysAlloc(M_SYSTEM_MORPHIS,M_DEV0,M_COMPLETE,&MilSystem);
MdigAlloc(MilSystem,M_DEV0,"M_DEFAULT" ,M_DEFAULT,&MilDigitizer); MdispAlloc(MilSystem,M_DEFAULT,"",M_DEFAULT,&MilDisplay);
MdigAlloc(MilSystem,M_DEV1,   "C:\\Program Files\\Matrox Imaging\\Drivers\\Morphis\\dcf\\PAL.DCF" ,   M_DEFAULT,&ColorMilDigitizer); MdigChannel(ColorMilDigitizer,M_CH1); MdispAlloc(MilSystem,M_DEFAULT,"",M_DEFAULT,&ColorMilDisplay);

SizeBand = MdigInquire(ColorMilDigitizer, M_SIZE_BAND, M_NULL); SizeX    = MdigInquire(ColorMilDigitizer, M_SIZE_X, M_NULL); SizeY    = MdigInquire(ColorMilDigitizer, M_SIZE_Y, M_NULL); MbufAlloc2d( MilSystem, SizeX, SizeY,   8+M_UNSIGNED,M_IMAGE+M_DISP,&MilImageDisp); MbufClear( MilImageDisp, 0 ); MbufAlloc2d( MilSystem, SizeX, SizeY,   8+M_UNSIGNED,M_IMAGE+M_GRAB+M_PROC,&MilImage);
ColorSizeBand = MdigInquire(ColorMilDigitizer, M_SIZE_BAND, M_NULL); ColorSizeX    = MdigInquire(ColorMilDigitizer, M_SIZE_X, M_NULL); ColorSizeY    = MdigInquire(ColorMilDigitizer, M_SIZE_Y, M_NULL); MbufAllocColor(MilSystem, ColorSizeBand, ColorSizeX, ColorSizeY, 8L+M_UNSIGNED,   M_IMAGE + M_DISP, &ColorMilImageDisp); MbufClear(ColorMilImageDisp, M_BLACK); MbufAllocColor(MilSystem, ColorSizeBand, ColorSizeX, ColorSizeY, 8L+M_UNSIGNED,   M_IMAGE + M_GRAB + M_PROC, &ColorMilImage);
MdispSelectWindow(MilDisplay, MilImageDisp, M_NULL); MdispSelectWindow(ColorMilDisplay, ColorMilImageDisp, M_NULL); }

void MilDestroy() {     //释放资源 MdispDeselect(MilDisplay, MilImageDisp); MdispDeselect(ColorMilDisplay, ColorMilImageDisp);
MbufFree(MilImageDisp); MbufFree(ColorMilImageDisp); MbufFree(MilImage); MbufFree(ColorMilImage); MdispFree(MilDisplay); MdispFree(ColorMilDisplay); MdigFree(MilDigitizer); MdigFree(ColorMilDigitizer);
MsysFree(MilSystem); MappFree(MilApplication); }

UINT Thread_One(LPVOID pParam) {

while(work) {     MdigGrab(MilDigitizer, MilImage);

  MbufCopy(MilImage, MilImageDisp);

}

return 0; }

UINT Thread_Two(LPVOID pParam) {
while(work) {       MdigGrab(ColorMilDigitizer, ColorMilImage);     MbufCopyColor(ColorMilImage,ColorMilImageDisp,M_ALL_BANDS );  }

return 0; }

posted on 2013-04-01 21:23  song2013  阅读(1358)  评论(0编辑  收藏  举报

导航