#include "grabthread_camera01.h"
#include <QDateTime>
#include <QDebug>
#include <QTimer>
grabthread_camera01::grabthread_camera01(Imagebuffer *imageBuffer) : QThread(),
imageBuffer(imageBuffer)
{
stopped = false;
}
void grabthread_camera01::initialize()
{
qDebug() << "SBaslerCameraControl: PylonInitialize initSome";
PylonInitialize();
UserID = string ("23435356");//你的相机ID
/*cameras[i].Attach(tlFactory.CreateDevice(devices[i]));
if (UserID == cameras[i].GetDeviceInfo().GetSerialNumber())
{
m_basler.Attach(CTlFactory::GetInstance().CreateDevice(UserID));
break;
}*/
connectcamera();
}
bool grabthread_camera01::connectcamera()
{
CTlFactory &tlFactory = CTlFactory::GetInstance();
DeviceInfoList_t devices;
if (tlFactory.EnumerateDevices(devices) == 0)
{
throw RUNTIME_EXCEPTION("没有检测到可用相机!");
}
int n = devices.size();
CInstantCameraArray cameras(min(devices.size(), maxCameras));
for (int i = 0; i < (int)cameras.GetSize(); i++)
{
cameras[i].Attach(tlFactory.CreateDevice(devices[i]));
string sn = cameras[i].GetDeviceInfo().GetSerialNumber();
if (sn == UserID )
{
cameras[i].DetachDevice();
//cameras[i].Close();
m_basler.Attach(tlFactory.CreateDevice(devices[i]));
break;
}
cameras[i].DetachDevice();
}
return true;
}
void grabthread_camera01::run()
{
StartAcquire();
}
void grabthread_camera01::CopyToImage(CGrabResultPtr pInBuffer, QImage &OutImage)
{
try {
uchar* buff = (uchar*)pInBuffer->GetBuffer();
int nHeight = pInBuffer->GetHeight();
int nWidth = pInBuffer->GetWidth();
QImage imgBuff(buff, nWidth, nHeight, QImage::Format_Indexed8);
OutImage = imgBuff;
}
catch (GenICam::GenericException &e) {
qDebug() << "CopyToImage Error:" << QString(e.GetDescription());
}
}
int grabthread_camera01::OpenCamera()
{
try {
m_basler.Open();
//获取触发模式
//bool OKopen = m_basler.IsOpen();
m_isOpen = true;
shezhicanshu();
}
catch (GenICam::GenericException &e) {
OutputDebugString(L"OpenCamera Error\n");
qDebug() << "OpenCamera Error" << QString(e.GetDescription());
m_isOpen = false;
return -2;
}
return 0;
}
void grabthread_camera01::onTimerGrabImage()
{
//if (m_isOpenAcquire)
while (!stopped)
{
QImage image;
GrabImage(image, 50);
if (!image.isNull())
{
emit sigCurrentImage01(image);
//imageBuffer->addGrabImage01(image);
qDebug() << "1111";
}
//sleep(20);
}
//QImage image;
//GrabImage(image, 5);
//if (!image.isNull())
//{
// //emit sigCurrentImage(image);
// //imageBuffer->addGrabImage01(image);
// qDebug() << "1234:" ;
// }
//QTimer::singleShot(100,this,SLOT(onTimerGrabImage()));
//sleep(20);
}
int grabthread_camera01::CloseCamera()
{
if (!m_isOpen) {
return -1;
}
try {
if (m_basler.IsOpen()) {
m_basler.DetachDevice();
m_basler.Close();
}
}
catch (GenICam::GenericException &e) {
// OutputDebugString(LPCWSTR(e.GetDescription()));
qDebug() << "CloseCamera Error:" << QString(e.GetDescription());
return -2;
}
return 0;
}
void grabthread_camera01::deleteAll()
{
//停止采集
if (m_isOpenAcquire)
{
StopAcquire();
}
//关闭摄像头
CloseCamera();
//关闭库
qDebug() << "SBaslerCameraControl deleteAll: PylonTerminate";
PylonTerminate();
qDebug() << "SBaslerCameraControl deleteAll: Close";
}
//*************
int grabthread_camera01::shezhicanshu()
{
INodeMap &cameraNodeMap = m_basler.GetNodeMap();
CEnumerationPtr ptrTriggerSel = cameraNodeMap.GetNode("TriggerSelector");
ptrTriggerSel->FromString("FrameStart");
CEnumerationPtr ptrTrigger = cameraNodeMap.GetNode("TriggerMode");
ptrTrigger->SetIntValue(1);
CEnumerationPtr ptrTriggerAcqMode = cameraNodeMap.GetNode("AcquisitionMode");
ptrTriggerAcqMode->FromString("Continuous");
CEnumerationPtr ptrTriggerSource = cameraNodeMap.GetNode("TriggerSource");
ptrTriggerSource->FromString("Software");
String_t str = ptrTriggerSource->ToString();
m_currentMode = QString::fromLocal8Bit(str.c_str());
const CFloatPtr exposureTime = cameraNodeMap.GetNode("ExposureTime");
exposureTime->SetValue(10000);
return 0;
}
long grabthread_camera01::StartAcquire()
{
stopped = false;
m_isOpenAcquire = true;
try {
qDebug() << "SBaslerCameraControl StartAcquire" << m_currentMode;
if (m_currentMode == "Software") {
m_basler.StartGrabbing(GrabStrategy_LatestImageOnly);
onTimerGrabImage();
}
}
catch (GenICam::GenericException &e) {
// OutputDebugString(L"StartAcquire error:");
qDebug() << "StartAcquire Error:" << QString(e.GetDescription());
return -2;
}
return 0;
}
long grabthread_camera01::StopAcquire()
{
m_isOpenAcquire = false;
qDebug() << "SBaslerCameraControl StopAcquire";
try {
if (m_basler.IsGrabbing())
{
m_basler.StopGrabbing();
}
}
catch (GenICam::GenericException &e)
{
//OutputDebugString(LPCWSTR(e.GetDescription()));
qDebug() << "StopAcquire Error:" << QString(e.GetDescription());
return -2;
}
return 0;
}
long grabthread_camera01::GrabImage(QImage &image, int timeout)
{
try {
if (!m_basler.IsGrabbing()) {
StartAcquire();
}
CGrabResultPtr ptrGrabResult;
if (m_currentMode == "Software")
{
if (m_basler.WaitForFrameTriggerReady(1000, TimeoutHandling_Return))
{
m_basler.ExecuteSoftwareTrigger();
m_basler.RetrieveResult(timeout, ptrGrabResult, TimeoutHandling_Return);
}
}
else if (m_currentMode == "Line1")
{
m_basler.RetrieveResult(timeout, ptrGrabResult, TimeoutHandling_Return);
}
if (ptrGrabResult == NULL)
{
return -5;
}
if (ptrGrabResult->GrabSucceeded()) {
qDebug() << "what: ptrGrabResult GrabSucceeded";
if (!ptrGrabResult.IsValid()) { OutputDebugString(L"GrabResult not Valid Error\n"); return -1; }
EPixelType pixelType = ptrGrabResult->GetPixelType();
switch (pixelType) {
case PixelType_Mono8: {
CopyToImage(ptrGrabResult, image);
} break;
case PixelType_BayerRG8: { qDebug() << "what: PixelType_BayerRG8"; } break;
default: qDebug() << "what: default"; break;
}
}
else {
qDebug() << "Grab Error!!!";
// OutputDebugString(L"Grab Error!!!");
return -3;
}
}
catch (GenICam::GenericException &e) {
// OutputDebugString(L"GrabImage Error\n");
qDebug() << "GrabImage Error:" << QString(e.GetDescription());
// OutputDebugString((e.GetDescription()));
return -2;
}
catch (...) {
OutputDebugString(L"ZP 11 Shot GetParam Try 12 No know Error\n");
return -1;
}
return 0;
}
void grabthread_camera01::stop()
{
stopped = true;
StopAcquire();
}
没有合适的资源?快使用搜索试试~ 我知道了~
QT调用basler SDK 多线程多相机采集代码
共65个文件
tlog:14个
obj:12个
cpp:12个
4星 · 超过85%的资源 需积分: 34 112 下载量 138 浏览量
2019-09-11
22:59:10
上传
评论 2
收藏 25.05MB ZIP 举报
温馨提示
basler相机的多个相机并多线程采集并显示,在程序中采集线程两个,通过相机的serialNumber进行相机的连接,采集的结构Ptrresult通过信号和槽进行连接,在widget中控件显示。学习初期和大家交流。没有配置,需要自己配置属性表。
资源推荐
资源详情
资源评论
收起资源包目录
duoxianji_test 03_steady.zip (65个子文件)
x64
Debug
grabthread_camera02.obj 511KB
moc_duoxiangjiwindow.obj 479KB
duoxianji_test.log 397B
controller.obj 495KB
grabthread_camera01.obj 511KB
moc_controller.obj 473KB
moc_picthread.obj 376KB
qt_work.log 7KB
vc140.pdb 5.57MB
main.obj 486KB
moc_grabthread_camera02.obj 181KB
moc_grabthread_camera01.obj 181KB
duoxiangjiwindow.obj 710KB
duoxianji_test.tlog
link.read.1.tlog 21KB
link.command.1.tlog 17KB
CL.command.1.tlog 87KB
custombuild.write.1.tlog 938B
CL.write.1.tlog 30KB
moc.write.1u.tlog 1KB
moc.read.1u.tlog 598B
uic.read.1u.tlog 126B
custombuild.read.1.tlog 986B
CL.read.1.tlog 2.64MB
duoxianji_test.write.1u.tlog 64KB
custombuild.command.1.tlog 3KB
uic.write.1u.tlog 252B
link.write.1.tlog 8KB
duoxianji_test.lastbuildstate 204B
picthread.obj 520KB
imagebuffer.obj 140KB
main.cpp 195B
controller.cpp 1KB
imagebuffer.cpp 3KB
picthread.cpp 4KB
imagebuffer.h 2KB
duoxiangjiwindow.ui 6KB
picthread.h 970B
duoxianji_test.vcxproj.user 1KB
duoxianji_test.VC.db 53.15MB
.vs
duoxianji_test
v14
.suo 76KB
ui_duoxiangjiwindow.h 7KB
grabthread_camera01.h 2KB
duoxianji_test.vcxproj 21KB
grabthread_camera01.cpp 7KB
duoxianji_test.sln 947B
duoxianji_test.pro 1KB
release
moc_predefs.h.cbt 61B
controller.h 632B
duoxianji_test.pro.user 23KB
duoxianji_test.vcxproj.filters 4KB
grabthread_camera02.h 2KB
duoxiangjiwindow.h 741B
grabthread_camera02.cpp 6KB
debug
moc_picthread.cpp 3KB
moc_predefs.h 276B
moc_duoxiangjiwindow.cpp 4KB
moc_grabthread_camera01.cpp 5KB
moc_grabthread_camera02.cpp 4KB
duoxianji_test.pdb 6.29MB
moc_predefs.h.cbt 59B
moc_controller.cpp 3KB
duoxianji_test.ilk 2.1MB
duoxianji_test.exe 357KB
duoxiangjiwindow.cpp 2KB
.qmake.stash 1KB
共 65 条
- 1
资源评论
- 黑化咸鱼2022-11-23请问QT显示dependent 'controler.cpp' does not exist.是什么原因啊?
乌鸦小跟班
- 粉丝: 62
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功