• HTuple HObject使用记录


    从HTuple获取数据

    HTuple hTuple= hDevelopExport.hv__Row1;

    double RR = hTuple[0].D;

                double[] ret = hTuple.ToDArr(); 
                double[] ret1 = hTuple1.ToDArr();
                double testD = hTuple[0].D;
                //string testS = hTuple[0].S;
                long testL = hTuple[0].L;
                int testI = hTuple[0].I;
                Object testO = hTuple[0].O;
                float testF = hTuple[0].F;

    给HTuple赋值

    HTuple data = new HTuple(ret);

    1. //
    2. // 摘要:
    3. // Create an empty tuple
    4. public HTuple();
    5. //
    6. // 摘要:
    7. // Create a tuple containing a single string value
    8. public HTuple(string s);
    9. //
    10. // 摘要:
    11. // Create a tuple containing double values
    12. public HTuple(params float[] f);
    13. //
    14. // 摘要:
    15. // Create a tuple containing a single double value
    16. public HTuple(float f);
    17. //
    18. // 摘要:
    19. // Create a tuple containing double values
    20. public HTuple(params double[] d);
    21. //
    22. // 摘要:
    23. // Create a tuple containing a single double value
    24. public HTuple(double d);
    25. //
    26. // 摘要:
    27. // Create an integer tuple representing pointer values. The used integer size depends
    28. // on the executing platform.
    29. public HTuple(params IntPtr[] ip);
    30. //
    31. // 摘要:
    32. // Create an integer tuple representing a pointer value. The used integer size depends
    33. // on the executing platform.
    34. public HTuple(IntPtr ip);
    35. //
    36. // 摘要:
    37. // Create a tuple containing 64-bit integer values
    38. public HTuple(params long[] l);
    39. //
    40. // 摘要:
    41. // Create a tuple containing a single 64-bit integer value
    42. public HTuple(long l);
    43. //
    44. // 摘要:
    45. // Create a tuple containing 32-bit integer values
    46. public HTuple(params int[] i);
    47. //
    48. // 摘要:
    49. // Create a tuple containing a single 32-bit integer value
    50. public HTuple(int i);
    51. //
    52. // 摘要:
    53. // Create tuple containing integer value 0 (false) or 1 (true)
    54. public HTuple(bool b);

    HObject转bitmap(灰度图)

    1. public void HObject2Bitmap8(HObject image, out Bitmap res)
    2. {
    3. HTuple hpoint, type, width, height;
    4. const int Alpha = 255;
    5. HOperatorSet.GetImagePointer1(image, out hpoint, out type, out width, out height);
    6. res = new Bitmap(width, height, PixelFormat.Format8bppIndexed);
    7. ColorPalette pal = res.Palette;
    8. for (int i = 0; i <= 255; i++)
    9. { pal.Entries[i] = Color.FromArgb(Alpha, i, i, i); }
    10. res.Palette = pal; Rectangle rect = new Rectangle(0, 0, width, height);
    11. BitmapData bitmapData = res.LockBits(rect, ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed);
    12. int PixelSize = Bitmap.GetPixelFormatSize(bitmapData.PixelFormat) / 8;
    13. IntPtr ptr1 = bitmapData.Scan0;
    14. IntPtr ptr2 = hpoint; int bytes = width * height;
    15. byte[] rgbvalues = new byte[bytes];
    16. System.Runtime.InteropServices.Marshal.Copy(ptr2, rgbvalues, 0, bytes);
    17. System.Runtime.InteropServices.Marshal.Copy(rgbvalues, 0, ptr1, bytes);
    18. res.UnlockBits(bitmapData);
    19. }

    HObject转bitmap(3通道图)

    1. public static Bitmap Honject2Bitmap24(HObject hObject)
    2. {
    3. //获取图像尺寸
    4. HTuple width0 = new HTuple();
    5. HTuple height0 = new HTuple();
    6. HTuple Pointer = new HTuple();
    7. HTuple type = new HTuple();
    8. HTuple width = new HTuple();
    9. HTuple height = new HTuple();
    10. HObject InterImage = new HObject();
    11. HOperatorSet.GetImageSize(hObject, out width0, out height0);
    12. HOperatorSet.GetImageSize(hObject, out width0, out height0);
    13. //创建交错格式图像
    14. HOperatorSet.InterleaveChannels(hObject, out InterImage, "rgb", 4 * width0, 0);
    15. //获取交错格式图像指针
    16. HOperatorSet.GetImagePointer1(InterImage, out Pointer, out type, out width, out height);
    17. IntPtr ptr = Pointer;
    18. //构建新Bitmap图像
    19. Bitmap bitmap = new Bitmap(width / 4, height, width, PixelFormat.Format24bppRgb, ptr);
    20. return bitmap;
    21. }

    Bitmap转HObject (灰度图)

    1. public static void Bitmap2HObjectBpp8(Bitmap bmp, out HObject image)
    2. {
    3. try
    4. {
    5. Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);
    6. BitmapData srcBmpData = bmp.LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format8bppIndexed);
    7. HOperatorSet.GenImage1(out image, "byte", bmp.Width, bmp.Height, srcBmpData.Scan0);
    8. bmp.UnlockBits(srcBmpData);
    9. }
    10. catch (Exception ex)
    11. {
    12. image = null;
    13. }
    14. }

    Bitmap转HObject(3通道图)

    1. public static void Bitmap2HObjectBpp24(Bitmap bmp, out HObject image) //90ms
    2. {
    3. try
    4. {
    5. Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);
    6. BitmapData srcBmpData = bmp.LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
    7. HOperatorSet.GenImageInterleaved(out image, srcBmpData.Scan0, "bgr", bmp.Width, bmp.Height, 0, "byte", 0, 0, 0, 0, -1, 0);
    8. bmp.UnlockBits(srcBmpData);
    9. }
    10. catch (Exception ex)
    11. {
    12. image = null;
    13. }
    14. }

    打可以快速定位问题的有效日志

  • 相关阅读:
    MySQL安装及应用合集(6):MySQL函数快速验证方法
    机器学习周记(第三十八周:语义分割)2024.5.6~2024.5.12
    MySQL数据库的基本操作及存储引擎的使用
    MyBatis动态SQL
    树形结构之父子节点查询
    redis和nacos的安装
    将小部分源码设计精髓带入到开发中来(工厂模式、适配器模式、抽象类、监听器)
    QTreeWidget样式qss
    manim边做边学--通用三维坐标系
    Multilinear Relationship Networks:多任务学习框架
  • 原文地址:https://blog.csdn.net/qq_30807313/article/details/128017719