刘彬 1 долоо хоног өмнө
parent
commit
3d6d80aeff

+ 2 - 2
Cameralibs/HKCamera/MvCamera.cs

@@ -272,7 +272,7 @@ namespace LampInspectionMachine.Cameralibs.HKCamera
                             CameraConnectChangedEvent?.Invoke(ID, true);
                         }
                         TotalTime = sw.Elapsed;
-                       
+                        ImageCallbackEvent?.Invoke(Image, TotalTime, ErrorMessage);
                         return Image;
                     }
                     else
@@ -388,7 +388,7 @@ namespace LampInspectionMachine.Cameralibs.HKCamera
                 try
                 {
                     Grab();
-                  //  ImageCallbackEvent?.Invoke(Image, TotalTime, ErrorMessage);
+                    ImageCallbackEvent?.Invoke(Image, TotalTime, ErrorMessage);
                 }
                 catch ( Exception )
                 {

+ 6 - 70
Core/Management.cs

@@ -363,9 +363,9 @@ namespace LampInspectionMachine.Core
         {
             try
             {
-                // Console.WriteLine(stopwatch.ElapsedMilliseconds.ToString());
+               
                 Image = image;
-                //stopwatch.Restart();
+              
             }
             finally
             {
@@ -382,9 +382,9 @@ namespace LampInspectionMachine.Core
         {
             try
             {
-                // Console.WriteLine(stopwatch.ElapsedMilliseconds.ToString());
+                
                 Image = image;
-                //stopwatch.Restart();
+               
             }
             finally
             {
@@ -515,7 +515,7 @@ namespace LampInspectionMachine.Core
                 resultImage = ConvertToColorCogImage(pData, ref pFrameInfo);
             }
 
-            // 将图像传递给VisionPro处理工具
+           
             Image = resultImage;
         }
 
@@ -577,71 +577,7 @@ namespace LampInspectionMachine.Core
         /// <summary>
         /// 将WriteableBitmap转换为CogImage8Grey(自动处理彩色转灰度)
         /// </summary>
-        public CogImage8Grey WriteableBitmapToCogImage8Grey(WriteableBitmap wbitmap)
-        {
-
-            int width = wbitmap.PixelWidth;
-            int height = wbitmap.PixelHeight;
-            CogImage8Grey image = new CogImage8Grey(width, height);
-
-            // 获取原始图像数据
-            int bytesPerPixel = (wbitmap.Format.BitsPerPixel + 7) / 8;
-            int stride = (width * bytesPerPixel + 3) & ~3;
-            byte[] pixels = new byte[height * stride];
-            wbitmap.CopyPixels(pixels, stride, 0);
-
-            // 获取CogImage8Grey的原始内存
-            byte[] cogPixels = new byte[width * height];
-            unsafe
-            {
-                fixed ( byte* srcPtr = pixels, dstPtr = cogPixels )
-                {
-                    byte* src = srcPtr;
-                    byte* dst = dstPtr;
-
-                    for ( int y = 0; y < height; y++ )
-                    {
-                        byte* srcRow = src + y * stride;
-                        for ( int x = 0; x < width; x++ )
-                        {
-                            byte* pixel = srcRow + x * bytesPerPixel;
-                            *dst++ = ( byte ) ( pixel[ 0 ] * 0.11 + pixel[ 1 ] * 0.59 + pixel[ 2 ] * 0.3 );
-                        }
-                    }
-                }
-
-
-            }
-            var pixelMemory = image.Get8GreyPixelMemory(CogImageDataModeConstants.Write, 0, 0,image.Width, image.Height);
-            IntPtr scan0 = pixelMemory.Scan0;
-            // Marshal.Copy(cogPixels, 0, scan0, cogPixels.Length);
-
-            for ( int y = 0; y < height; y++ )
-            {
-                IntPtr destPtr = pixelMemory.Scan0 + y * pixelMemory.Stride;
-                Marshal.Copy(cogPixels, y * width, destPtr, width);
-            }
-
-            return image;
-        }
-
-        private static byte[] ConvertToGrayscale(WriteableBitmap wb)
-        {
-            int width = wb.PixelWidth;
-            int height = wb.PixelHeight;
-            byte[] grayData = new byte[width * height];
-            int stride = wb.BackBufferStride; // 使用实际步长
-
-            // 锁定并复制像素数据
-            wb.Lock();
-            IntPtr buffer = wb.BackBuffer;
-            byte[] pixelData = new byte[stride * height];
-            System.Runtime.InteropServices.Marshal.Copy(pixelData, 0, buffer, pixelData.Length);
-            wb.Unlock();
-
-
-            return pixelData;
-        }
+        
         public void OnSwitchToolBlock(int index)
         {
             cogToolBlock1 = CamTemplateS[ index ];