Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
顾剑亮
/
Camera
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
图表
网络
创建新的问题
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit d543ae03
由
刘韬
编写于
2022-12-07 11:38:10 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
1
1 个父辈
ed43b30d
显示空白字符变更
内嵌
并排
正在显示
20 个修改的文件
包含
108 行增加
和
46 行删除
.vs/Camera/v16/.suo
.vs/Camera/v16/Browse.VC.db
CameraVisionLib/Barcode.cs
CameraVisionLib/CameraVisionLib.cs
CameraVisionLib/HIK/HIK_IPCamera.cs
CameraVisionLib/HIK/HIK_VisionCamera.cs
CameraVisionLib/bin/Debug/Asa.Camera.VisionLib.dll
CameraVisionLib/bin/Debug/Asa.Camera.VisionLib.pdb
CameraVisionLib/bin/Debug/Asa.Camera.VisionLib.xml
CameraVisionLib/obj/Debug/Asa.Camera.VisionLib.dll
CameraVisionLib/obj/Debug/Asa.Camera.VisionLib.pdb
CameraVisionLib/obj/Debug/CameraVisionLib.csproj.AssemblyReference.cache
CameraVisionLibSetting/bin/Debug/Asa.Camera.VisionLib.dll
CameraVisionLibSetting/bin/Debug/Asa.Camera.VisionLib.pdb
CameraVisionLibSetting/bin/Debug/Asa.Camera.VisionLib.xml
CameraVisionLibSetting/bin/Debug/CameraVisionLibSetting.exe
CameraVisionLibSetting/bin/Debug/CameraVisionLibSetting.zip
CameraVisionLibSetting/bin/Debug/EyemLib.zip
CameraVisionLibSetting/obj/Debug/CameraVisionLibSetting.csproj.AssemblyReference.cache
CameraVisionLibSetting/obj/Debug/CameraVisionLibSetting.exe
.vs/Camera/v16/.suo
查看文件 @
d543ae0
此文件类型无法预览
.vs/Camera/v16/Browse.VC.db
0 → 100644
查看文件 @
d543ae0
此文件太大,无法显示。
CameraVisionLib/Barcode.cs
查看文件 @
d543ae0
...
...
@@ -153,16 +153,20 @@ namespace Asa.Barcode
Stopwatch
stopwatch
=
new
Stopwatch
();
stopwatch
.
Start
();
HOperatorSet
.
Rgb1ToGray
(
hObj
,
out
HObject
grayImage
);
//HOperatorSet.ScaleImage(grayImage1, out HObject grayImage, 1.2, -45);
//grayImage1.Dispose();
HOperatorSet
.
CreateBarCodeModel
(
new
HTuple
(),
new
HTuple
(),
out
HTuple
hv_BarCode
);
//创建条码模型
HOperatorSet
.
SetBarCodeParam
(
hv_BarCode
,
"num_scanlines"
,
5
);
//扫描线的最大数量
HOperatorSet
.
SetBarCodeParam
(
hv_BarCode
,
"min_identical_scanlines"
,
3
);
//成功解码最少扫描线数量
HOperatorSet
.
SetBarCodeParam
(
hv_BarCode
,
"start_stop_tolerance"
,
"high"
);
//扫描线的起点和终点的容许误差,high误差大,low误差小
//
HOperatorSet.SetBarCodeParam(hv_BarCode, "start_stop_tolerance", "high"); //扫描线的起点和终点的容许误差,high误差大,low误差小
HOperatorSet
.
SetBarCodeParam
(
hv_BarCode
,
"max_diff_orient"
,
5
);
//条码相邻两条竖条边缘扭曲的最大角度容差
HOperatorSet
.
FindBarCode
(
grayImage
,
out
HObject
symbolRegions
,
hv_BarCode
,
"auto"
,
out
HTuple
hv_String
);
//寻找条码
HOperatorSet
.
GetBarCodeResult
(
hv_BarCode
,
"all"
,
"decoded_types"
,
out
HTuple
hv_Type
);
//获取条码类型
HOperatorSet
.
GetBarCodeResult
(
hv_BarCode
,
"all"
,
"orientation"
,
out
HTuple
hv_Orientation
);
//获取条码方向,x轴逆时针[0,180],顺时针[0,-180]
HOperatorSet
.
SmallestRectangle2
(
symbolRegions
,
out
HTuple
row
,
out
HTuple
column
,
out
HTuple
phi
,
out
HTuple
length1
,
out
HTuple
length2
);
HOperatorSet
.
ClearBarCodeModel
(
hv_BarCode
);
//清除条码模型
symbolRegions
.
Dispose
();
grayImage
.
Dispose
();
stopwatch
.
Stop
();
Common
.
log
.
Info
(
"Halcon Extract1DCode Count="
+
hv_String
.
Length
+
" time:"
+
stopwatch
.
ElapsedMilliseconds
);
...
...
CameraVisionLib/CameraVisionLib.cs
查看文件 @
d543ae0
...
...
@@ -236,6 +236,18 @@ namespace Asa.Camera
}
return
result
.
ToArray
();
}
/// <summary>
/// 按索引获取当前图像
/// </summary>
/// <returns></returns>
public
Bitmap
GetImage
(
int
index
)
{
if
(
cameraAll
[
0
].
Count
==
0
)
return
null
;
cameraAll
[
0
].
GrabOne
(
index
,
out
Bitmap
bmp
);
return
bmp
;
}
/// <summary>
/// 获取当前图像
...
...
CameraVisionLib/HIK/HIK_IPCamera.cs
查看文件 @
d543ae0
...
...
@@ -6,6 +6,9 @@ using System.Drawing;
using
System.Runtime.InteropServices
;
using
System.Drawing.Imaging
;
using
CameraVisionLib.Model
;
using
System.IO
;
using
System.Runtime.Serialization.Formatters.Binary
;
using
System.Threading
;
namespace
Asa.HIK
{
...
...
@@ -305,8 +308,6 @@ namespace Asa.HIK
private
bool
LoginDevice
(
int
idx
)
{
try
...
...
@@ -450,19 +451,22 @@ namespace Asa.HIK
private
bool
GrabDevice
(
int
idx
,
out
Bitmap
bmp
)
{
if
(
info
[
idx
].
Preview
==
IntPtr
.
Zero
)
{
bmp
=
null
;
try
{
uint
lpSizeReturned
=
0
;
uint
dwPicSize
=
8
00000
;
uint
dwPicSize
=
100
00000
;
byte
[]
sJpegPicBuffer
=
new
byte
[
dwPicSize
];
IPCameraAPI
.
NET_DVR_JPEGPARA
lpJpegPara
=
new
()
{
wPicQuality
=
0
,
wPicSize
=
0xff
};
bool
rtn
=
IPCameraAPI
.
NET_DVR_CaptureJPEGPicture_NEW
(
info
[
idx
].
ID
,
1
,
ref
lpJpegPara
,
sJpegPicBuffer
,
dwPicSize
,
ref
lpSizeReturned
);
if
(
rtn
)
{
System
.
IO
.
MemoryStream
ms
=
new
(
sJpegPicBuffer
,
0
,
(
int
)
lpSizeReturned
);
byte
[]
newbuf
=
new
byte
[(
int
)
lpSizeReturned
];
Buffer
.
BlockCopy
(
sJpegPicBuffer
,
0
,
newbuf
,
0
,
newbuf
.
Count
());
System
.
IO
.
MemoryStream
ms
=
new
(
newbuf
,
0
,
newbuf
.
Count
());
bmp
=
new
Bitmap
(
System
.
Drawing
.
Image
.
FromStream
(
ms
));
info
[
idx
].
Width
=
bmp
.
Width
;
info
[
idx
].
Height
=
bmp
.
Height
;
...
...
@@ -479,48 +483,78 @@ namespace Asa.HIK
Common
.
log
.
Error
(
class
Name
+
" GrabDevice"
,
ex
);
return
false
;
}
}
else
{
//以下为使用保存文件的方式读取
//
bmp = null;
//string path = System.IO.Path.GetTempPath()
+ System.IO.Path.GetRandomFileName();
bmp
=
null
;
string
path
=
System
.
IO
.
Path
.
GetTempPath
()
+
"HIK"
+
System
.
IO
.
Path
.
GetRandomFileName
();
//try
//{
// IPCameraAPI.NET_DVR_JPEGPARA lpJpegPara = new()
// {
// wPicQuality = 0, //图片质量系数 0最好 1较好 2一般
// wPicSize = 0xff //Auto使用当前码流分辨率
// };
// bool rtn = IPCameraAPI.NET_DVR_CaptureJPEGPicture(info[idx].ID, 1, ref lpJpegPara, path);
// if (rtn)
// {
// System.IO.FileStream fs = new(path, System.IO.FileMode.Open);
// byte[] array = new byte[fs.Length];
// fs.Read(array, 0, array.Length);
// System.IO.MemoryStream ms = new(array);
// bmp = new Bitmap(System.Drawing.Image.FromStream(ms));
// info[idx].Width = bmp.Width;
// info[idx].Height = bmp.Height;
// fs.Dispose();
// System.IO.File.Delete(path);
// Common.log.Info(string.Format("{0} GrabOne OK, IP={1}", className, info[idx].IP));
// }
// else
// {
// uint err = IPCameraAPI.NET_DVR_GetLastError();
// Common.log.Info(string.Format("{0} GrabOne failed, IP={1}, errorcode={2}", className, info[idx].IP, err));
// }
// return rtn;
//}
//catch (Exception ex)
//{
// Common.log.Error(className + " GrabDevice", ex);
// return false;
//}
}
try
{
IPCameraAPI
.
NET_DVR_JPEGPARA
lpJpegPara
=
new
()
{
wPicQuality
=
0
,
//图片质量系数 0最好 1较好 2一般
wPicSize
=
0xff
//Auto使用当前码流分辨率
};
bool
rtn
=
IPCameraAPI
.
NET_DVR_CapturePicture
(
info
[
idx
].
ID
,
path
);
if
(
rtn
)
{
Thread
.
Sleep
(
100
);
int
i
=
0
;
for
(
i
=
0
;
i
<
100
;
i
++)
{
try
{
var
a
=
new
Bitmap
(
path
);
bmp
=
DeepClone
(
a
);
a
.
Dispose
();
break
;
}
catch
{
Thread
.
Sleep
(
100
);
}
}
//System.IO.FileStream fs = new(path, System.IO.FileMode.Open);
//byte[] array = new byte[fs.Length];
//fs.Read(array, 0, array.Length);
//System.IO.MemoryStream ms = new(array);
//bmp = new Bitmap(System.Drawing.Image.FromStream(ms));
//info[idx].Width = bmp.Width;
//info[idx].Height = bmp.Height;
//fs.Dispose();
System
.
IO
.
File
.
Delete
(
path
);
Common
.
log
.
Info
(
string
.
Format
(
"{0} GrabOne OK, IP={1}"
,
class
Name
,
info
[
idx
].
IP
)
+
",i:"
+
i
);
}
else
{
uint
err
=
IPCameraAPI
.
NET_DVR_GetLastError
();
Common
.
log
.
Info
(
string
.
Format
(
"{0} GrabOne failed, IP={1}, errorcode={2}"
,
class
Name
,
info
[
idx
].
IP
,
err
));
}
return
rtn
;
}
catch
(
Exception
ex
)
{
Common
.
log
.
Error
(
class
Name
+
" GrabDevice"
,
ex
);
return
false
;
}
}
}
public
static
T
DeepClone
<
T
>(
T
_object
)
{
T
dstobject
;
using
(
MemoryStream
mStream
=
new
MemoryStream
())
{
BinaryFormatter
bf
=
new
BinaryFormatter
();
bf
.
Serialize
(
mStream
,
_object
);
mStream
.
Seek
(
0
,
SeekOrigin
.
Begin
);
//指定当前流的位置为流的开头。
dstobject
=
(
T
)
bf
.
Deserialize
(
mStream
);
mStream
.
Close
();
}
return
dstobject
;
}
private
bool
GrabDevice
(
int
idx
,
out
byte
[]
buff
,
out
PixelFormat
format
)
{
buff
=
null
;
...
...
CameraVisionLib/HIK/HIK_VisionCamera.cs
查看文件 @
d543ae0
...
...
@@ -415,7 +415,7 @@ namespace Asa.HIK
byte
[]
buffArr
=
new
byte
[
buffSize
];
IntPtr
pData
=
Marshal
.
UnsafeAddrOfPinnedArrayElement
(
dataArr
,
0
);
MyCamera
.
MV_FRAME_OUT_INFO_EX
stFrameInfo
=
new
();
result
=
cameraCurr
[
idx
].
MV_CC_GetOneFrameTimeout_NET
(
pData
,
dataSize
,
ref
stFrameInfo
,
100
000
);
result
=
cameraCurr
[
idx
].
MV_CC_GetOneFrameTimeout_NET
(
pData
,
dataSize
,
ref
stFrameInfo
,
5
000
);
if
(
result
!=
MyCamera
.
MV_OK
)
{
Common
.
log
.
Info
(
string
.
Format
(
"{0} MV_CC_GetOneFrameTimeout_NET failed,{1}"
,
cameraName
[
idx
],
result
));
...
...
CameraVisionLib/bin/Debug/Asa.Camera.VisionLib.dll
查看文件 @
d543ae0
此文件类型无法预览
CameraVisionLib/bin/Debug/Asa.Camera.VisionLib.pdb
查看文件 @
d543ae0
此文件类型无法预览
CameraVisionLib/bin/Debug/Asa.Camera.VisionLib.xml
查看文件 @
d543ae0
...
...
@@ -289,6 +289,12 @@
</summary>
<returns></returns>
</member>
<member
name=
"M:Asa.Camera.VisionLib.GetImage(System.Int32)"
>
<summary>
按索引获取当前图像
</summary>
<returns></returns>
</member>
<member
name=
"M:Asa.Camera.VisionLib.GetImage(System.String)"
>
<summary>
获取当前图像
...
...
CameraVisionLib/obj/Debug/Asa.Camera.VisionLib.dll
查看文件 @
d543ae0
此文件类型无法预览
CameraVisionLib/obj/Debug/Asa.Camera.VisionLib.pdb
查看文件 @
d543ae0
此文件类型无法预览
CameraVisionLib/obj/Debug/CameraVisionLib.csproj.AssemblyReference.cache
查看文件 @
d543ae0
此文件类型无法预览
CameraVisionLibSetting/bin/Debug/Asa.Camera.VisionLib.dll
查看文件 @
d543ae0
此文件类型无法预览
CameraVisionLibSetting/bin/Debug/Asa.Camera.VisionLib.pdb
查看文件 @
d543ae0
此文件类型无法预览
CameraVisionLibSetting/bin/Debug/Asa.Camera.VisionLib.xml
查看文件 @
d543ae0
...
...
@@ -289,6 +289,12 @@
</summary>
<returns></returns>
</member>
<member
name=
"M:Asa.Camera.VisionLib.GetImage(System.Int32)"
>
<summary>
按索引获取当前图像
</summary>
<returns></returns>
</member>
<member
name=
"M:Asa.Camera.VisionLib.GetImage(System.String)"
>
<summary>
获取当前图像
...
...
CameraVisionLibSetting/bin/Debug/CameraVisionLibSetting.exe
查看文件 @
d543ae0
此文件类型无法预览
CameraVisionLibSetting/bin/Debug/CameraVisionLibSetting.zip
0 → 100644
查看文件 @
d543ae0
此文件太大,无法显示。
CameraVisionLibSetting/bin/Debug/EyemLib.zip
0 → 100644
查看文件 @
d543ae0
此文件太大,无法显示。
CameraVisionLibSetting/obj/Debug/CameraVisionLibSetting.csproj.AssemblyReference.cache
查看文件 @
d543ae0
此文件类型无法预览
CameraVisionLibSetting/obj/Debug/CameraVisionLibSetting.exe
查看文件 @
d543ae0
此文件类型无法预览
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论