From 913c2f4f74d58617a9e23e63da0094295b722c8b Mon Sep 17 00:00:00 2001
From: C3204 <zhengyabo@lanpucloud.cn>
Date: 星期四, 08 一月 2026 13:18:51 +0800
Subject: [PATCH] 增加IO触发相机获取图像后自动触发对应的检测流程以及Log记录。
---
LB_VisionProcesses/Cameras/LBCameras/PHM6000Camera.cs | 86 +++++++++++++++++++++++++++---------------
1 files changed, 55 insertions(+), 31 deletions(-)
diff --git a/LB_VisionProcesses/Cameras/LBCameras/PHM6000Camera.cs b/LB_VisionProcesses/Cameras/LBCameras/PHM6000Camera.cs
index 640fcd0..e615d81 100644
--- a/LB_VisionProcesses/Cameras/LBCameras/PHM6000Camera.cs
+++ b/LB_VisionProcesses/Cameras/LBCameras/PHM6000Camera.cs
@@ -187,24 +187,28 @@
private void OnAcquisitionCompleted(IntPtr pInstance, int nOption)
{
// nOption: 0=涓�鎵规暟鎹粨鏉�, 1=鍏ㄩ儴瀹屾垚, 2=鐐逛簯灏辩华
+ // 鏍规嵁闇�姹傚彉鏇达紝鎴戜滑鍙鐞嗕寒搴﹀浘銆侽ption 1 鎴� 0 琛ㄧず 2D 鏁版嵁灏辩华銆�
if (nOption == 1 || nOption == 0)
{
- GenerateBitmapAndNotify();
+ GenerateIntensityMap();
}
}
- private void GenerateBitmapAndNotify()
+ private void GenerateIntensityMap()
{
- Bitmap bmp = null;
- lock (_bufferLock)
+ if (_cameraHandle == IntPtr.Zero) return;
+
+ int width = 0;
+ int height = 0;
+
+ // 鐩存帴浠� SDK 鑾峰彇鍚堝苟鍚庣殑寮哄害鏁版嵁鎸囬拡 (unsigned char*)
+ IntPtr pIntensity = PHM6000Profiler.GetIntensityData(_cameraHandle, ref width, ref height);
+
+ if (pIntensity == IntPtr.Zero || width <= 0 || height <= 0) return;
+
+ try
{
- if (_lineDataBuffer.Count == 0) return;
-
- // 榛樿瀹藉害 4096 (绾挎壂浼犳劅鍣ㄥ吀鍨嬪��)
- int width = 4096;
- int height = _lineDataBuffer.Count;
-
- bmp = new Bitmap(width, height, PixelFormat.Format8bppIndexed);
+ Bitmap bmp = new Bitmap(width, height, PixelFormat.Format8bppIndexed);
// 璁剧疆鐏板害璋冭壊鏉�
ColorPalette palette = bmp.Palette;
@@ -213,30 +217,20 @@
BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed);
- IntPtr scan0 = bmpData.Scan0;
- for (int i = 0; i < height; i++)
- {
- // 浠呮彁鍙� Alpha (寮哄害鍥�)
- // 娉ㄦ剰锛歀BPointZA 缁撴瀯涓� alpha 鏄 8 涓瓧鑺�
- byte[] lineBytes = _lineDataBuffer[i];
- byte[] intensityRow = new byte[width];
-
- for (int x = 0; x < Math.Min(width, lineBytes.Length / 8); x++)
- {
- intensityRow[x] = lineBytes[x * 8 + 7]; // alpha 浣�
- }
-
- Marshal.Copy(intensityRow, 0, scan0 + (i * bmpData.Stride), width);
- }
+ // 楂樻�ц兘鍐呭瓨鎷疯礉
+ int size = width * height;
+ byte[] managedData = new byte[size];
+ Marshal.Copy(pIntensity, managedData, 0, size);
+ Marshal.Copy(managedData, 0, bmpData.Scan0, size);
bmp.UnlockBits(bmpData);
- _lineDataBuffer.Clear();
- }
- if (bmp != null)
- {
- // 瑙﹀彂浜嬩欢
+ // 瑙﹀彂浜嬩欢閫氱煡 UI 鏇存柊浜害鍥�
ImageGrabbed?.Invoke(this, new CameraEventArgs(SN, bmp));
+ }
+ catch (Exception ex)
+ {
+ AsyncLogHelper.Error($"PHM6000: 鐢熸垚浜害鍥惧紓甯� - {ex.Message}");
}
}
@@ -272,6 +266,36 @@
return false;
}
+ public override bool StartWith_SoftTriggerModel()
+ {
+ throw new NotImplementedException();
+ }
+
+ public override bool StartWith_HardTriggerModel(TriggerSource hardtriggeritem = TriggerSource.Line0)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override bool GetImage(out Bitmap bitmap, int outtime = 3000)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override bool GetImageWithSoftTrigger(out Bitmap bitmap, int outtime = 3000)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override void SetCamConfig(CameraConfig config)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override void GetCamConfig(out CameraConfig config)
+ {
+ throw new NotImplementedException();
+ }
+
#endregion
}
--
Gitblit v1.9.3