Basler相机实时图像显示--Qt代码


Basler相机实时图像显示的Qt版本的代码,代码中具体的说明请参考我的博客
资源截图
代码片段和文件信息
#include “BaslerCamera_RealTimeShow.h“
#include 
#include 
#include 

BaslerCamera_RealTimeShow::BaslerCamera_RealTimeShow(QWidget *parent)
    : QMainWindow(parent)
{
    ui.setupUi(this);

    m_camera.RegisterImageEventHandler(this Pylon::RegistrationMode_ReplaceAll Pylon::Ownership_ExternalOwnership);
    // Register this object as a configuration event handler so we will be notified of camera state changes.
    // See Pylon::CConfigurationEventHandler for details
    m_camera.RegisterConfiguration(this Pylon::RegistrationMode_ReplaceAll Pylon::Ownership_ExternalOwnership);

    // Add the AutoPacketSizeConfiguration and let pylon delete it when not needed anymore.
    m_camera.RegisterConfiguration(new CAutoPacketSizeConfiguration() Pylon::RegistrationMode_Append Pylon::Cleanup_Delete);

   m_camera.Attach(Pylon::CTlFactory::GetInstance().CreateFirstDevice() Pylon::Cleanup_Delete);

    m_camera.Open();

    // Camera may have been disconnected.
    if (!m_camera.IsOpen() || m_camera.IsGrabbing())
    {
      return;
    }

    // Since we may switch between single and continuous shot we must configure the camera accordingly.
    // The predefined configurations are only executed once when the camera is opened.
    // To be able to use them in our use case we just call them explicitly to apply the configuration.
    m_continousConfiguration.OnOpened(m_camera);

    // Start grabbing until StopGrabbing() is called.
    m_camera.StartGrabbing(Pylon::GrabStrategy_OneByOne Pylon::GrabLoop_ProvidedByInstantCamera);

    ui.centralWidget->installEventFilter(this);

    connect(this SIGNAL(OneImageFinishSignal()) this SLOT(OneImageFinishSlot()));

}

void BaslerCamera_RealTimeShow::OnImagesSkipped(Pylon::CInstantCamera& camera size_t countOfSkippedImages)
{

}
void BaslerCamera_RealTimeShow::OnImageGrabbed(Pylon::CInstantCamera& camera const Pylon::CGrabResultPtr& grabResult)
{

  m_mutexLock.lock();

  m_ptrGrabResult = grabResult;

  //qDebug() << __FUNCTION__;

  emit OneImageFinishSignal();

  m_mutexLock.unlock();
  
}

void BaslerCamera_RealTimeShow::OneImageFinishSlot()
{
  //qDebug() << __FUNCTION__;
  ui.centralWidget->update();
}
bool BaslerCamera_RealTimeShow::eventFilter(Qobject *watched QEvent *event)
{
  if (watched == ui.centralWidget && event->type() == QEvent::Paint)
  {
    showImage();
  }
  return false;
}
void BaslerCamera_RealTimeShow::showImage()
{
  
  m_mutexLock.lock();

  //qDebug() << “123“ << endl;

// 新建pylon ImageFormatConverter对象.
CImageFormatConverter formatConverter;

Mat openCvImage;
QPainter painter(ui.centralWidget);

//确定输出像素格式
formatConverter.OutputPixelFormat = PixelType_BGR8packed;
//将抓取的缓冲数据转化成pylon image.
formatConverter.Convert(m_bitmapImage m_ptrGrabResult);

// 将 pylon image转成OpenCV image.
openCvImage = cv::Mat(m_ptrGrabResult->GetHeight() m_ptrGrabResult->G

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。

发表评论

评论列表(条)