C# + Basler Demo学习-Grab

操作:把Grab文件夹拷出来,在新Grab文件夹内新建控制台项目。将新Grab文件夹内的文件添加到项目中,其中把有主函数的那个的所有内容复制粘贴到控制台项目自动生成的program.cs中,在把这个文件从项目中排除。
我也不太知道这么操作会不会有啥不对,感觉不太错,但也不太对。
要不对于这种一个解决方案底下好几个项目的怎么使用还是请教下李工吧

项目说明(pylon SDK Samples Manual.pdf)

This sample illustrates how to grab images and process images asynchronously. This means that while the application is processing a buffer, the acquisition of the next buffer is done in parallel.
The sample uses a pool of buffers. The buffers are allocated automatically. Once a buffer is filled and ready for processing, the buffer is retrieved from the stream grabber as part of a grab result. The grab result is processed and the buffer is passed back to the stream grabber by disposing the grab result. The buffer is reused and refilled.
A buffer retrieved from the stream grabber as a grab result is not overwritten in the background as long as the grab result is not disposed

有以下几个特性重复的报错

image
分别是什么意思也都截下来了
image
image
image
image
image
image
简单直接些,都注释掉就可以了。为了防止和原来程序的注释混淆,所以加了J

读程序

实例化→设置采集模式→打开相机连接→//设置参数→开始抓取→获取结果并处理→停止抓取→关闭连接
需要注意的有:
image

程序代码

Grab.cs
/*
   This sample illustrates how to grab images and process images asynchronously.
   This means that while the application is processing a buffer,
   the acquisition of the next buffer is done in parallel.
   The sample uses a pool of buffers. The buffers are automatically allocated. Once a buffer is filled
   and ready for processing, the buffer is retrieved from the stream grabber as part of a grab
   result. The grab result is processed and the buffer is passed back to the stream grabber by
   disposing the grab result. The buffer is reused and refilled.
   A buffer retrieved from the stream grabber as a grab result is not overwritten in the background
   as long as the grab result is not disposed.
*/

using System;
using Basler.Pylon;

namespace Grab
{
    class Grab
    {
        internal static void Main()
        {
            // The exit code of the sample application.
            int exitCode = 0;

            try
            {
                // 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.
                    Console.WriteLine("Using camera {0}.", 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)
                            {
                                // Access the image data.
                                Console.WriteLine("SizeX: {0}", grabResult.Width);
                                Console.WriteLine("SizeY: {0}", grabResult.Height);
                                byte[] buffer = grabResult.PixelData as byte[];
                                Console.WriteLine("Gray value of first pixel: {0}", buffer[0]);
                                Console.WriteLine("");

                                // Display the grabbed image.
                                ImageWindow.DisplayImage(0, grabResult);
                            }
                            else
                            {
                                Console.WriteLine("Error: {0} {1}", grabResult.ErrorCode, grabResult.ErrorDescription);
                            }
                        }
                    }

                    // Stop grabbing.
                    camera.StreamGrabber.Stop();

                    // Close the connection to the camera device.
                    camera.Close();
                }
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Exception: {0}", e.Message);
                exitCode = 1;
            }
            finally
            {
                // Comment the following two lines to disable waiting on exit.
                Console.Error.WriteLine("\nPress enter to exit.");
                Console.ReadLine();
            }

            Environment.Exit(exitCode);
        }
    }
}

posted @ 2021-12-28 00:35  橘子Jane  阅读(272)  评论(0编辑  收藏  举报