QT c++ 海康红外热像仪

//本文描述2通道海康通道红外热像仪预览和抓图

#include "mainwindow.h"

#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)

: QMainWindow(parent)

, ui(new Ui::MainWindow)

{

ui->setupUi(this);

userID=-1;

previewID=-1;

if(initSDK())

qDebug()<<"SDK init Success!\n";

}

long MainWindow::play(HWND hWnd, NET_DVR_PREVIEWINFO &struPlayInfo)

{

struPlayInfo={0};

struPlayInfo.hPlayWnd = hWnd;//需要 SDK 解码时句柄设为有效值,仅取流不解码时可设为空

struPlayInfo.lChannel = 1;//预览通道号

struPlayInfo.dwStreamType = 0;//码流类型:0-主码流,1-子码流,2-三码流,3-虚拟码流,以此类推

struPlayInfo.dwLinkMode = 0;//0- TCP 方式,1- UDP 方式,2- 多播方式,3- RTP 方式,4-RTP/RTSP,5-RSTP/HTTP

struPlayInfo.bBlocked = 1;//0- 非阻塞取流,1- 阻塞取流

long IRealPlayHandle = NET_DVR_RealPlay_V40(userID, &struPlayInfo, NULL, NULL);

if(IRealPlayHandle <0)

{

qDebug() << "NET_DVR_RealPlay_V40 error;error number " <<NET_DVR_GetLastError();

QMessageBox::warning(this,"error","NET_DVR_RealPlay_V40 error;error number "+QString::number(NET_DVR_GetLastError()));

NET_DVR_Logout(userID);

userID=-1;

return -1;

}

return IRealPlayHandle;

}

long MainWindow::play2(HWND hWnd, NET_DVR_PREVIEWINFO &struPlayInfo)

{

struPlayInfo={0};

struPlayInfo.hPlayWnd = hWnd;//需要 SDK 解码时句柄设为有效值,仅取流不解码时可设为空

struPlayInfo.lChannel = 2;//预览通道号

struPlayInfo.dwStreamType = 0;//码流类型:0-主码流,1-子码流,2-三码流,3-虚拟码流

struPlayInfo.dwLinkMode = 0;//0- TCP 方式,1- UDP 方式,2- 多播方式,3- RTP 方式

//4-RTP/RTSP,5-RSTP/HTTP

struPlayInfo.bBlocked = 1;//0- 非阻塞取流,1- 阻塞取流

long IRealPlayHandle = NET_DVR_RealPlay_V40(userID, &struPlayInfo, NULL, NULL);

if(IRealPlayHandle <0)

{

qDebug() << "NET_DVR_RealPlay_V40 error;error number " <<NET_DVR_GetLastError();

QMessageBox::warning(this,"error","NET_DVR_RealPlay_V40 error;error number "+QString::number(NET_DVR_GetLastError()));

NET_DVR_Logout**(userID);**

userID=-1;

return -1;

}

return IRealPlayHandle;

}

bool MainWindow::initSDK()

{

bool isok = NET_DVR_Init();

if(isok == false)

{

qDebug()<< "NET_DVR_Init error;error number is " <<NET_DVR_GetLastError();

QMessageBox::warning(this,"error","NET_DVR_Init error;error number is "+QString::number(NET_DVR_GetLastError()));

return isok;

}

//设置连接时间与重连时间

NET_DVR_SetConnectTime(2000, 1);

NET_DVR_SetReconnect(10000, true);

return isok;

}

bool MainWindow::uninitSDK()//好像没啥效果

{

bool isok = NET_DVR_Cleanup();

if(isok == false)

{

qDebug()<< "NET_DVR_Cleanup error;error number is " <<NET_DVR_GetLastError();

QMessageBox::warning(this,"error","NET_DVR_Cleanup error;error number "+QString::number(NET_DVR_GetLastError()));

return isok;

}

return isok;

}

MainWindow::~MainWindow()

{ uninitSDK();

delete ui;

}

void MainWindow::on_PreviewButton_clicked()

{

Preview_Channel1();

Preview_Channel2();

}

void MainWindow::Preview_Channel1()//通道1

{

if(userID==-1)

{

qDebug() <<"Need Login!\n";

QMessageBox::warning(this,"error","Need Login!");

return;

}

HWND hWnd = (HWND)ui->label ->winId();//显示到label

NET_DVR_PREVIEWINFO struPlayInfo;

previewID = play(hWnd, struPlayInfo);

if(previewID==-1)

{

return;

}

qDebug()<<"channel 1 Preview Success!" << userID;

}

void MainWindow::Preview_Channel2()//通道2

{

if(userID==-1)

{

qDebug() <<"Need Login!\n";

QMessageBox::warning(this,"error","Need Login!");

return;

}

HWND hWnd = (HWND)ui->label2->winId();//显示到label2

NET_DVR_PREVIEWINFO struPlayInfo;

previewID2 = play2(hWnd, struPlayInfo);

if(previewID==-1)

{

return;

}

qDebug()<<"channel 2 Preview Success!" << userID;

}

void MainWindow::on_LoginButton_clicked()

{

NET_DVR_DEVICEINFO_V30 DeviceInfoTmp;

QSettings settings("./cameraConfig.ini", QSettings::IniFormat);

QSettings::Status status = settings.status();

// 获取指定键值示例

QString Ip = settings.value("ip_address/ip","192.168.6.208").toString();

int Port = settings.value("ip_address/port",8000).toInt();

userID=NET_DVR_Login_V30(Ip.toUtf8().data(),Port,(char *)"admin",(char *)"123456",&DeviceInfoTmp);//用户名和密码,读者可以加到配置文件里

if(userID<0)

{

qDebug() << "NET_DVR_Login_V30 error;" << "error number is " << NET_DVR_GetLastError();

QMessageBox::warning(this,"error","NET_DVR_Login_V30 error;error number "+QString::number(NET_DVR_GetLastError()));

return;

}

qDebug()<<"Login Success,userID:" << userID;

qDebug()<<"Login Success,userID:\n" ;

}

void MainWindow::on_StopPreviewButton_clicked()//两通道一起停

{

if(previewID!=-1)

{

if**(NET_DVR_StopRealPlay**(previewID)==false)

{

qDebug() << "NET_DVR_StopRealPlay error;" << "error number is " << NET_DVR_GetLastError();

QMessageBox::warning(this,"error","NET_DVR_StopRealPlay error;error number "+QString::number(NET_DVR_GetLastError()));

return;

}

previewID=-1;

qDebug() <<"Stop Preview1 Success!\n";

}

//------------------------

if(previewID2!=-1)

{

if(NET_DVR_StopRealPlay(previewID2)==false)

{

qDebug() << "NET_DVR_StopRealPlay error;" << "error number is " << NET_DVR_GetLastError();

QMessageBox::warning(this,"error","NET_DVR_StopRealPlay error;error number "+QString::number(NET_DVR_GetLastError()));

return;

}

previewID2=-1;

qDebug() <<"Stop Preview2 Success!\n";

}

}

void MainWindow::on_CaptureButton_clicked()//抓图

{

//channel1

if(userID!=-1)

{

NET_DVR_JPEGPARA IpJpegPara2;

IpJpegPara2.wPicQuality=0;

IpJpegPara2.wPicSize=0xff;

QDateTime current_date_time =QDateTime::currentDateTime();//当前时间

QString current_date =current_date_time.toString("yyyy-MM-dd_hh-mm-ss_zzz");//转换格式

current_date="d:\\Capture_Pic\\"+current_date+".jpg";//jpg格式

char* fileName;

QByteArray ba = current_date.toLatin1(); //

fileName=ba.data();

//channel2

if(NET_DVR_CaptureJPEGPicture(userID,1,&IpJpegPara2,fileName)==false)

{

qDebug() << "NET_DVR_CaptureJPEGPicture error;" << "error number is " << NET_DVR_GetLastError();

QMessageBox::warning(this,"error","NET_DVR_CaptureJPEGPicture error;error number "+QString::number(NET_DVR_GetLastError()));

return;

}

qDebug() <<"Capture Success!\n";

}

}

void MainWindow::on_LogoutButton_clicked()//好像没啥用,保留着

{

if(userID!=-1)

{

if(NET_DVR_Logout(userID)==false)

{

qDebug() << "NET_DVR_Logout error;" << "error number is " << NET_DVR_GetLastError();

QMessageBox::warning(this,"error","NET_DVR_Logout error;error number "+QString::number(NET_DVR_GetLastError()));

return;

}

userID=-1;

qDebug() <<"Logout Success!\n";

}

}

相关推荐
小唐C++1 分钟前
C++小病毒-1.0勒索
开发语言·c++·vscode·python·算法·c#·编辑器
S-X-S7 分钟前
集成Sleuth实现链路追踪
java·开发语言·链路追踪
北 染 星 辰29 分钟前
Python网络自动化运维---用户交互模块
开发语言·python·自动化
佳心饼干-41 分钟前
数据结构-栈
开发语言·数据结构
我们的五年42 分钟前
【C语言学习】:C语言补充:转义字符,<<,>>操作符,IDE
c语言·开发语言·后端·学习
灯火不休ᝰ1 小时前
[java] java基础-字符串篇
java·开发语言·string
励志去大厂的菜鸟1 小时前
系统相关类——java.lang.Math (三)(案例详细拆解小白友好)
java·服务器·开发语言·深度学习·学习方法
w(゚Д゚)w吓洗宝宝了1 小时前
单例模式 - 单例模式的实现与应用
开发语言·javascript·单例模式
siy23331 小时前
【c语言日寄】Vs调试——新手向
c语言·开发语言·学习·算法
vd_vd1 小时前
Redis单线程为什么能这么快
java·开发语言