#include "Qt_Dalsa01.h"
#include "stdafx.h"
#include "SapClassBasic.h"
#include "SapClassGui.h"
#include "qdebug"
#include <opencv.hpp>
#include "highgui.hpp"
#include "imgproc/imgproc_c.h"
#include <core/core.hpp>
#pragma execution_character_set("utf-8")
using namespace std;
static int MAX_BUFFER = 15;
static QStringList qtDeviceList;
//static SapAcqDevice *m_AcqDevice;
static SapBuffer *m_Buffers;
static SapBuffer *m_pBuffer; // Pointer to a SapBuffer object
static const char* m_PathName;
static int m_num;
static int m_Type;
static CString m_Options;
static int m_StartFrame;
void Qt_Dalsa01::XferCallback(SapXferCallbackInfo *pInfo)
{
// Display the last transferred frame
Qt_Dalsa01 *pView = (Qt_Dalsa01 *)pInfo->GetContext();
qDebug() << "XferCallback";
BYTE pData;
void *pDataAddr = &pData;
BOOL success = pView->m_Buffers->GetAddress(&pDataAddr);
qDebug() << 0;
int width = pView->m_Buffers->GetWidth();
int height = pView->m_Buffers->GetHeight();
cv::Mat img = cv::Mat::zeros(cv::Size(width, height), CV_8U);
memcpy(img.data, pDataAddr, width*height);
//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;
}
void Qt_Dalsa01::getDalsaDeviceList()
{
SapManager m_SapManager;
QString qtServername;
//qDebug() << m_SapManager.GetServerCount();
if (m_SapManager.GetServerCount()==1)
{
qDebug() << "Device List NULL";
return;
}
for (int i = 1; i < m_SapManager.GetServerCount(); i++)
{
// Does this server support "Acq" (frame-grabber) or "AcqDevice" (camera)?
char name[128];
char device[128];
if (m_SapManager.GetServerName(i, name, sizeof(name)))
{
qtServername = QString(QLatin1String(name));
qtDeviceList << qtServername;
//qDebug() << "qtDevicename::"<< qtServername;
qDebug() << "GetServerCount::" << m_SapManager.GetServerCount();
//qDebug() <<"GetServerIndex"<< m_SapManager.GetServerIndex(name);
qDebug() << m_SapManager.GetResourceCount(name, SapManager::ResourceAcqDevice);
for (int j = 0; j < m_SapManager.GetResourceCount(name, SapManager::ResourceAcqDevice); j++)
{
m_SapManager.GetResourceName(name, SapManager::ResourceAcqDevice, j, device, sizeof(device));
qDebug() << "device::" << QString(QLatin1String(device));
}
}
// At least one server must be available
if (qtDeviceList.length() <= 0)
{
qDebug() << "Device List NULL";
return;
}
}
}
Qt_Dalsa01::Qt_Dalsa01(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
// Transfer event handler is called each time a complete frame is transferred
m_num = 0;
connect(ui.pushButton, &QPushButton::clicked, [=]() {
QString q_PathName = QString::number(m_num) + ".bmp";
std::string str = q_PathName.toStdString();
const char* ch = str.c_str();
//printf(m_PathName);
qDebug() << ch;
// Define objects
//m_AcqDevice = new SapAcqDevice(dlg.GetLocation(), dlg.GetConfigFile());
getDalsaDeviceList();
qDebug() << "getDeviceList finish::"<<qtDeviceList.length();
if (qtDeviceList.length()<1)
{
return;
}
std::string deviceName = qtDeviceList[0].toStdString();
const char* cdeviceName = deviceName.c_str();
SapXferCallbackInfo *pInfo;
//m_AcqDevice = new SapAcqDevice(SapLocation("X64 - CL_1", 0), "MyCamera.ccf");
qDebug() << 1;
m_AcqDevice = new SapAcqDevice(SapLocation(cdeviceName, 0), "1.ccf");
//char FeatureValue[128];
//char deviceModelName[128];
//m_AcqDevice->GetFeatureValue("DeviceModelName", deviceModelName,sizeof(deviceModelName)); //Linea M4096-7um
//qDebug() << "deviceModelName::";
//printf(deviceModelName);
//QString qdeviceModelName = QString(QLatin1String(deviceModelName));
//qDebug() << "qdeviceModelName::"<< qdeviceModelName;
//char deviceUserId[128];
//m_AcqDevice->GetFeatureValue("DeviceUserID", deviceUserId,sizeof(deviceUserId)); //空
//qDebug() << "deviceUserId::" ;
//printf(deviceUserId);
//QString qdeviceUserId = QString(QLatin1String(deviceUserId));
//qDebug() << "qdeviceUserId::" << qdeviceUserId;
//SapBuffer* pBuffer =new SapBuffer(1, m_AcqDevice, SapBuffer::MemoryType::ScatterGather);
//m_Buffers = new SapBufferWithTrash(MAX_BUFFER, m_AcqDevice);
m_Buffers = new SapBuffer(15, m_AcqDevice);
m_View = new SapView(m_Buffers);
m_Xfer = new SapAcqDeviceToBuf(m_AcqDevice, m_Buffers, XferCallback, this);
bool success = m_AcqDevice->Create();
success = m_Buffers->Create();
success = m_View->Create();
success = m_Xfer->Create();
m_Xfer->Init();
// Start a continuous transfer (live grab)
success = m_Xfer->Grab();
printf("Press any key to stop grab");// << "Press any key to stop grab" << endl;
getchar();
// Stop the transfer and wait (timeout = 5 seconds)
success = m_Xfer->Freeze();
success = m_Xfer->Wait(5000);
printf("Press any key to terminate");
getchar();
// Release resources for all objects
success = m_Xfer->Destroy();
success = m_View->Destroy();
success = m_Buffers->Destroy();
success = m_AcqDevice->Destroy();
});
// Free all objects
// Note that the delete operator actually calls the Dispose method
//delete m_Xfer;
//delete m_View;
//delete m_Buffers;
//delete m_AcqDevice;
}
Qt_Dalsa01_QT调用Dalsa线扫相机
版权申诉
5星 · 超过95%的资源 128 浏览量
2021-09-11
04:27:45
上传
评论 2
收藏 4KB ZIP 举报
心梓
- 粉丝: 808
- 资源: 8057
- 1
- 2
- 3
- 4
前往页