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
有以下几个特性重复的报错
分别是什么意思也都截下来了
简单直接些,都注释掉就可以了。为了防止和原来程序的注释混淆,所以加了J
读程序
实例化→设置采集模式→打开相机连接→//设置参数→开始抓取→获取结果并处理→停止抓取→关闭连接
需要注意的有:
程序代码
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);
}
}
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具