From 7d40453bb5702b1898bc9fe57afbdb3f2e629918 Mon Sep 17 00:00:00 2001
From: C3032 <C3032@BC3032>
Date: 星期二, 06 一月 2026 15:09:01 +0800
Subject: [PATCH] Merge branch 'feature/Camera3D'
---
LB_VisionProcesses/Cameras/LBCameras/PHM6000Camera.cs | 56 +++++++++++++++++++++++++-------------------------------
1 files changed, 25 insertions(+), 31 deletions(-)
diff --git a/LB_VisionProcesses/Cameras/LBCameras/PHM6000Camera.cs b/LB_VisionProcesses/Cameras/LBCameras/PHM6000Camera.cs
index 640fcd0..0aba8c7 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,31 +217,21 @@
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}");
+ }
}
private void SyncConfigFromCamera()
--
Gitblit v1.9.3