tingzhiyi
一朵小冯花
采纳率0%
2017-08-11 01:07 阅读 5.7k

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

2

请问各位大神,怎么把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条回答 默认 最新

相关推荐