zoukankan
html css js c++ java
MIL与opencv的转化
/**/
/*
This is a standalone program. Pass an image name as a first parameter of the program.
Switch between standard and probabilistic Hough transform by changing "#if 1" to "#if 0" and back
*/
#include
<
cv.h
>
#include
<
highgui.h
>
#include
<
math.h
>
#include
<
stdio.h
>
#include
<
mil.h
>
//
cxcore.lib cv.lib highgui.lib mil.lib milcor.lib milgen.lib milmet2.lib milcor2.lib milmet2d.lib milmet2cl.lib milpul.lib milorion.lib mil1394.lib milvga.lib
#define
CHECK_EXIT(x) {if(!(x)){printf("Error %s\n",#x);exit(0);}}
class
CMIL_CV
{
MIL_ID MilApplication,
/**/
/*
Application identifier.
*/
MilSystem,
/**/
/*
System identifier.
*/
//
MilDisplay, /* Display identifier. */
MilDigitizer,
/**/
/*
Digitizer identifier.
*/
MilImageDisp;
/**/
/*
Image buffer identifier.
*/
static
void
MouseCallback (
int
event
,
int
x,
int
y,
int
flags,
void
*
param)
{
if
(
event
==
CV_EVENT_LBUTTONDOWN)
//
CV_EVENT_MOUSEMOVE)
{
IplImage
*
img
=*
(IplImage
**
)param;
//
为什么直接传param就不行
CHECK_EXIT(CV_IS_IMAGE(img));
CvFont ft
=
cvFont(
2
,
1
);
char
s[
100
];
sprintf(s,
"
%3d,%3d %d
"
,x,y,CV_IMAGE_ELEM(img,BYTE,y,x));;
cvPutText(img,s,cvPoint(
100
,
100
),
&
ft,CV_RGB(
0
,
0
,
0
));
printf(
"
%s\n
"
,s);
}
}
public
:
enum
{
Mil_CH0
=
M_CH0,
Mil_CH1
=
M_CH1,
}
;
BOOL MilGetImage(
int
Channel,IplImage
*
&
dst)
{
try
{
MbufClear(MilImageDisp,
0
);
MdigChannel(MilDigitizer, Channel);
MdigGrab(MilDigitizer, MilImageDisp);
int
w
=
MbufInquire(MilImageDisp,M_SIZE_X,M_NULL);;
int
h
=
MbufInquire(MilImageDisp,M_SIZE_Y,M_NULL);;
int
band
=
MbufInquire(MilImageDisp,M_SIZE_BAND,M_NULL);;
int
pitch
=
MbufInquire(MilImageDisp,M_PITCH_BYTE,M_NULL);;
//
IplImage *dst=cvCreateImage(cvSize(w,h),8,band);
if
(
!
dst)
dst
=
cvCreateImage(cvSize(w,h),
8
,band);
//
CHECK_EXIT(dst->width==w && dst->height==h && dst->nChannels=band);
char
*
p
=
dst
->
imageData;
MbufGet(MilImageDisp,p);
dst
->
origin
=
IPL_ORIGIN_TL;
//
cvFlip(dst,dst,0);
}
catch
(
)
{
return
FALSE;
}
return
TRUE;
}
;
BOOL MilOpen(
char
*
DCF_NAME)
{
try
{
MappAlloc(M_DEFAULT,
&
MilApplication);
MsysAlloc(M_SYSTEM_METEOR_II, M_DEF_SYSTEM_NUM, M_SETUP,
&
MilSystem);
//
MdispAlloc(MilSystem, M_DEFAULT, M_DEF_DISPLAY_FORMAT, M_DEFAULT, &MilDisplay);
MdigAlloc(MilSystem, M_DEFAULT, DCF_NAME, M_DEFAULT,
&
MilDigitizer);
printf(
"
Allocate a display buffer, clear it and display it. \n
"
);
MbufAllocColor(MilSystem,
MdigInquire(MilDigitizer, M_SIZE_BAND, M_NULL),
(
long
) (MdigInquire(MilDigitizer, M_SIZE_X, M_NULL)),
(
long
) (MdigInquire(MilDigitizer, M_SIZE_Y, M_NULL)),
8L
+
M_UNSIGNED,
M_IMAGE
+
M_GRAB
+
M_DISP,
&
MilImageDisp);
MdigControl(MilDigitizer, M_GRAB_MODE, M_SYNCHRONOUS);
//
must!!
MdigControl(MilDigitizer, M_CAMERA_LOCK, M_ENABLE);
//
MbufClear(MilImageDisp,
0
);
}
catch
(
)
{
return
FALSE;
}
return
TRUE;
}
BOOL MilClose()
{
try
{
MbufFree(MilImageDisp);
MdigFree(MilDigitizer);
MsysFree(MilSystem);
MappFree(MilApplication);
}
catch
(
)
{
return
FALSE;
}
return
TRUE;
}
void
Test()
{
CHECK_EXIT(MilOpen(
"
H:/wqj/project/CMILL_CV/DCF6.dcf
"
));
IplImage
*
img0
=
0
;
//
必须初始化为0
IplImage
*
img1
=
0
;
int
Image_id
=
0
;
cvNamedWindow(
"
CH0
"
,
1
);
cvNamedWindow(
"
CH1
"
,
1
);
cvSetMouseCallback(
"
CH0
"
, MouseCallback,
&
img0);
cvSetMouseCallback(
"
CH1
"
, MouseCallback,
&
img1);
printf(
"
Press g to save image in current directory.\n
"
);
printf(
"
Press Esc to Exit.\n
"
);
do
{
//
奇怪,抓到的图都是CH0的
//
--要设置同步
MilGetImage(M_CH0,img0);
CHECK_EXIT(img0);
//
printf("ImageSize %d*%d*%d\n",img0->width,img0->height,img0->nChannels);
MilGetImage(M_CH1,img1);
CHECK_EXIT(img1);
int
c
=
cvWaitKey(
100
);
if
(c
==
'
g
'
)
{
char
img_name[
100
];
sprintf(img_name,
"
left_%.2d.bmp
"
,Image_id);
cvSaveImage(img_name,img0);
sprintf(img_name,
"
right_%.2d.bmp
"
,Image_id);
cvSaveImage(img_name,img1);
printf(
"
save image %d ok\n
"
,Image_id);
Image_id
++
;
}
else
if
(c
==
27
)
break
;
cvShowImage(
"
CH0
"
, img0 );
cvShowImage(
"
CH1
"
, img1 );
}
while
(
1
);
printf(
"
Exit..\n
"
);
CHECK_EXIT(MilClose());
cvReleaseImage(
&
img0);
cvReleaseImage(
&
img1);
}
}
;
int
main(
int
argc,
char
**
argv)
{
CMIL_CV milcv;
milcv.Test();
return
0
;
}
查看全文
相关阅读:
批处理处理oracle数据库脚本导入
Log4Net 配置说明
MSSQL和oracle数据通讯
计算字符串中每种字符出现的次数[Dictionary<char,int>泛型集合用法]
newagg新蛋笔试题
Oracle数据库切换SQLServer数据库解决方案
sqlserver 的事务和c#的事务
SQL Server 2005 导出 数据脚本
ASP.NET CMD WebShell
Silverlight BUG
原文地址:https://www.cnblogs.com/wqj1212/p/1003551.html
最新文章
LSMW例子详解
[转]软件设计本质论—白话面向对象
[转]Select Single And Up To 1 Rows
SAP data migration: Create project milestone
如何为做好的query建立一个事务代码
[转]ABAP Program to create nonGUI tab strips
SAP data migration: Create billing plan for sales
.NET Framework类库列表总结
MySQL的三大引擎:InnoDB、MyISAM和Memory
.net中对象序列化技术浅谈 转自周公的专栏
热门文章
简单代码实现C#中运行另外一个程序
关于防止sql注入的几种手段
泛型List【转】
C# 类库 (Dll)开发
C#中IList与List区别
重新认识抽象类和接口的区别
支持 汉字 拼音 笔画 转换Microsoft Visual Studio International Pack 1.0 Beta1
sqlserver 行转列
MSSQL远程链接本地化的方法
企业管理器里删除不需要的注册
Copyright © 2011-2022 走看看