Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
孙克
/
AccAOI
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit b63041d8
由
LN
编写于
2019-08-05 14:40:11 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
增加相机获取图片代码
1 个父辈
c00b7345
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
488 行增加
和
13 行删除
AOIProject/Program.cs
AccAOI/AccAOI.csproj
AccAOI/FrmAoiSetting.Designer.cs
AccAOI/FrmAoiSetting.cs
AccAOI/camera/CameraManager.cs
AccAOI/camera/HIKCamera.cs
dll/MvCameraControl.Net.dll
AOIProject/Program.cs
查看文件 @
b63041d
...
@@ -17,7 +17,11 @@ namespace AOIProject
...
@@ -17,7 +17,11 @@ namespace AOIProject
{
{
Application
.
EnableVisualStyles
();
Application
.
EnableVisualStyles
();
Application
.
SetCompatibleTextRenderingDefault
(
false
);
Application
.
SetCompatibleTextRenderingDefault
(
false
);
Application
.
Run
(
new
FrmAoiSetting
());
string
path
=
"E:\\VSSource\\TSAV-智能组装机\\Line-TSAV-AOI\\TSA-V\\bin\\Debug\\config\\AOIConfig\\"
;
string
filename
=
"E:\\VSSource\\TSAV-智能组装机\\Line-TSAV-AOI\\TSA-V\\bin\\Debug\\config\\AOIConfig\\aaaaa.data"
;
AccAOI
.
camera
.
CameraManager
.
LoadCamera
();
Application
.
Run
(
new
FrmAoiSetting
(
filename
,
null
,
path
));
AccAOI
.
camera
.
CameraManager
.
CloseCamera
();
}
}
}
}
}
}
AccAOI/AccAOI.csproj
查看文件 @
b63041d
...
@@ -38,6 +38,9 @@
...
@@ -38,6 +38,9 @@
<Reference Include="Asa.Theme">
<Reference Include="Asa.Theme">
<HintPath>..\dll\Asa.Theme.dll</HintPath>
<HintPath>..\dll\Asa.Theme.dll</HintPath>
</Reference>
</Reference>
<Reference Include="MvCameraControl.Net">
<HintPath>..\dll\MvCameraControl.Net.dll</HintPath>
</Reference>
<Reference Include="OpenCvSharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6adad1e807fea099, processorArchitecture=MSIL">
<Reference Include="OpenCvSharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6adad1e807fea099, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\OpenCvSharp3-AnyCPU.4.0.0.20181129\lib\net40\OpenCvSharp.dll</HintPath>
<HintPath>..\packages\OpenCvSharp3-AnyCPU.4.0.0.20181129\lib\net40\OpenCvSharp.dll</HintPath>
...
@@ -67,6 +70,7 @@
...
@@ -67,6 +70,7 @@
</ItemGroup>
</ItemGroup>
<ItemGroup>
<ItemGroup>
<Compile Include="AOIFormUtil.cs" />
<Compile Include="AOIFormUtil.cs" />
<Compile Include="camera\CameraManager.cs" />
<Compile Include="ControlUtil.cs" />
<Compile Include="ControlUtil.cs" />
<Compile Include="control\AioTempMatchControl.cs">
<Compile Include="control\AioTempMatchControl.cs">
<SubType>Form</SubType>
<SubType>Form</SubType>
...
@@ -104,6 +108,7 @@
...
@@ -104,6 +108,7 @@
<Compile Include="FrmAoiSetting.Designer.cs">
<Compile Include="FrmAoiSetting.Designer.cs">
<DependentUpon>FrmAoiSetting.cs</DependentUpon>
<DependentUpon>FrmAoiSetting.cs</DependentUpon>
</Compile>
</Compile>
<Compile Include="camera\HIKCamera.cs" />
<Compile Include="Program.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="control\AioTempMatchControl.resx">
<EmbeddedResource Include="control\AioTempMatchControl.resx">
...
...
AccAOI/FrmAoiSetting.Designer.cs
查看文件 @
b63041d
...
@@ -105,7 +105,7 @@ namespace AccAOI
...
@@ -105,7 +105,7 @@ namespace AccAOI
//
//
this
.
btnOpenImage
.
ImageSize
=
new
System
.
Drawing
.
Size
(
0
,
0
);
this
.
btnOpenImage
.
ImageSize
=
new
System
.
Drawing
.
Size
(
0
,
0
);
this
.
btnOpenImage
.
Inside
=
false
;
this
.
btnOpenImage
.
Inside
=
false
;
this
.
btnOpenImage
.
Location
=
new
System
.
Drawing
.
Point
(
10
32
,
40
);
this
.
btnOpenImage
.
Location
=
new
System
.
Drawing
.
Point
(
10
91
,
40
);
this
.
btnOpenImage
.
Name
=
"btnOpenImage"
;
this
.
btnOpenImage
.
Name
=
"btnOpenImage"
;
this
.
btnOpenImage
.
Size
=
new
System
.
Drawing
.
Size
(
109
,
30
);
this
.
btnOpenImage
.
Size
=
new
System
.
Drawing
.
Size
(
109
,
30
);
this
.
btnOpenImage
.
StateColor
=
System
.
Drawing
.
Color
.
FromArgb
(((
int
)(((
byte
)(
30
)))),
((
int
)(((
byte
)(
30
)))),
((
int
)(((
byte
)(
30
)))));
this
.
btnOpenImage
.
StateColor
=
System
.
Drawing
.
Color
.
FromArgb
(((
int
)(((
byte
)(
30
)))),
((
int
)(((
byte
)(
30
)))),
((
int
)(((
byte
)(
30
)))));
...
@@ -129,14 +129,14 @@ namespace AccAOI
...
@@ -129,14 +129,14 @@ namespace AccAOI
this
.
cmbCameraList
.
Inside
=
false
;
this
.
cmbCameraList
.
Inside
=
false
;
this
.
cmbCameraList
.
Location
=
new
System
.
Drawing
.
Point
(
730
,
40
);
this
.
cmbCameraList
.
Location
=
new
System
.
Drawing
.
Point
(
730
,
40
);
this
.
cmbCameraList
.
Name
=
"cmbCameraList"
;
this
.
cmbCameraList
.
Name
=
"cmbCameraList"
;
this
.
cmbCameraList
.
Size
=
new
System
.
Drawing
.
Size
(
158
,
30
);
this
.
cmbCameraList
.
Size
=
new
System
.
Drawing
.
Size
(
217
,
30
);
this
.
cmbCameraList
.
TabIndex
=
12
;
this
.
cmbCameraList
.
TabIndex
=
12
;
//
//
// btnGetCameraImg
// btnGetCameraImg
//
//
this
.
btnGetCameraImg
.
ImageSize
=
new
System
.
Drawing
.
Size
(
0
,
0
);
this
.
btnGetCameraImg
.
ImageSize
=
new
System
.
Drawing
.
Size
(
0
,
0
);
this
.
btnGetCameraImg
.
Inside
=
false
;
this
.
btnGetCameraImg
.
Inside
=
false
;
this
.
btnGetCameraImg
.
Location
=
new
System
.
Drawing
.
Point
(
9
08
,
40
);
this
.
btnGetCameraImg
.
Location
=
new
System
.
Drawing
.
Point
(
9
67
,
40
);
this
.
btnGetCameraImg
.
Name
=
"btnGetCameraImg"
;
this
.
btnGetCameraImg
.
Name
=
"btnGetCameraImg"
;
this
.
btnGetCameraImg
.
Size
=
new
System
.
Drawing
.
Size
(
109
,
30
);
this
.
btnGetCameraImg
.
Size
=
new
System
.
Drawing
.
Size
(
109
,
30
);
this
.
btnGetCameraImg
.
StateColor
=
System
.
Drawing
.
Color
.
FromArgb
(((
int
)(((
byte
)(
30
)))),
((
int
)(((
byte
)(
30
)))),
((
int
)(((
byte
)(
30
)))));
this
.
btnGetCameraImg
.
StateColor
=
System
.
Drawing
.
Color
.
FromArgb
(((
int
)(((
byte
)(
30
)))),
((
int
)(((
byte
)(
30
)))),
((
int
)(((
byte
)(
30
)))));
...
@@ -206,7 +206,7 @@ namespace AccAOI
...
@@ -206,7 +206,7 @@ namespace AccAOI
//
//
this
.
btnImageChange
.
ImageSize
=
new
System
.
Drawing
.
Size
(
0
,
0
);
this
.
btnImageChange
.
ImageSize
=
new
System
.
Drawing
.
Size
(
0
,
0
);
this
.
btnImageChange
.
Inside
=
false
;
this
.
btnImageChange
.
Inside
=
false
;
this
.
btnImageChange
.
Location
=
new
System
.
Drawing
.
Point
(
779
,
76
);
this
.
btnImageChange
.
Location
=
new
System
.
Drawing
.
Point
(
838
,
76
);
this
.
btnImageChange
.
Name
=
"btnImageChange"
;
this
.
btnImageChange
.
Name
=
"btnImageChange"
;
this
.
btnImageChange
.
Size
=
new
System
.
Drawing
.
Size
(
109
,
30
);
this
.
btnImageChange
.
Size
=
new
System
.
Drawing
.
Size
(
109
,
30
);
this
.
btnImageChange
.
StateColor
=
System
.
Drawing
.
Color
.
FromArgb
(((
int
)(((
byte
)(
30
)))),
((
int
)(((
byte
)(
30
)))),
((
int
)(((
byte
)(
30
)))));
this
.
btnImageChange
.
StateColor
=
System
.
Drawing
.
Color
.
FromArgb
(((
int
)(((
byte
)(
30
)))),
((
int
)(((
byte
)(
30
)))),
((
int
)(((
byte
)(
30
)))));
...
@@ -218,7 +218,7 @@ namespace AccAOI
...
@@ -218,7 +218,7 @@ namespace AccAOI
//
//
this
.
flatButton1
.
ImageSize
=
new
System
.
Drawing
.
Size
(
0
,
0
);
this
.
flatButton1
.
ImageSize
=
new
System
.
Drawing
.
Size
(
0
,
0
);
this
.
flatButton1
.
Inside
=
false
;
this
.
flatButton1
.
Inside
=
false
;
this
.
flatButton1
.
Location
=
new
System
.
Drawing
.
Point
(
9
08
,
76
);
this
.
flatButton1
.
Location
=
new
System
.
Drawing
.
Point
(
9
67
,
76
);
this
.
flatButton1
.
Name
=
"flatButton1"
;
this
.
flatButton1
.
Name
=
"flatButton1"
;
this
.
flatButton1
.
Size
=
new
System
.
Drawing
.
Size
(
109
,
30
);
this
.
flatButton1
.
Size
=
new
System
.
Drawing
.
Size
(
109
,
30
);
this
.
flatButton1
.
StateColor
=
System
.
Drawing
.
Color
.
FromArgb
(((
int
)(((
byte
)(
30
)))),
((
int
)(((
byte
)(
30
)))),
((
int
)(((
byte
)(
30
)))));
this
.
flatButton1
.
StateColor
=
System
.
Drawing
.
Color
.
FromArgb
(((
int
)(((
byte
)(
30
)))),
((
int
)(((
byte
)(
30
)))),
((
int
)(((
byte
)(
30
)))));
...
@@ -230,7 +230,7 @@ namespace AccAOI
...
@@ -230,7 +230,7 @@ namespace AccAOI
//
//
this
.
flatButton2
.
ImageSize
=
new
System
.
Drawing
.
Size
(
0
,
0
);
this
.
flatButton2
.
ImageSize
=
new
System
.
Drawing
.
Size
(
0
,
0
);
this
.
flatButton2
.
Inside
=
false
;
this
.
flatButton2
.
Inside
=
false
;
this
.
flatButton2
.
Location
=
new
System
.
Drawing
.
Point
(
10
32
,
76
);
this
.
flatButton2
.
Location
=
new
System
.
Drawing
.
Point
(
10
91
,
76
);
this
.
flatButton2
.
Name
=
"flatButton2"
;
this
.
flatButton2
.
Name
=
"flatButton2"
;
this
.
flatButton2
.
Size
=
new
System
.
Drawing
.
Size
(
109
,
30
);
this
.
flatButton2
.
Size
=
new
System
.
Drawing
.
Size
(
109
,
30
);
this
.
flatButton2
.
StateColor
=
System
.
Drawing
.
Color
.
FromArgb
(((
int
)(((
byte
)(
30
)))),
((
int
)(((
byte
)(
30
)))),
((
int
)(((
byte
)(
30
)))));
this
.
flatButton2
.
StateColor
=
System
.
Drawing
.
Color
.
FromArgb
(((
int
)(((
byte
)(
30
)))),
((
int
)(((
byte
)(
30
)))),
((
int
)(((
byte
)(
30
)))));
...
...
AccAOI/FrmAoiSetting.cs
查看文件 @
b63041d
using
AOI
;
using
AccAOI.camera
;
using
AOI
;
using
System
;
using
System
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.ComponentModel
;
using
System.ComponentModel
;
using
System.Data
;
using
System.Data
;
using
System.Drawing
;
using
System.Drawing
;
using
System.Drawing.Drawing2D
;
using
System.Drawing.Drawing2D
;
using
System.IO
;
using
System.Linq
;
using
System.Linq
;
using
System.Text
;
using
System.Text
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
...
@@ -20,6 +22,7 @@ namespace AccAOI
...
@@ -20,6 +22,7 @@ namespace AccAOI
private
AoiProject
Project
=
null
;
private
AoiProject
Project
=
null
;
private
bool
CanSel
=
true
;
private
bool
CanSel
=
true
;
private
string
DefaultPath
=
""
;
private
string
DefaultPath
=
""
;
private
string
currProjectFileName
=
""
;
public
FrmAoiSetting
()
public
FrmAoiSetting
()
{
{
InitializeComponent
();
InitializeComponent
();
...
@@ -29,9 +32,9 @@ namespace AccAOI
...
@@ -29,9 +32,9 @@ namespace AccAOI
{
{
InitializeComponent
();
InitializeComponent
();
this
.
WindowState
=
FormWindowState
.
Maximized
;
this
.
WindowState
=
FormWindowState
.
Maximized
;
if
(!
programPath
.
Equals
(
""
)
&&
(
image
!=
null
)
)
if
(!
programPath
.
Equals
(
""
))
{
{
BaseImg
=
image
;
//
BaseImg = image;
// Project = new AoiProject(image);
// Project = new AoiProject(image);
string
result
=
""
;
string
result
=
""
;
Project
=
AoiProject
.
Load
(
programPath
,
out
result
);
Project
=
AoiProject
.
Load
(
programPath
,
out
result
);
...
@@ -39,10 +42,20 @@ namespace AccAOI
...
@@ -39,10 +42,20 @@ namespace AccAOI
{
{
MessageBox
.
Show
(
"加载项目"
+
programPath
+
"失败:\r\n"
+
result
);
MessageBox
.
Show
(
"加载项目"
+
programPath
+
"失败:\r\n"
+
result
);
}
}
else
{
currProjectFileName
=
programPath
;
}
}
if
(
image
!=
null
)
{
if
(
Project
!=
null
)
{
Project
.
standardImage
=
image
;
}
}
}
DefaultPath
=
defaultPath
;
DefaultPath
=
defaultPath
;
ShowPorject
();
}
}
private
void
FrmAoiSetting_Load
(
object
sender
,
EventArgs
e
)
private
void
FrmAoiSetting_Load
(
object
sender
,
EventArgs
e
)
{
{
...
@@ -58,6 +71,16 @@ namespace AccAOI
...
@@ -58,6 +71,16 @@ namespace AccAOI
BaseImg
=
(
Image
)
Image
.
FromFile
(
defaultImg
).
Clone
();
BaseImg
=
(
Image
)
Image
.
FromFile
(
defaultImg
).
Clone
();
imageBox1
.
Image
=
BaseImg
;
imageBox1
.
Image
=
BaseImg
;
}
}
foreach
(
string
str
in
CameraManager
.
hikNameList
)
{
cmbCameraList
.
ItemAdd
(
str
);
}
if
(
Project
!=
null
)
{
ShowPorject
();
}
}
}
private
void
btnOpenImage_Click
(
object
sender
,
EventArgs
e
)
private
void
btnOpenImage_Click
(
object
sender
,
EventArgs
e
)
...
@@ -96,6 +119,21 @@ namespace AccAOI
...
@@ -96,6 +119,21 @@ namespace AccAOI
MessageBox
.
Show
(
"清先选择相机"
);
MessageBox
.
Show
(
"清先选择相机"
);
return
;
return
;
}
}
Bitmap
img
=
CameraManager
.
GetCamerImage
(
camera
);
if
(
img
!=
null
)
{
//读取图片内容
BaseImg
=
(
Image
)
img
.
Clone
();
if
(
Project
!=
null
)
{
Project
.
standardImage
=
BaseImg
;
}
imageBox1
.
Image
=
BaseImg
;
if
(
imageBox1
.
Visible
.
Equals
(
false
))
{
btnImageChange_Click
(
null
,
null
);
}
}
}
}
private
void
btnOpenPro_Click
(
object
sender
,
EventArgs
e
)
private
void
btnOpenPro_Click
(
object
sender
,
EventArgs
e
)
...
@@ -121,6 +159,10 @@ namespace AccAOI
...
@@ -121,6 +159,10 @@ namespace AccAOI
{
{
MessageBox
.
Show
(
"加载项目"
+
fileName
+
"失败:\r\n"
+
msg
);
MessageBox
.
Show
(
"加载项目"
+
fileName
+
"失败:\r\n"
+
msg
);
}
}
else
{
currProjectFileName
=
fileName
;
}
ShowPorject
();
ShowPorject
();
}
}
...
@@ -135,7 +177,13 @@ namespace AccAOI
...
@@ -135,7 +177,13 @@ namespace AccAOI
System
.
Windows
.
Forms
.
SaveFileDialog
saveFileDialog
=
new
System
.
Windows
.
Forms
.
SaveFileDialog
();
System
.
Windows
.
Forms
.
SaveFileDialog
saveFileDialog
=
new
System
.
Windows
.
Forms
.
SaveFileDialog
();
saveFileDialog
.
Title
=
"保存项目"
;
saveFileDialog
.
Title
=
"保存项目"
;
saveFileDialog
.
Filter
=
"(*.data)|*.data|(*.*)|*.*"
;
saveFileDialog
.
Filter
=
"(*.data)|*.data|(*.*)|*.*"
;
if
(!
String
.
IsNullOrEmpty
(
DefaultPath
))
if
(!
String
.
IsNullOrEmpty
(
currProjectFileName
))
{
saveFileDialog
.
InitialDirectory
=
Path
.
GetFullPath
(
currProjectFileName
);
saveFileDialog
.
FileName
=
Path
.
GetFileName
(
currProjectFileName
);
}
else
if
(!
String
.
IsNullOrEmpty
(
DefaultPath
))
{
{
saveFileDialog
.
InitialDirectory
=
DefaultPath
;
saveFileDialog
.
InitialDirectory
=
DefaultPath
;
}
}
...
@@ -245,6 +293,7 @@ namespace AccAOI
...
@@ -245,6 +293,7 @@ namespace AccAOI
{
{
CloseCurrAoi
();
CloseCurrAoi
();
aoiList
.
ItemClear
();
aoiList
.
ItemClear
();
BaseImg
=
Project
.
standardImage
;
imageBox1
.
Image
=
Project
.
standardImage
;
imageBox1
.
Image
=
Project
.
standardImage
;
imageBox1
.
SelectionRegion
=
new
GraphicsPath
();
imageBox1
.
SelectionRegion
=
new
GraphicsPath
();
...
@@ -418,7 +467,23 @@ namespace AccAOI
...
@@ -418,7 +467,23 @@ namespace AccAOI
private
void
flatButton1_Click
(
object
sender
,
EventArgs
e
)
private
void
flatButton1_Click
(
object
sender
,
EventArgs
e
)
{
{
string
camera
=
cmbCameraList
.
Text
;
if
(
camera
.
Equals
(
""
))
{
MessageBox
.
Show
(
"清先选择相机"
);
return
;
}
Bitmap
img
=
CameraManager
.
GetCamerImage
(
camera
);
if
(
img
!=
null
)
{
//读取图片内容
TestImage
=
(
Image
)
img
.
Clone
();
testImageBox1
.
Image
=
TestImage
;
if
(
testImageBox1
.
Visible
.
Equals
(
false
))
{
btnImageChange_Click
(
null
,
null
);
}
}
}
}
}
}
}
}
AccAOI/camera/CameraManager.cs
0 → 100644
查看文件 @
b63041d
using
System
;
using
System.Collections.Generic
;
using
System.Drawing
;
using
System.Linq
;
using
System.Runtime.ExceptionServices
;
using
System.Text
;
using
System.Threading.Tasks
;
namespace
AccAOI.camera
{
public
class
CameraManager
{
public
static
List
<
string
>
hikNameList
=
new
List
<
string
>();
private
static
char
spiltChar
=
'#'
;
public
static
string
ErrorMsg
=
""
;
public
static
void
LoadCamera
(
bool
isReLoad
=
false
)
{
if
(
isReLoad
)
{
HIKCamera
.
Instance
.
Load
();
}
string
[]
names
=
HIKCamera
.
Instance
.
CameraName
;
hikNameList
.
AddRange
(
names
);
}
public
static
void
CloseCamera
()
{
HIKCamera
.
Instance
.
Close
();
}
[
HandleProcessCorruptedStateExceptions
]
public
static
Bitmap
GetCamerImage
(
string
cameraName
)
{
Bitmap
bitm
=
null
;
try
{
if
(
hikNameList
.
Contains
(
cameraName
))
{
bool
result
=
HIKCamera
.
Instance
.
IsOpen
;
if
(!
result
)
{
result
=
HIKCamera
.
Instance
.
Open
(
cameraName
);
}
if
(
result
)
{
HIKCamera
.
Instance
.
GrabOne
();
if
(
HIKCamera
.
Instance
.
Image
!=
null
)
{
bitm
=
(
Bitmap
)
HIKCamera
.
Instance
.
Image
;
//HIKCamera.Instance.Close();
}
}
else
{
ErrorMsg
=
(
"相机【"
+
cameraName
+
"】打开失败:"
+
HIKCamera
.
Instance
.
ErrInfo
);
}
}
else
{
ErrorMsg
=
(
"未找到相机【"
+
cameraName
+
"】无法获取图片"
);
}
}
catch
(
Exception
ex
)
{
ErrorMsg
=
(
"从相机【"
+
cameraName
+
"】获取图片出错:"
+
ex
.
ToString
());
}
return
bitm
;
}
}
}
AccAOI/camera/HIKCamera.cs
0 → 100644
查看文件 @
b63041d
//引用MvCameraControl.Net.dll
using
System
;
using
MvCamCtrl.NET
;
using
System.Drawing
;
using
System.Drawing.Imaging
;
using
System.Collections.Generic
;
using
System.Runtime.InteropServices
;
namespace
AccAOI.camera
{
/// <summary>
/// 海康相机
/// </summary>
public
class
HIKCamera
{
public
static
HIKCamera
Instance
=
new
HIKCamera
();
/// <summary>
/// 当前相机
/// </summary>
private
MyCamera
cameraCurr
;
/// <summary>
/// 所有相机列表
/// </summary>
private
MyCamera
.
MV_CC_DEVICE_INFO_LIST
cameraAll
;
/// <summary>
/// 所有相机的名称
/// </summary>
private
List
<
string
>
cameraName
=
new
List
<
string
>();
/// <summary>
/// 海康相机
/// </summary>
private
HIKCamera
()
{
cameraAll
=
new
MyCamera
.
MV_CC_DEVICE_INFO_LIST
();
Load
();
}
/// <summary>
/// 错误信息
/// </summary>
public
string
ErrInfo
{
set
;
get
;
}
/// <summary>
/// 相机总数
/// </summary>
public
int
Count
{
get
{
return
(
int
)
cameraAll
.
nDeviceNum
;
}
}
/// <summary>
/// 相机名称,ModelName,SerialNumber
/// </summary>
public
string
[]
CameraName
{
get
{
return
cameraName
.
ToArray
();
}
}
/// <summary>
/// 当前相机是否打开
/// </summary>
public
bool
IsOpen
{
get
{
if
(
cameraCurr
==
null
)
return
false
;
else
return
true
;
}
}
/// <summary>
/// 相机图像宽度
/// </summary>
public
int
Width
{
set
;
get
;
}
/// <summary>
/// 相机图像高度
/// </summary>
public
int
Height
{
set
;
get
;
}
/// <summary>
/// 相机32位缓存
/// </summary>
public
byte
[]
Buffer
{
get
;
private
set
;
}
/// <summary>
/// 相机32位图像
/// </summary>
public
Bitmap
Image
{
get
;
private
set
;
}
/// <summary>
/// 加载相机
/// </summary>
public
void
Load
()
{
int
rtn
=
MyCamera
.
MV_CC_EnumDevices_NET
(
MyCamera
.
MV_GIGE_DEVICE
|
MyCamera
.
MV_USB_DEVICE
,
ref
cameraAll
);
if
(
rtn
!=
MyCamera
.
MV_OK
)
return
;
cameraName
.
Clear
();
string
s
=
""
;
for
(
int
i
=
0
;
i
<
cameraAll
.
nDeviceNum
;
i
++)
{
MyCamera
.
MV_CC_DEVICE_INFO
device
=
(
MyCamera
.
MV_CC_DEVICE_INFO
)
Marshal
.
PtrToStructure
(
cameraAll
.
pDeviceInfo
[
i
],
typeof
(
MyCamera
.
MV_CC_DEVICE_INFO
));
if
(
device
.
nTLayerType
==
MyCamera
.
MV_GIGE_DEVICE
)
{
IntPtr
buffer
=
Marshal
.
UnsafeAddrOfPinnedArrayElement
(
device
.
SpecialInfo
.
stGigEInfo
,
0
);
MyCamera
.
MV_GIGE_DEVICE_INFO
gigeInfo
=
(
MyCamera
.
MV_GIGE_DEVICE_INFO
)
Marshal
.
PtrToStructure
(
buffer
,
typeof
(
MyCamera
.
MV_GIGE_DEVICE_INFO
));
s
=
"GigE:"
+
gigeInfo
.
chModelName
+
" ("
+
gigeInfo
.
chSerialNumber
+
")"
;
}
else
if
(
device
.
nTLayerType
==
MyCamera
.
MV_USB_DEVICE
)
{
IntPtr
buffer
=
Marshal
.
UnsafeAddrOfPinnedArrayElement
(
device
.
SpecialInfo
.
stUsb3VInfo
,
0
);
MyCamera
.
MV_USB3_DEVICE_INFO
usbInfo
=
(
MyCamera
.
MV_USB3_DEVICE_INFO
)
Marshal
.
PtrToStructure
(
buffer
,
typeof
(
MyCamera
.
MV_USB3_DEVICE_INFO
));
s
=
"USB:"
+
usbInfo
.
chModelName
+
" ("
+
usbInfo
.
chSerialNumber
+
")"
;
}
cameraName
.
Add
(
s
);
}
}
/// <summary>
/// 打开指定相机
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public
bool
Open
(
string
name
)
{
int
n
=
cameraName
.
FindIndex
(
s
=>
s
==
name
);
if
(
n
==
-
1
)
return
false
;
else
return
Open
(
n
);
}
/// <summary>
/// 打开指定相机
/// </summary>
/// <param name="idx">索引</param>
/// <returns></returns>
public
bool
Open
(
int
idx
)
{
if
(
idx
<
0
||
idx
>=
Count
)
return
false
;
if
(
cameraCurr
!=
null
)
Close
();
try
{
MyCamera
.
MV_CC_DEVICE_INFO
device
=
(
MyCamera
.
MV_CC_DEVICE_INFO
)
Marshal
.
PtrToStructure
(
cameraAll
.
pDeviceInfo
[
idx
],
typeof
(
MyCamera
.
MV_CC_DEVICE_INFO
));
cameraCurr
=
new
MyCamera
();
if
(
cameraCurr
==
null
)
return
false
;
int
nRet
=
cameraCurr
.
MV_CC_CreateDevice_NET
(
ref
device
);
if
(
nRet
!=
MyCamera
.
MV_OK
)
return
false
;
nRet
=
cameraCurr
.
MV_CC_OpenDevice_NET
();
if
(
nRet
!=
MyCamera
.
MV_OK
)
{
cameraCurr
.
MV_CC_DestroyDevice_NET
();
return
false
;
}
if
(
device
.
nTLayerType
==
MyCamera
.
MV_GIGE_DEVICE
)
{
int
nPacketSize
=
cameraCurr
.
MV_CC_GetOptimalPacketSize_NET
();
if
(
nPacketSize
>
0
)
nRet
=
cameraCurr
.
MV_CC_SetIntValue_NET
(
"GevSCPSPacketSize"
,
(
uint
)
nPacketSize
);
}
cameraCurr
.
MV_CC_SetEnumValue_NET
(
"AcquisitionMode"
,
2
);
//工作在连续模式
cameraCurr
.
MV_CC_SetEnumValue_NET
(
"TriggerMode"
,
0
);
//连续模式
MyCamera
.
MVCC_INTVALUE
pstValue
=
new
MyCamera
.
MVCC_INTVALUE
();
nRet
=
cameraCurr
.
MV_CC_GetWidth_NET
(
ref
pstValue
);
Width
=
(
int
)
pstValue
.
nCurValue
;
nRet
=
cameraCurr
.
MV_CC_GetHeight_NET
(
ref
pstValue
);
Height
=
(
int
)
pstValue
.
nCurValue
;
return
true
;
}
catch
(
Exception
ex
)
{
ErrInfo
=
ex
.
Message
;
return
false
;
}
}
/// <summary>
/// 关闭当前相机
/// </summary>
public
void
Close
()
{
if
(
cameraCurr
!=
null
)
{
cameraCurr
.
MV_CC_CloseDevice_NET
();
cameraCurr
.
MV_CC_DestroyDevice_NET
();
cameraCurr
=
null
;
}
}
/// <summary>
/// 停止抓取数据
/// </summary>
public
void
Stop
()
{
if
(
cameraCurr
==
null
)
return
;
int
rtn
=
cameraCurr
.
MV_CC_StopGrabbing_NET
();
if
(
rtn
!=
MyCamera
.
MV_OK
)
return
;
}
/// <summary>
/// 抓取一张图像
/// </summary>
public
void
GrabOne
()
{
int
rtn
=
cameraCurr
.
MV_CC_StartGrabbing_NET
();
if
(
rtn
!=
MyCamera
.
MV_OK
)
return
;
MyCamera
.
MVCC_INTVALUE
stParam
=
new
MyCamera
.
MVCC_INTVALUE
();
rtn
=
cameraCurr
.
MV_CC_GetIntValue_NET
(
"PayloadSize"
,
ref
stParam
);
if
(
rtn
!=
MyCamera
.
MV_OK
)
return
;
uint
dataSize
=
stParam
.
nCurValue
;
byte
[]
dataArr
=
new
byte
[
dataSize
];
uint
buffSize
=
dataSize
*
3
+
2048
;
byte
[]
buffArr
=
new
byte
[
buffSize
];
IntPtr
pData
=
Marshal
.
UnsafeAddrOfPinnedArrayElement
(
dataArr
,
0
);
MyCamera
.
MV_FRAME_OUT_INFO_EX
stFrameInfo
=
new
MyCamera
.
MV_FRAME_OUT_INFO_EX
();
rtn
=
cameraCurr
.
MV_CC_GetOneFrameTimeout_NET
(
pData
,
dataSize
,
ref
stFrameInfo
,
100000
);
if
(
rtn
!=
MyCamera
.
MV_OK
)
return
;
MyCamera
.
MvGvspPixelType
enDstPixelType
=
stFrameInfo
.
enPixelType
;
switch
(
stFrameInfo
.
enPixelType
)
{
case
MyCamera
.
MvGvspPixelType
.
PixelType_Gvsp_Mono8
:
case
MyCamera
.
MvGvspPixelType
.
PixelType_Gvsp_Mono10
:
case
MyCamera
.
MvGvspPixelType
.
PixelType_Gvsp_Mono10_Packed
:
case
MyCamera
.
MvGvspPixelType
.
PixelType_Gvsp_Mono12
:
case
MyCamera
.
MvGvspPixelType
.
PixelType_Gvsp_Mono12_Packed
:
enDstPixelType
=
stFrameInfo
.
enPixelType
;
break
;
case
MyCamera
.
MvGvspPixelType
.
PixelType_Gvsp_BayerGR8
:
case
MyCamera
.
MvGvspPixelType
.
PixelType_Gvsp_BayerRG8
:
case
MyCamera
.
MvGvspPixelType
.
PixelType_Gvsp_BayerGB8
:
case
MyCamera
.
MvGvspPixelType
.
PixelType_Gvsp_BayerBG8
:
case
MyCamera
.
MvGvspPixelType
.
PixelType_Gvsp_BayerGR10
:
case
MyCamera
.
MvGvspPixelType
.
PixelType_Gvsp_BayerRG10
:
case
MyCamera
.
MvGvspPixelType
.
PixelType_Gvsp_BayerGB10
:
case
MyCamera
.
MvGvspPixelType
.
PixelType_Gvsp_BayerBG10
:
case
MyCamera
.
MvGvspPixelType
.
PixelType_Gvsp_BayerGR12
:
case
MyCamera
.
MvGvspPixelType
.
PixelType_Gvsp_BayerRG12
:
case
MyCamera
.
MvGvspPixelType
.
PixelType_Gvsp_BayerGB12
:
case
MyCamera
.
MvGvspPixelType
.
PixelType_Gvsp_BayerBG12
:
case
MyCamera
.
MvGvspPixelType
.
PixelType_Gvsp_BayerGR10_Packed
:
case
MyCamera
.
MvGvspPixelType
.
PixelType_Gvsp_BayerRG10_Packed
:
case
MyCamera
.
MvGvspPixelType
.
PixelType_Gvsp_BayerGB10_Packed
:
case
MyCamera
.
MvGvspPixelType
.
PixelType_Gvsp_BayerBG10_Packed
:
case
MyCamera
.
MvGvspPixelType
.
PixelType_Gvsp_BayerGR12_Packed
:
case
MyCamera
.
MvGvspPixelType
.
PixelType_Gvsp_BayerRG12_Packed
:
case
MyCamera
.
MvGvspPixelType
.
PixelType_Gvsp_BayerGB12_Packed
:
case
MyCamera
.
MvGvspPixelType
.
PixelType_Gvsp_BayerBG12_Packed
:
case
MyCamera
.
MvGvspPixelType
.
PixelType_Gvsp_RGB8_Packed
:
case
MyCamera
.
MvGvspPixelType
.
PixelType_Gvsp_YUV422_Packed
:
case
MyCamera
.
MvGvspPixelType
.
PixelType_Gvsp_YUV422_YUYV_Packed
:
case
MyCamera
.
MvGvspPixelType
.
PixelType_Gvsp_YCBCR411_8_CBYYCRYY
:
enDstPixelType
=
MyCamera
.
MvGvspPixelType
.
PixelType_Gvsp_RGB8_Packed
;
break
;
}
IntPtr
pImage
=
Marshal
.
UnsafeAddrOfPinnedArrayElement
(
buffArr
,
0
);
MyCamera
.
MV_PIXEL_CONVERT_PARAM
stConverPixelParam
=
new
MyCamera
.
MV_PIXEL_CONVERT_PARAM
();
stConverPixelParam
.
nWidth
=
stFrameInfo
.
nWidth
;
stConverPixelParam
.
nHeight
=
stFrameInfo
.
nHeight
;
stConverPixelParam
.
pSrcData
=
pData
;
stConverPixelParam
.
nSrcDataLen
=
stFrameInfo
.
nFrameLen
;
stConverPixelParam
.
enSrcPixelType
=
stFrameInfo
.
enPixelType
;
stConverPixelParam
.
enDstPixelType
=
enDstPixelType
;
stConverPixelParam
.
pDstBuffer
=
pImage
;
stConverPixelParam
.
nDstBufferSize
=
buffSize
;
rtn
=
cameraCurr
.
MV_CC_ConvertPixelType_NET
(
ref
stConverPixelParam
);
if
(
rtn
!=
MyCamera
.
MV_OK
)
return
;
if
(
enDstPixelType
==
MyCamera
.
MvGvspPixelType
.
PixelType_Gvsp_Mono8
)
{
Image
=
new
Bitmap
(
stFrameInfo
.
nWidth
,
stFrameInfo
.
nHeight
,
stFrameInfo
.
nWidth
*
1
,
PixelFormat
.
Format8bppIndexed
,
pImage
);
ColorPalette
cp
=
Image
.
Palette
;
for
(
int
i
=
0
;
i
<
256
;
i
++)
cp
.
Entries
[
i
]
=
Color
.
FromArgb
(
i
,
i
,
i
);
Image
.
Palette
=
cp
;
int
picSize
=
Image
.
Width
*
Image
.
Height
;
Buffer
=
new
byte
[
picSize
];
Array
.
Copy
(
buffArr
,
Buffer
,
picSize
);
//Rectangle rect = new Rectangle(0, 0, Image.Width, Image.Height);
//BitmapData bmpData = Image.LockBits(rect, ImageLockMode.ReadWrite, Image.PixelFormat);
//IntPtr iPtr = bmpData.Scan0;
//int picSize = Image.Width * Image.Height;
//Buffer = new byte[picSize];
//Marshal.Copy(iPtr, Buffer, 0, picSize);
//Image.UnlockBits(bmpData);
}
else
{
for
(
int
i
=
0
;
i
<
stFrameInfo
.
nHeight
;
i
++)
{
for
(
int
j
=
0
;
j
<
stFrameInfo
.
nWidth
;
j
++)
{
byte
chRed
=
buffArr
[
i
*
stFrameInfo
.
nWidth
*
3
+
j
*
3
];
buffArr
[
i
*
stFrameInfo
.
nWidth
*
3
+
j
*
3
]
=
buffArr
[
i
*
stFrameInfo
.
nWidth
*
3
+
j
*
3
+
2
];
buffArr
[
i
*
stFrameInfo
.
nWidth
*
3
+
j
*
3
+
2
]
=
chRed
;
}
}
Image
=
new
Bitmap
(
stFrameInfo
.
nWidth
,
stFrameInfo
.
nHeight
,
stFrameInfo
.
nWidth
*
3
,
PixelFormat
.
Format24bppRgb
,
pImage
);
int
picSize
=
Image
.
Width
*
Image
.
Height
*
3
;
Buffer
=
new
byte
[
picSize
];
Array
.
Copy
(
buffArr
,
Buffer
,
picSize
);
}
rtn
=
cameraCurr
.
MV_CC_StopGrabbing_NET
();
if
(
rtn
!=
MyCamera
.
MV_OK
)
return
;
}
/// <summary>
/// 抓取连续图像,触发GrabImage事件
/// </summary>
/// <param name="hWnd"></param>
public
void
GrabContinuous
(
IntPtr
hWnd
)
{
int
rtn
=
cameraCurr
.
MV_CC_StartGrabbing_NET
();
if
(
rtn
!=
MyCamera
.
MV_OK
)
return
;
rtn
=
cameraCurr
.
MV_CC_Display_NET
(
hWnd
);
if
(
rtn
!=
MyCamera
.
MV_OK
)
return
;
}
}
}
\ No newline at end of file
\ No newline at end of file
dll/MvCameraControl.Net.dll
0 → 100644
查看文件 @
b63041d
此文件类型无法预览
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论