******注意添加引用   PylonC.NET.dll

目前手头没有相机,故出现没有找到相机提示窗口,点击确定窗口自动关闭。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Cognex.VisionPro;
using PylonC.NET;
using System.Runtime.InteropServices;
using System.Threading;namespace Basler
{public partial class Form1 : Form{private Thread ThreadObject;                //线程private bool ThreadStop = false;public Form1(){InitializeComponent();//线程对象实例化ThreadObject = new Thread(new ThreadStart(ThreadFunction));//打开相机OpenCameraSoftTrigger();}private void button1_Click(object sender, EventArgs e){if (ThreadObject.ThreadState == System.Threading.ThreadState.Unstarted){ThreadObject.Start();}}private void button2_Click(object sender, EventArgs e){ThreadStop = true;//停止采集图像Pylon.DeviceClose(hDev);Pylon.DestroyDevice(hDev);}//线程回调函数public void ThreadFunction(){int ImageWidth = 1280;int ImageHeight = 1024;CogImage8Grey Image = new CogImage8Grey();var cogRoot = new CogImage8Root();IntPtr ImageBufferPtr = Marshal.AllocHGlobal(ImageWidth * ImageHeight);byte[] ImageBuffer = new byte[ImageWidth * ImageHeight];while (!ThreadStop){//采集单张图像SnapAcquisitionSoftTrigger(ref ImageBuffer);//将图像数据从托管区拷贝到非托管区Marshal.Copy(ImageBuffer, 0, ImageBufferPtr, ImageWidth * ImageHeight);//初始化cogRoot.Initialize(ImageWidth, ImageHeight, ImageBufferPtr, ImageWidth, null);//指定Image图像数据为cogRootImage.SetRoot(cogRoot);//将图像数据传给cogRecordDisplay1控件cogRecordDisplay1.Image = Image as CogImage8Grey;//显示图像cogRecordDisplay1.Fit(true);}}///balser  sdk/private PYLON_DEVICE_HANDLE hDev = new PYLON_DEVICE_HANDLE();   /* Handle for the pylon device. */private uint numDevices;                                        /* Number of available devices. */private const int numGrabs = 1000;                              /* Number of images to grab. */private PylonBuffer<Byte> imgBuf = null;                        /* Buffer used for grabbing. *///打开相机public void OpenCameraSoftTrigger(){bool isAvail;Pylon.Initialize();/* Enumerate all camera devices. You must call PylonEnumerateDevices() before creating a device. */numDevices = Pylon.EnumerateDevices();if (0 == numDevices){MessageBox.Show("没有找到相机");System.Environment.Exit(0);}else{/* Get a handle for the first device found.  */hDev = Pylon.CreateDeviceByIndex(0);}/* Before using the device, it must be opened. Open it for configuring parameters and for grabbing images. */Pylon.DeviceOpen(hDev, Pylon.cPylonAccessModeControl | Pylon.cPylonAccessModeStream);/* Set the pixel format to Mono8, where gray values will be output as 8 bit values for each pixel. *//* ... Check first to see if the device supports the Mono8 format. */isAvail = Pylon.DeviceFeatureIsAvailable(hDev, "EnumEntry_PixelFormat_Mono8");if (!isAvail){/* Feature is not available. */MessageBox.Show("设备不支持8位灰度图像");}/* ... Set the pixel format to Mono8. */Pylon.DeviceFeatureFromString(hDev, "PixelFormat", "Mono8");/* Disable acquisition start trigger if available. */isAvail = Pylon.DeviceFeatureIsAvailable(hDev, "EnumEntry_TriggerSelector_AcquisitionStart");if (isAvail){Pylon.DeviceFeatureFromString(hDev, "TriggerSelector", "AcquisitionStart");Pylon.DeviceFeatureFromString(hDev, "TriggerMode", "Off");}/* Disable frame burst start trigger if available */isAvail = Pylon.DeviceFeatureIsAvailable(hDev, "EnumEntry_TriggerSelector_FrameBurstStart");if (isAvail){Pylon.DeviceFeatureFromString(hDev, "TriggerSelector", "FrameBurstStart");Pylon.DeviceFeatureFromString(hDev, "TriggerMode", "Off");}/* Disable frame start trigger if available */isAvail = Pylon.DeviceFeatureIsAvailable(hDev, "EnumEntry_TriggerSelector_FrameStart");if (isAvail){Pylon.DeviceFeatureFromString(hDev, "TriggerSelector", "FrameStart");Pylon.DeviceFeatureFromString(hDev, "TriggerMode", "Off");}/* For GigE cameras, we recommend increasing the packet size for betterperformance. If the network adapter supports jumbo frames, set the packetsize to a value > 1500, e.g., to 8192. In this sample, we only set the packet sizeto 1500. *//* ... Check first to see if the GigE camera packet size parameter is supported and if it is writable. */isAvail = Pylon.DeviceFeatureIsWritable(hDev, "GevSCPSPacketSize");if (isAvail){/* ... The device supports the packet size feature. Set a value. */Pylon.DeviceSetIntegerFeature(hDev, "GevSCPSPacketSize", 1500);}}//采集单张图像public void SnapAcquisitionSoftTrigger(ref byte[] ImageBufferPtr){PylonGrabResult_t grabResult;/* Grab one single frame from stream channel 0. Thecamera is set to "single frame" acquisition mode.Wait up to 500 ms for the image to be grabbed.If imgBuf is null a buffer is automatically created with the right size.*/Pylon.DeviceGrabSingleFrame(hDev, 0, ref imgBuf, out grabResult, 500);IntPtr dataAddress = imgBuf.Pointer;/* Check to see if the image was grabbed successfully. */if (grabResult.Status == EPylonGrabStatus.Grabbed){Marshal.Copy(dataAddress, ImageBufferPtr, 0, 1280 * 1024 - 1);}else{Console.WriteLine("图像抓取失败!n");}}}
}

VproC#混合编程,Basler相机加载显示实时图像相关推荐

  1. Ionic+Angular+Express实现前后端交互使用HttpClient发送get请求数据并加载显示(附代码下载)

    场景 Ionic介绍以及搭建环境.新建和运行项目: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/106308166 在上面搭建起 ...

  2. three.js 加载显示文字

    three.js 加载显示文字 代码放到 ./three.js/examples/ 下 <!DOCTYPE html> <html lang="en">&l ...

  3. Android 四大组件之——Acitivity(四) Activity是如何加载显示内容的?

    1. 在Activity调用onCreate()等生命周期之前,Activity会调用attach()方法,而在attach()方法中会调用如下代码 onAttach() {PolicyManager ...

  4. thinkphp+ajax无刷新分页并加载显示图片

    2019独角兽企业重金招聘Python工程师标准>>> 最近自己用thinkphp和bootstrap做一个小站点,在用到ajax与后台数据库交互实现无刷新分页时,因为我需要返回的数 ...

  5. opengl加载显示3D模型UC类型文件

    opengl加载显示3D模型UC类型文件 前置条件 注意事项 项目展示 项目完整C++源代码 前置条件 opengl三方库freeglut,显示uc格式的三维模型文件, 注意事项 源代码 model_ ...

  6. opengl加载显示3D模型3d类型文件

    opengl加载显示3d模型UC类型文件 前置条件 注意事项 项目展示 项目完整C++源代码 前置条件 opengl三方库freeglut,显示3d格式的三维模型文件, 注意事项 源代码 model_ ...

  7. opengl加载显示3DS模型3DS类型文件

    opengl加载显示3DS模型UC类型文件 前置条件 注意事项 项目展示 项目完整C++源代码 前置条件 opengl三方库freeglut,显示3DS格式的三维模型文件 注意事项 源代码 model ...

  8. opengl加载显示3D模型3MF类型文件

    opengl加载显示3D模型3MF类型文件 前置条件 注意事项 项目展示 项目完整C++源代码 前置条件 opengl三方库freeglut,显示3MF格式的三维模型文件 注意事项 源代码 model ...

  9. opengl加载显示3D模型AC类型文件

    opengl加载显示3D模型AC类型文件 前置条件 注意事项 项目展示 项目完整C++源代码 前置条件 opengl三方库freeglut,显示AC格式的三维模型文件 注意事项 源代码 model_f ...

  10. opengl加载显示3D模型AMF类型文件

    opengl加载显示3D模型AMF类型文件 前置条件 注意事项 项目展示 项目完整C++源代码 前置条件 opengl三方库freeglut,显示AMF格式的三维模型文件 注意事项 源代码 model ...

最新文章

  1. 新建域用户添加提示密码策略受限
  2. C++程序员学Python:C与Python进行交互
  3. idea设置启动时打开欢迎页
  4. Pressed状态和clickable,duplicateParentState的关系
  5. primefaces_使用PrimeFaces开发数据导出实用程序
  6. linux 嵌入式 快照_Linux 系统之Systemd
  7. 修改Linux启动后的默认颜色,更改linux目录的默认颜色(我选择了Yellow)
  8. 最牛逼的微服务架构方案,没有之一!
  9. html下拉嵌套只读,html组件不可输入(只读)同时任何组件都有效
  10. Java正则表达式例子汇总
  11. ACM 学习笔记(七) 贪心
  12. 判断用户什么时候离开,以什么方式离开
  13. python 新手常见问题
  14. excel从html文件传输乱码,打开乱码解决步骤7:在Excel中直接打开该文本文件
  15. 原理图编译出现Has no driving source 啥意思?
  16. redmi路由器是linux,拯救小米路由器硬盘数据的方法及软件下载
  17. 轻松理解java前期绑定(静态绑定)与后期绑定(动态绑定) 的区别。
  18. python汇率转换_python汇率兑换
  19. The remote device or resource won't accept the connect
  20. openfiler服务器打不开web管理页面

热门文章

  1. 数据结构-图的课程设计
  2. 中职教计算机专业发展,中等职业教育中计算机专业教育思考
  3. 学习ZYNQ问题记录
  4. java实现图片文件上传下载_java实现文件的上传和下载
  5. Qt Design Studio 1.4正式发布
  6. PyTorch实践系列(二):GPU与CPU运行对比
  7. 创业者两大特征:喜欢折腾与坚持不懈
  8. android声波通信demo,Android声波通信改进版
  9. 2019做报表用什么软件:报表类型,产品推荐
  10. python编程考试_Python编程练习(一)