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 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)