Lizhifun 2017-08-11 01:07 采纳率: 0%
浏览 6300
已结题

Basler相机获取的图片流转为Halcon中图片格式HImage

请问各位大神,怎么把Basler相机获取的图片流转为Halcon中图片格式HImage呢,语言用的是C#;
相机返回的结果有两种,一种是Basler自定义的返回结果,一种是图片的像素数组
如果能先转为bmp保存到内存中也行
图片说明

附源码:

  // Create a camera object that selects the first camera device found.
                // More constructors are available for selecting a specific camera device.
                using (Camera camera = new Camera())
                {
                    // Print the model name of the camera.
                    camera_info.Text=camera.CameraInfo[CameraInfoKey.ModelName];

                    // Set the acquisition mode to free running continuous acquisition when the camera is opened.
                    camera.CameraOpened += Configuration.AcquireContinuous;

                    // Open the connection to the camera device.
                    camera.Open();

                    // The parameter MaxNumBuffer can be used to control the amount of buffers
                    // allocated for grabbing. The default value of this parameter is 10.
                    camera.Parameters[PLCameraInstance.MaxNumBuffer].SetValue(5);
                    // Start grabbing.
                    camera.StreamGrabber.Start();

                    // Grab a number of images.
                    for (int i = 0; i < 10; ++i)
                    {
                        // Wait for an image and then retrieve it. A timeout of 5000 ms is used.
                        IGrabResult grabResult = camera.StreamGrabber.RetrieveResult(5000, TimeoutHandling.ThrowException);
                        using (grabResult)
                        {
                            // Image grabbed successfully?
                            if (grabResult.GrabSucceeded)
                            {

                               ImagePersistence.Save(ImageFileFormat.Bmp, "C:\\" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".bmp", grabResult);
                                // Access the image data.
                               buffer = grabResult.PixelData as byte[];

                               // Display the grabbed image.
                               //ImageWindow.DisplayImage(0, grabResult);

                            }
                            else
                            {
                                MessageBox.Show(grabResult.ErrorCode+","+grabResult.ErrorDescription);
                            }
                        }
                    }
                    //将获得的图片转换为Halcon对象
                    HImageConvertFromBytes(buffer);

                    // Stop grabbing.
                    camera.StreamGrabber.Stop();
                    // Close the connection to the camera device.
                    camera.Dispose();
                    camera.Close();

                }
  • 写回答

1条回答 默认 最新

  • zqbnqsdsmd 2018-06-14 16:20
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘