代码格式化

This commit is contained in:
hehaoyang 2023-10-21 23:39:10 +08:00
parent f0f073da51
commit 5bbc23649b
5 changed files with 90 additions and 85 deletions

View File

@ -142,9 +142,9 @@ void DataBase::initialization()
/* 创建 程序配置信息 表 */
if (!query.exec("CREATE TABLE IF NOT EXISTS [Setting] ("
" [name] TEXT NOT NULL PRIMARY KEY,"
" [value] TEXT"
");"))
" [name] TEXT NOT NULL PRIMARY KEY,"
" [value] TEXT"
");"))
{
qDebug("配置表创建失败");
return;
@ -175,14 +175,14 @@ void DataBase::initialization()
bsd_video_input_source = read_setting("bsd_video_input_source", QString(";;;;;;")).split(";");
bsd_warn_regions = read_setting(
"bsd_warn_regions",
QString("0,0 0,0 0,0 0,0$0,0 0,0 0,0 0,0$0,0 0,0 0,0 0,0*"
"0,0 0,0 0,0 0,0$0,0 0,0 0,0 0,0$0,0 0,0 0,0 0,0*"
"0,0 0,0 0,0 0,0$0,0 0,0 0,0 0,0$0,0 0,0 0,0 0,0*"
"0,0 0,0 0,0 0,0$0,0 0,0 0,0 0,0$0,0 0,0 0,0 0,0*"
"0,0 0,0 0,0 0,0$0,0 0,0 0,0 0,0$0,0 0,0 0,0 0,0*"
"0,0 0,0 0,0 0,0$0,0 0,0 0,0 0,0$0,0 0,0 0,0 0,0"))
.split("*");
"bsd_warn_regions",
QString("0,0 0,0 0,0 0,0$0,0 0,0 0,0 0,0$0,0 0,0 0,0 0,0*"
"0,0 0,0 0,0 0,0$0,0 0,0 0,0 0,0$0,0 0,0 0,0 0,0*"
"0,0 0,0 0,0 0,0$0,0 0,0 0,0 0,0$0,0 0,0 0,0 0,0*"
"0,0 0,0 0,0 0,0$0,0 0,0 0,0 0,0$0,0 0,0 0,0 0,0*"
"0,0 0,0 0,0 0,0$0,0 0,0 0,0 0,0$0,0 0,0 0,0 0,0*"
"0,0 0,0 0,0 0,0$0,0 0,0 0,0 0,0$0,0 0,0 0,0 0,0"))
.split("*");
}
bool DataBase::save_setting()

View File

@ -36,7 +36,7 @@ public:
static DataBase database(void);
static CarInfoInput *get_car_info(void);
static CarInfoInput* get_car_info(void);
static QString get_video_frame_data(int type, int channel, int id);
@ -83,10 +83,10 @@ private:
QDateTime vehicle_status_update_time;
/* 边缘云 Socket (客户端) */
HxSocketUtils *platform;
HxSocketUtils* platform;
/* DebugTool Socket (服务端) */
HxSocketUtils *debug_tool;
HxSocketUtils* debug_tool;
/* 车辆状态信息 */
CarInfoInput car_info;

View File

@ -90,6 +90,9 @@ public slots:
}
}
/**
* @brief
*/
void reconnection()
{
/* 取消已有的连接 */
@ -127,12 +130,15 @@ private:
QString address;
bool is_reconnect = false;
QTcpServer server;
QTcpSocket *socket = nullptr;
QTcpSocket* socket = nullptr;
};
class HxProcessUtils
{
public:
/**
*
*/
static int execute(QString command)
{
auto array = command.split(" ");

View File

@ -1,7 +1,7 @@
#include "HxVideoDevice.h"
/* bsd算法结果处理函数 */
void algorithm_alarm_callback(int nDataChannel, ObjectTrackEventResult *pObjectTrackEventResult, void *pPrivData)
void algorithm_alarm_callback(int nDataChannel, ObjectTrackEventResult* pObjectTrackEventResult, void* pPrivData)
{
Q_UNUSED(nDataChannel);
Q_UNUSED(pPrivData);
@ -36,11 +36,11 @@ void algorithm_alarm_callback(int nDataChannel, ObjectTrackEventResult *pObjectT
TaskDispatch::algorithm_alarm_event(1, 0, pObjectTrackEventResult->nEventType, 0, 0, 0, 0, 0, 0, 0, base64_string, filename);
}
else if (nDataChannel == 1 || /* BSD-右前 */
nDataChannel == 3 || /* BSD-右后 */
nDataChannel == 4 || /* BSD-左前 */
nDataChannel == 5 || /* BSD-左后 */
nDataChannel == 6 || /* BSD-前 */
nDataChannel == 7) /* BSD-后 */
nDataChannel == 3 || /* BSD-右后 */
nDataChannel == 4 || /* BSD-左前 */
nDataChannel == 5 || /* BSD-左后 */
nDataChannel == 6 || /* BSD-前 */
nDataChannel == 7) /* BSD-后 */
{
int channel = 0;
@ -85,17 +85,17 @@ void algorithm_alarm_callback(int nDataChannel, ObjectTrackEventResult *pObjectT
/* 上传 */
TaskDispatch::algorithm_alarm_event(channel,
pObjectTrackEventResult->nDangerLevel,
pObjectTrackEventResult->nEventType,
pObjectTrackEventResult->objInfo[i].nDetectType,
pObjectTrackEventResult->objInfo[i].nLeft,
pObjectTrackEventResult->objInfo[i].nTop,
pObjectTrackEventResult->objInfo[i].nRight,
pObjectTrackEventResult->objInfo[i].nBottom,
pObjectTrackEventResult->objInfo[i].fDist,
pObjectTrackEventResult->objInfo[i].fVelo,
base64_string,
filename);
pObjectTrackEventResult->nDangerLevel,
pObjectTrackEventResult->nEventType,
pObjectTrackEventResult->objInfo[i].nDetectType,
pObjectTrackEventResult->objInfo[i].nLeft,
pObjectTrackEventResult->objInfo[i].nTop,
pObjectTrackEventResult->objInfo[i].nRight,
pObjectTrackEventResult->objInfo[i].nBottom,
pObjectTrackEventResult->objInfo[i].fDist,
pObjectTrackEventResult->objInfo[i].fVelo,
base64_string,
filename);
}
}
}
@ -160,73 +160,72 @@ QString VideoDevice::build_video(int id)
QString url = QString("ftp://%3/%4/%5/alarm/").arg(DataBase::ftp_address, QDateTime::currentDateTime().toString("yyyyMMdd"), DataBase::device_id);
QString filename = QString("%1.mp4").arg(QDateTime::currentDateTime().toString("yyyyMMddHHmmsszzz"));
QtConcurrent::run([=]()
{
if(video_frames_string.contains(id))
{
frame_mutex.lock();
auto first_key = video_frames_string.firstKey();
frame_mutex.unlock();
QtConcurrent::run([=]() {
if (video_frames_string.contains(id))
{
frame_mutex.lock();
auto first_key = video_frames_string.firstKey();
frame_mutex.unlock();
auto start_id = id - frame_fps * 10, end_id = id + frame_fps * 10;
auto start_id = id - frame_fps * 10, end_id = id + frame_fps * 10;
start_id = start_id < first_key ? first_key : start_id;
start_id = start_id < first_key ? first_key : start_id;
qDebug() << "build video; start id = "<<start_id << " end id = " << end_id;
qDebug() << "build video; start id = " << start_id << " end id = " << end_id;
while(true)
{
frame_mutex.lock();
auto last_key = video_frames_string.lastKey();
frame_mutex.unlock();
while (true)
{
frame_mutex.lock();
auto last_key = video_frames_string.lastKey();
frame_mutex.unlock();
// qDebug() << " end id = " << end_id << " last id = "<< last_key;
// qDebug() << " end id = " << end_id << " last id = "<< last_key;
/* 判断最新的视频帧是否超过设定的时间 */
if(last_key >= end_id)
{
frame_mutex.lock();
auto _video_frames_string = video_frames_string;
_video_frames_string.detach();
frame_mutex.unlock();
/* 判断最新的视频帧是否超过设定的时间 */
if (last_key >= end_id)
{
frame_mutex.lock();
auto _video_frames_string = video_frames_string;
_video_frames_string.detach();
frame_mutex.unlock();
VideoWriter writer(filename.toUtf8().data(), CV_FOURCC('m', 'p', '4', 'v'), frame_fps, Size(video_capture.get(CV_CAP_PROP_FRAME_WIDTH), video_capture.get(CV_CAP_PROP_FRAME_HEIGHT)), true);
VideoWriter writer(filename.toUtf8().data(), CV_FOURCC('m', 'p', '4', 'v'), frame_fps, Size(video_capture.get(CV_CAP_PROP_FRAME_WIDTH), video_capture.get(CV_CAP_PROP_FRAME_HEIGHT)), true);
for(int i = start_id; i <= end_id; i++)
{
auto __frame = imdecode(_video_frames_string[i], CV_LOAD_IMAGE_COLOR);
for (int i = start_id; i <= end_id; i++)
{
auto __frame = imdecode(_video_frames_string[i], CV_LOAD_IMAGE_COLOR);
writer.write(__frame);
writer.write(__frame);
msleep(frame_fps);
msleep(frame_fps);
qDebug() << " write "<< filename <<". frame id = " << i;
}
qDebug() << " write " << filename << ". frame id = " << i;
}
writer.release();
writer.release();
qDebug() << "video build finish";
qDebug() << "video build finish";
HxProcessUtils::execute(QString("curl -u %1:%2 %3 --ftp-create-dirs -T %4")
.arg(DataBase::ftp_username,
DataBase::ftp_password,
url,
filename));
HxProcessUtils::execute(QString("curl -u %1:%2 %3 --ftp-create-dirs -T %4")
.arg(DataBase::ftp_username,
DataBase::ftp_password,
url,
filename));
QFile::remove(filename);
QFile::remove(filename);
return;
}
msleep(100);
}
} });
return;
}
msleep(100);
}
} });
return url + filename;
}
void VideoDevice::test(void)
{
ObjectTrackEventResult pObjectTrackEventResult = {0};
ObjectTrackEventResult pObjectTrackEventResult = { 0 };
pObjectTrackEventResult.nFrameId = video_frames_string.lastKey();
pObjectTrackEventResult.nEventType = EVENT_PCW;
pObjectTrackEventResult.nObjectNumber = 1;
@ -257,7 +256,7 @@ QString VideoDevice::snap(Mat frame)
QString VideoDevice::snap(vector<uint8_t> buffer)
{
QByteArray byteArray = QByteArray::fromRawData((const char *)buffer.data(), buffer.size());
QByteArray byteArray = QByteArray::fromRawData((const char*)buffer.data(), buffer.size());
return QString(byteArray.toBase64());
}
@ -338,7 +337,7 @@ void VideoDevice::run()
}
}
int VideoDevice::MvGetFrameBlkInfo(VideoFrameDataInfo *pImageDataInfo)
int VideoDevice::MvGetFrameBlkInfo(VideoFrameDataInfo* pImageDataInfo)
{
Q_UNUSED(pImageDataInfo);
@ -346,14 +345,14 @@ int VideoDevice::MvGetFrameBlkInfo(VideoFrameDataInfo *pImageDataInfo)
if (pImageDataInfo == NULL)
return -1;
pImageDataInfo->pu8VirAddr = (unsigned char *)calloc(pImageDataInfo->u32Width * pImageDataInfo->u32Height * 3, sizeof(unsigned char));
pImageDataInfo->pu8VirAddr = (unsigned char*)calloc(pImageDataInfo->u32Width * pImageDataInfo->u32Height * 3, sizeof(unsigned char));
if (pImageDataInfo->pu8VirAddr == NULL)
return -1;
#endif
return 0;
}
int VideoDevice::MvReleaseFrameBlkInfo(VideoFrameDataInfo *pImageDataInfo)
int VideoDevice::MvReleaseFrameBlkInfo(VideoFrameDataInfo* pImageDataInfo)
{
Q_UNUSED(pImageDataInfo);
@ -370,7 +369,7 @@ int VideoDevice::MvReleaseFrameBlkInfo(VideoFrameDataInfo *pImageDataInfo)
return 0;
}
int VideoDevice::MvConvertImage(VideoFrameDataInfo *pSrcImageDataInfo, VideoFrameDataInfo *pDstImageDataInfo)
int VideoDevice::MvConvertImage(VideoFrameDataInfo* pSrcImageDataInfo, VideoFrameDataInfo* pDstImageDataInfo)
{
Q_UNUSED(pSrcImageDataInfo);
Q_UNUSED(pDstImageDataInfo);

View File

@ -45,9 +45,9 @@ protected:
void run() override;
private:
int MvGetFrameBlkInfo(VideoFrameDataInfo *pImageDataInfo);
int MvReleaseFrameBlkInfo(VideoFrameDataInfo *pImageDataInfo);
int MvConvertImage(VideoFrameDataInfo *pSrcImageDataInfo, VideoFrameDataInfo *pDstImageDataInfo);
int MvGetFrameBlkInfo(VideoFrameDataInfo* pImageDataInfo);
int MvReleaseFrameBlkInfo(VideoFrameDataInfo* pImageDataInfo);
int MvConvertImage(VideoFrameDataInfo* pSrcImageDataInfo, VideoFrameDataInfo* pDstImageDataInfo);
private:
int type;