QT调用Dalsa线扫相机

网上有很多dalsa相机的MFC的例子。笔者最近做项目用到dalsa线阵相机。学习了好几天。直接上代码:
pro 文件:
#-------------------------------------------------

Project created by QtCreator 2022-07-29T15:17:04

#-------------------------------------------------

QT += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = Dalsa
TEMPLATE = app

The following define makes your compiler emit warnings if you use

any feature of Qt which has been marked as deprecated (the exact warnings

depend on your compiler). Please consult the documentation of the

deprecated API in order to know how to port your code away from it.

DEFINES += QT_DEPRECATED_WARNINGS

You can also make your code fail to compile if you use deprecated APIs.

In order to do so, uncomment the following line.

You can also select to disable deprecated APIs only up to a certain version of Qt.

#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0

CONFIG += c++11

SOURCES +=
main.cpp
mainwindow.cpp

HEADERS +=
mainwindow.h

FORMS +=
mainwindow.ui

Default rules for deployment.

qnx: target.path = /tmp/ T A R G E T / b i n e l s e : u n i x : ! a n d r o i d : t a r g e t . p a t h = / o p t / {TARGET}/bin else: unix:!android: target.path = /opt/ TARGET/binelse:unix:!android:target.path=/opt/{TARGET}/bin
!isEmpty(target.path): INSTALLS += target

INCLUDEPATH += “D:/Program Files/Teledyne DALSA/Sapera/Include”
INCLUDEPATH += “D:/Program Files/Teledyne DALSA/Sapera/Classes/Basic”

LIBS += “D:/Program Files/Teledyne DALSA/Sapera/Lib/Win64/corapi.lib”
LIBS += “D:/Program Files/Teledyne DALSA/Sapera/Lib/Win64/SapClassBasic.lib”

win32:CONFIG(release, debug|release): LIBS += -LC:/opencv/build/x64/vc14/lib/ -lopencv_world341
else:win32:CONFIG(debug, debug|release): LIBS += -LC:/opencv/build/x64/vc14/lib/ -lopencv_world341d

INCLUDEPATH += C:/opencv/build/include
DEPENDPATH += C:/opencv/build/include

中间的lib 和opencv的库使用了绝对地址,需要自己修改

mainwindow.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include
#include “SapClassBasic.h”
#include “opencv2/opencv.hpp”
using namespace cv;
namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
Q_OBJECT

public:
explicit MainWindow(QWidget *parent = nullptr);
~MainWindow();

 static void XferCallbackLft(SapXferCallbackInfo *pInfoLft);

private slots:
void on_pushButton_clicked();

void on_pushButton_2_clicked();

private:
bool InitCarmer();
void printout(QString str);

protected:
SapManager m_pManager;
SapAcqDevice *m_pCamera;
SapBufferWithTrash *m_pBuffer;

SapTransfer* m_pXfer;
SapView *m_pView;
SapFeature *m_pFeature;

private:
Ui::MainWindow *ui;
bool m_Flag = false;//设置标志位,以判定是否有设备
bool initstate=false;
int num;
QList l;
};

#endif // MAINWINDOW_H

cpp

#include “mainwindow.h”
#include “ui_mainwindow.h”
#include
static int m_num=0;
static int nownum=0;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{

ui->setupUi(this);

InitCarmer();

}

MainWindow::~MainWindow()
{
m_pXfer->Destroy();
m_pView->Destroy();
m_pBuffer->Destroy();

m_pCamera->Destroy();

delete ui;

}

void MainWindow::XferCallbackLft(SapXferCallbackInfo *pInfo)
{
// Display the last transferred frame
MainWindow *pView = (MainWindow *)pInfo->GetContext();
BYTE pData;
void pDataAddr = &pData;
BOOL success = pView->m_pBuffer->GetAddress(nownum,&pDataAddr);
if (nownum==0)
nownum=1;
else
nownum=0;
int width = pView->m_pBuffer->GetWidth();
int height = pView->m_pBuffer->GetHeight();
cv::Mat img = cv::Mat::zeros(cv::Size(width, height), CV_8U);
memcpy(img.data, pDataAddr, width
height);
success = pView->m_pBuffer->ReleaseAddress(pDataAddr);
//cv:imshow(“image”, img);
QString q_PathName = QString::number(m_num) + “.bmp”;
std::string str = q_PathName.toStdString();
const char *m_PathName1 = str.c_str();
//printf(m_PathName);
qDebug() << m_PathName1;
cv::imwrite(m_PathName1, img); //可以存图

m_num += 1;

}

bool MainWindow::InitCarmer()
{
char m_SerName[100];
char m_ResName[100];
m_pManager.GetServerName(0, SapManager::ResourceAcqDevice, m_SerName);//CAMERA 相机名称
m_pManager.GetResourceName(1, SapManager::ResourceAcqDevice, m_ResName);//UESR ID,可自行设置
SapLocation loc(m_SerName,0);//默认值0,1会报错
m_pCamera = new SapAcqDevice(loc,“./T_Linea_C2048-7.ccf”);//创建相机对象
m_pBuffer = new SapBufferWithTrash(2,m_pCamera);//创建缓冲区对象
m_pView = new SapView(m_pBuffer);//创建显示区对象
m_pXfer = new SapAcqDeviceToBuf(m_pCamera,m_pBuffer,XferCallbackLft,this);//绑定相机与缓冲区
// m_pFeature = new SapFeature(m_pCamera->GetLocation());//创建Feature对象以获取参数信息
//创建对象资源
if(!m_pCamera->Create())
{
qDebug()<<“create SapAcqDevice error”;
return false;
}
if(!m_pBuffer->Create())
{
qDebug()<<“create SapBufferWithTrash error”;
return false;
}
if(!m_pView->Create())
{
qDebug()<<“create SapView error”;
return false;
}
// if(!m_pFeature->Create())
// {
// qDebug()<<“create SapFeature error”;
// return false;
// }
if(!m_pXfer->Create())
{
qDebug()<<“create SapAcqDeviceToBuf error”;
return false;
}

m_pXfer->Init();
double m_tmp=0;//初始化设备温度值
m_pCamera->GetFeatureValue("DeviceTemperature", &m_tmp);//不可用int型,否则数值不正确
qDebug() << "Device:" << m_SerName <<endl<<"Current Temp:" << m_tmp <<"C" <<"\tUser ID:" <<m_ResName<< endl;//显示设备名,温度和User ID
return  true;

}

void MainWindow::printout(QString str)
{
qDebug() << str;
}

void MainWindow::on_pushButton_clicked()
{
bool success = m_pXfer->Grab();
}

void MainWindow::on_pushButton_2_clicked()
{
bool success = m_pXfer->Freeze();
}

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
Qt是一个跨平台的C++应用程序开发框架,它提供了丰富的工具和库来简化应用程序的开发过程。而Dalsa线扫相机是一种高性能的工业相机,可以用于识别和捕捉高速运动对象。 在Qt调用Dalsa线扫相机需要以下步骤: 1. 首先,需要安装并配置相机的SDK(软件开发工具包)。SDK提供了相机的驱动程序和相关的API(应用程序接口)用于与相机进行通信。 2. 在Qt项目中,需要包含相机的头文件和库文件。在项目文件中添加相机的头文件路径和库文件路径,以便编译器能够找到它们。 3. 创建一个Qt对象来管理相机的连接和操作。可以使用相机的API来初始化相机,设置参数(如曝光时间、增益等),开始采集图像数据等。 4. 在Qt的图形界面中,可以使用QImage或QPixmap类来处理和显示采集到的图像数据。可以使用相机的API将采集到的图像数据转换为Qt能够处理的格式,然后在界面中显示出来。 5. 启动Qt应用程序后,可以通过界面上的按钮或其他交互方式来触发开始和停止相机的采集操作。在触发相机采集后,可以使用Qt的定时器来定期获取相机的图像数据,并更新界面上的显示。 总之,通过Qt可以方便地调用Dalsa线扫相机,并实现图像采集、处理和显示等功能。只要正确配置相机的SDK并使用相机的API,即可在Qt应用程序中与相机进行交互。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值