打开__DEBUG宏后会在系统配置页面显示测试图片按钮方便测试

1600-900
Jeffrey_Li 2 years ago
parent ee453f2857
commit 5b66880fc9

@ -1,5 +1,5 @@
#include "alg_jd.h"
#include "common.h"
#include <direct.h> //所需的库文件
// Remove the bounding boxes with low confidence using non-maxima suppression
static void post_process(cv::Mat& frame, std::vector<cv::Mat>& outs, std::vector<std::pair<int, cv::Rect> > &results);
@ -19,40 +19,8 @@ static int inpHeight = 416; // Height of network's input image
static std::vector<std::string> classes;
bool AlgJd::init()
bool AlgJd::init(QString model_path, QString jpg_path)
{
QString model_path;
QString jpg_path;
std::fstream cfg_file;
cfg_file.open("../conf/conf.txt");
if (!cfg_file.is_open())
{
std::cout << "Error: Open config file " << "../conf/conf.txt" << std::endl;
return false;
}
while (!cfg_file.eof())
{
char tmp[256] = "";
cfg_file.getline(tmp, 256);
std::string line(tmp);
if (line.length() > 0)
{
size_t pos = line.find('=');
std::string tmp_key = line.substr(0, pos);
if (tmp_key == "MODELPATH")
{
model_path = line.substr(pos + 1).c_str();
}
if (tmp_key == "JPGPATH")
{
jpg_path = line.substr(pos + 1).c_str();
}
}
}
cfg_file.close();
//std::cout << "MODEL PATH IS " << model_path.toStdString().c_str() << std::endl;
// Load names of classes
std::string classesFile = "../model/jd.names";

@ -8,11 +8,11 @@
#include <opencv2/highgui.hpp>
#include <iostream>
#include <fstream>
#include "common.h"
class AlgJd
{
public:
bool init();
bool init(QString model_path, QString jpg_path);
bool test_detect();
bool test_detect_batcht(int shoot);
int detect(cv::Mat& in, cv::Mat &out, std::vector<std::pair<int, cv::Rect> > &results);

@ -7,23 +7,7 @@
#include <QtCore\qcryptographichash.h>
#include <QtCore\qprocess.h>
// 主界面基本参数配置文件
#define CONFIGURE_FILE "../conf/conf.txt"
// 相机旋转角度配置文件
#define ROTATE_FILE "../conf/rotate.txt"
#define MODBUS_CONFIGURE_FILE "../conf/modbus.txt"
#define PLC_CONFIG_FILE "../conf/plc.txt"
#define SELECT_RECTS_FILE "../conf/SelectRects%d%d.txt"
#define STATISTIC_FILE "../conf/camera%d_statistic.txt"
#define ALARM_RECORD_FILE "alarm.txt"
#define OUTPUT_HIGH_WIDTH 20000 //输出信号的脉冲宽度,微秒
#define OP_TIME 300 //OP权限时长默认300秒
#define ADMIN_TIME 600 //ADMIN权限时长默认300秒
#define STOP_SECONDS 3 //检查多少次不变触发自动换班
int g_op_time; //OP权限时长默认300秒
@ -41,7 +25,9 @@ QDateTime g_ts_start;
extern SingleCamInfoStruct SingleCamInfo[NumberOfSupportedCameras];
AlgJd alg_jd[NumberOfSupportedCameras]; //检测胶点的AI算法
#ifdef __DEBUG
AlgJd alg_test;//test AI算法
#endif
QThread* pThread[NumberOfSupportedCameras];
//巴鲁夫相机相关
@ -293,7 +279,7 @@ Cigarette::Cigarette(QWidget *parent)
{
if(SingleCamInfo[i].Detect){
cam_status_mat[i]->setStyleSheet(tr("background-color: rgb(0, 170, 0);"));
if (!alg_jd[i].init())
if (!alg_jd[i].init(g_sys_conf.model_path,g_sys_conf.jpg_path))
{
QMessageBox::information(NULL, QStringLiteral("系统自检失败"), QStringLiteral("AI模型1初始化失败请检查程序完整性"), QMessageBox::Ok);
exit(-1);
@ -301,7 +287,9 @@ Cigarette::Cigarette(QWidget *parent)
CreatWorkThread(SingleCamInfo[i].CamClass, i, this);
}
}
#ifdef __DEBUG
alg_test.init(g_sys_conf.model_path,g_sys_conf.jpg_path);
#endif
//自动打开所有相机
if (g_sys_conf.auto_open == 1)
{
@ -651,6 +639,10 @@ void Cigarette::on_btn_setup_released()
{
dialog_setup = new DialogSetup(this);
connect(dialog_setup, SIGNAL(system_exit()), this, SLOT(OnExit()));
#ifdef __DEBUG
connect(dialog_setup, SIGNAL(_testimg()), this, SLOT(TestImg()));
connect(dialog_setup, SIGNAL(_testimgs()), this, SLOT(TestImgs()));
#endif
dialog_setup->setModal(true);
dialog_setup->show();
dialog_setup->move((this->width() - dialog_setup->width()) / 2, (this->height() - dialog_setup->height()) / 2);
@ -659,7 +651,60 @@ void Cigarette::on_btn_setup_released()
QMessageBox::information(NULL, QStringLiteral("权限检查"), QStringLiteral("请先点击解锁按钮,进入管理员模式"), QMessageBox::Ok);
}
}
#ifdef __DEBUG
void Cigarette::TestImg()
{
QString srcDirPath = QString::fromStdString(SelectFileOFN());
//输入图像
std::cout << "open file------ " << srcDirPath.toStdString() << std::endl;
cv::Mat imagein = cv::imread(srcDirPath.toStdString(), cv::IMREAD_COLOR);
if (!imagein.data)
{
return;
}
std::vector<std::pair<int, cv::Rect> > results;
cv::Mat output;
alg_test.detect(imagein, output,results);
cv::imshow("TestImg", output);
cv::waitKeyEx(1);
}
void Cigarette::TestImgs()
{
QString srcDirPath = QString::fromStdString(SelectDirIFD());
vector<string> files;
std::cout << "srcDirPath=" << srcDirPath.toStdString() << std::endl;
srcDirPath += "/";
//获取该路径下的所有文件
getFiles(srcDirPath.toStdString() + "*.jpg", files);
if (files.size() == 0)
{
QMessageBox::StandardButton result = QMessageBox::information(NULL, QStringLiteral("提示"), QStringLiteral("没有找到图片"));
return;
}
for (int index = 0; index < files.size(); index++)
{
//输入图像
std::cout << "open file------ " << files[index] << std::endl;
cv::Mat imagein = cv::imread(srcDirPath.toStdString() + files[index], cv::IMREAD_COLOR);
if (!imagein.data)
{
break;
}
cv::Mat output;
std::vector<std::pair<int, cv::Rect> > results;
alg_test.detect(imagein, output,results);
cv::imshow("TestImg", output);
int k = cv::waitKeyEx(1);
if (k == 27)break;//ESC键
QCoreApplication::processEvents();
}
}
#endif
//管理员登陆
void Cigarette::OnAdmin()
{

@ -42,10 +42,9 @@
#include <QFileInfoList>
#include <Windows.h>
#include <QSignalMapper>
#include <QSharedPointer>
#include <common.h>
class QTimer;
#define OPEN true
@ -117,8 +116,11 @@ private slots :
void OnOp();
void OnExit();
void OnRestart();
void OnAdmin();
#ifdef __DEBUG
void TestImg();
void TestImgs();
#endif
private:
Ui::CigaretteClass ui;
DialogSetupPasswd *dialog_setup_passwd;

@ -1,6 +1,8 @@
#include "common.h"
#include <string>
#include "stdarg.h"
#include <io.h>
int string_split(std::string str, std::string pattern,std::vector<std::string> &out)
{
std::string::size_type pos;
@ -113,4 +115,247 @@ bool CheckSelectRects(
}
}
return false;
}
void getFiles(std::string path, std::vector<std::string>& files)
{
//文件句柄
intptr_t hFile = 0;
//文件信息
struct _finddata_t fileinfo;
std::string p;
if ((hFile = _findfirst(p.assign(path).c_str(), &fileinfo)) != -1)
{
do
{
if (!(fileinfo.attrib & _A_SUBDIR))
{
files.push_back(fileinfo.name);
}
} while (_findnext(hFile, &fileinfo) == 0);
_findclose(hFile);
}
}
std::string WstringToString(std::wstring wstr)
{
int nLen = wcslen(wstr.c_str());
std::string str;
str.resize(nLen * 2, ' ');
int nResult = WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)wstr.c_str(), -1, (LPSTR)str.c_str(), nLen * 2, NULL, NULL);
return str;
}
/*
TCHAR*char*
*/
char* LPWSTR2LPSTR(LPWSTR lpwszStrIn)
{
LPSTR pszOut = NULL;
if (lpwszStrIn != NULL) {
int nInputStrLen = wcslen(lpwszStrIn);
int nOutputStrLen = WideCharToMultiByte(CP_ACP, 0, lpwszStrIn, nInputStrLen, NULL, 0, 0, 0) + 2;
pszOut = new char[nOutputStrLen];
if (pszOut != NULL) {
memset(pszOut, 0x00, nOutputStrLen);
WideCharToMultiByte(CP_ACP, 0, lpwszStrIn, nInputStrLen, pszOut, nOutputStrLen, 0, 0);
}
}
return pszOut;
}
//从string s的位置pos开始向后找找到第一个等于x的位置返回其位置
//找到,返回找到的位置,找不到返回-1
int __find(const std::string s, const int start, const char x) {
if (start >= s.length())return -1;
for (int i = start; i < s.length(); ++i) {
if (s[i] == x) return i;
}
return -1;
}
//双斜杠转单斜杠
void pathConvert_Double2Single(std::string& s) {
int start = 0;
while (start < s.length()) {
int pos = s.find('\\', start);
if (pos == -1)break;
s.replace(pos, 1,"/");
start = pos + 1;
}
}
int CALLBACK BrowseCallbackProc(
HWND hwnd, UINT uMsg, LPARAM /*lParam*/, LPARAM lpData)
{
LPWSTR buf[1000];
GetCurrentDirectory(1000, (LPWSTR)buf);
if (uMsg == BFFM_INITIALIZED)
{
SendMessage(hwnd, BFFM_SETSELECTION, (WPARAM)TRUE, (LPARAM)buf);
}
return 0;
}
std::string SelectDirBRI()
{
BROWSEINFO bi;
bi.hwndOwner = NULL;
bi.pidlRoot = CSIDL_DESKTOP;
bi.pszDisplayName = NULL;
bi.lpszTitle = NULL;//显?位于对话框左上部的提?信息
bi.ulFlags = BIF_DONTGOBELOWDOMAIN | BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE;//有新建?件夹按钮
bi.lpfn = BrowseCallbackProc;
bi.iImage = 0;
LPITEMIDLIST pidl = SHBrowseForFolder(&bi);//调?选择对话框
if (pidl == NULL)
{
std::cout << "没有选择目录" << std::endl;
return "";
}
TCHAR strFolder[MAX_PATH];
SHGetPathFromIDList(pidl, strFolder);
std::string sFolder = "";
sFolder = WstringToString(strFolder);
int pos = sFolder.find('\0');
if (pos)
{
sFolder = sFolder.substr(0, pos);
}
return sFolder;
}
std::string SelectFileOFN()
{
OPENFILENAME ofn;//#include <Commdlg.h>
TCHAR szOpenFileNames[80 * MAX_PATH] = { 0 };
TCHAR szPath[MAX_PATH];
TCHAR szFileName[80 * MAX_PATH];
int nLen = 0;
TCHAR* p = NULL;
ZeroMemory(&ofn, sizeof(ofn));
// 结构体大小
ofn.lStructSize = sizeof(ofn);
// 拥有着窗口句柄
ofn.hwndOwner = NULL;
// 接收返回的文件名注意第一个字符需要为NULL
ofn.lpstrFile = szOpenFileNames;
// 缓冲区长度
ofn.nMaxFile = sizeof(szOpenFileNames);
// _T可替换为TEXT使用_T需要引tchar.h
ofn.lpstrFile[0] = _T('\0');
// 设置过滤
ofn.lpstrFilter = _T("All\0*.*\0.mp4\0*.mp4\0.avi\0*.avi\0.mkv\0*.mkv\0.rmvb\0*.rmvb\0.f4v\0*.f4v\0.flv\0*.flv\0.m4v\0*.m4v\0.mpg\0*.mpg\0\0");
// 过滤器索引
ofn.nFilterIndex = 1;
// 窗口标题
ofn.lpstrTitle = _T("请选择图片");
// 文件必须存在、允许多选、隐藏只读选项、对话框使用资源管理器风格的用户界面
// 官方文档https://docs.microsoft.com/en-us/windows/win32/api/commdlg/ns-commdlg-openfilenamea
ofn.Flags = OFN_FILEMUSTEXIST | OFN_ALLOWMULTISELECT | OFN_HIDEREADONLY | OFN_EXPLORER;
// 如果打开文件失败,则不操作
if (!::GetOpenFileName(&ofn)) {
return "";
}
// 把第一个文件名前的复制到szPath,即:
// 如果只选了一个文件,就复制到最后一个'/'
// 如果选了多个文件,就复制到第一个NULL字符
lstrcpyn(szPath, szOpenFileNames, ofn.nFileOffset);
// 当只选了一个文件时,下面这个NULL字符是必需的.
// 这里不区别对待选了一个和多个文件的情况
szPath[ofn.nFileOffset] = '\0';
nLen = lstrlen(szPath);
// 如果选了多个文件,则必须加上'//'
if (szPath[nLen - 1] != '\\') {
lstrcat(szPath, _T("\\"));
}
// 把指针移到第一个文件
p = szOpenFileNames + ofn.nFileOffset;
// 对szFileName进行清零
ZeroMemory(szFileName, sizeof(szFileName));
// 定义字符串,用于拼接所选的所有文件的完整路径
std::string str = "";
while (*p) {
// 读取文件名
std::string fileName = LPWSTR2LPSTR(p);
// 读取文件所在文件夹路径
std::string filePath = LPWSTR2LPSTR(szPath);
// 拼接文件完整路径
std::string completePath = filePath + fileName;
// 拼接字符串
str += completePath;
//移至下一个文件
p += lstrlen(p) + 1;
}
return str;
// 将string转为char*
//char* strc = new char[strlen(str.c_str()) + 1];
//const char* cc = str.c_str();
//strcpy_s(strc, str.size() + 1, cc);
}
//https://learn.microsoft.com/en-us/windows/win32/shell/common-file-dialog?redirectedfrom=MSDN
std::string SelectDirIFD()
{
std::string folderpath = "";
// CoCreate the File Open Dialog object.
IFileDialog* pfd = NULL;
HRESULT hr = CoCreateInstance(CLSID_FileOpenDialog,
NULL,
CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&pfd));
if (SUCCEEDED(hr))
{
// Set the options on the dialog.
DWORD dwFlags;
// Before setting, always get the options first in order
// not to override existing options.
hr = pfd->GetOptions(&dwFlags);
if (SUCCEEDED(hr))
{
// In this case, get shell items only for file system items.
hr = pfd->SetOptions(dwFlags | FOS_PICKFOLDERS);
if (SUCCEEDED(hr))
{
// Show the dialog
hr = pfd->Show(NULL);
if (SUCCEEDED(hr))
{
// Obtain the result once the user clicks
// the 'Open' button.
// The result is an IShellItem object.
IShellItem* psiResult;
hr = pfd->GetResult(&psiResult);
if (SUCCEEDED(hr))
{
// We are just going to print out the
// name of the file for sample sake.
PWSTR pszFilePath = NULL;
hr = psiResult->GetDisplayName(SIGDN_FILESYSPATH,&pszFilePath);
if (SUCCEEDED(hr))
{
folderpath = LPWSTR2LPSTR(pszFilePath);
CoTaskMemFree(pszFilePath);
}
psiResult->Release();
}
}
}
}
pfd->Release();
}
return folderpath;
}

@ -2,15 +2,19 @@
#include <iostream>
#include <vector>
#include "basecamera.h"
#include <mutex>
#include "basecamera.h"
#include "QtCore\qdatetime.h"
#include <Windows.h>
#include <ShlObj.h>
#include <Commdlg.h>
#include <tchar.h>
//#define __DEBUG //debug信息输出功能
#define __UDPSend //网络发送功能
#define __DEBUG //debug信息输出功能
//#define __UDPSend //网络发送功能
#define USB_BASLER_NEW_FW //使用basler定制固件
//#define IMM_PROCESS //拍照后立马处理,不等校验信号
#define IMM_FEED_BACK //处理完后立马反馈,不等校验信号
//#define IMM_FEED_BACK //处理完后立马反馈,不等校验信号
//#define ONE_TIME_SHIFT //错开一拍发送反馈(默认错开两次)
#define AI_WARM_UP //AI识别开始前的热身动作
//#define LICENSE_VERIFY //开启license文件校验
@ -31,8 +35,30 @@
#define DEBUG(format, ...)
#endif
// 主界面基本参数配置文件
#define CONFIGURE_FILE "../conf/conf.txt"
// 相机旋转角度配置文件
#define ROTATE_FILE "../conf/rotate.txt"
#define MODBUS_CONFIGURE_FILE "../conf/modbus.txt"
#define PLC_CONFIG_FILE "../conf/plc.txt"
#define SELECT_RECTS_FILE "../conf/SelectRects%d%d.txt"
#define STATISTIC_FILE "../conf/camera%d_statistic.txt"
#define ALARM_RECORD_FILE "alarm.txt"
#define OUTPUT_HIGH_WIDTH 20000 //输出信号的脉冲宽度,微秒
#define OP_TIME 300 //OP权限时长默认300秒
#define ADMIN_TIME 600 //ADMIN权限时长默认300秒
#define STOP_SECONDS 3 //检查多少次不变触发自动换班
int string_split(std::string str, std::string pattern,std::vector<std::string> &out);
std::string format(const char *pszFmt, ...);
void getFiles(std::string path, std::vector<std::string>& files);
std::string SelectDirBRI();
std::string SelectFileOFN();
std::string SelectDirIFD();
class SysConf
{
public:
@ -63,6 +89,8 @@ public:
int MonitorPort;
int FeedbackPort;
int FilePort;
QString model_path;
QString jpg_path;
//MonitorPort为数据端口
//MonitorPort+NumberOfSupportedCameras为图像端口
//MonitorPort+NumberOfSupportedCameras*2为发送命令端口,也就是FeedbackPort
@ -198,5 +226,5 @@ public:
uint8_t Flag[2] = {0};
std::vector<RectRatio> RectVet[2];
};
void DrawSelectRects(cv::Mat input, DisplayLabelConf &t_DisplayLabelConf, int Cnt);
bool CheckSelectRects(cv::Mat input, std::vector<std::vector<std::pair<int, cv::Rect> > > &VecRects,int VecCnt, DisplayLabelConf &t_DisplayLabelConf, int LabelCnt);
void DrawSelectRects(cv::Mat input, DisplayLabelConf& t_DisplayLabelConf, int Cnt);
bool CheckSelectRects(cv::Mat input, std::vector<std::vector<std::pair<int, cv::Rect> > >& VecRects, int VecCnt, DisplayLabelConf& t_DisplayLabelConf, int LabelCnt);

@ -70,6 +70,10 @@ DialogSetup::DialogSetup(QWidget * parent) : QDialog(parent) {
break;
}
//
#ifndef __DEBUG
ui.pushButton_testimg->setVisible(false);
ui.pushButton_testimgs->setVisible(false);
#endif
}
DialogSetup::~DialogSetup() {
@ -617,3 +621,13 @@ void DialogSetup::recMsgFromChangeShift(QTime timeA, QTime timeB, QTime timeC)
g_sys_conf.shiftB.setHMS(timeB.hour(), timeB.minute(), 0);
g_sys_conf.shiftC.setHMS(timeC.hour(), timeC.minute(), 0);
}
#ifdef __DEBUG
void DialogSetup::on_pushButton_testimg_released()
{
emit _testimg();
}
void DialogSetup::on_pushButton_testimgs_released()
{
emit _testimgs();
}
#endif

@ -2,7 +2,7 @@
#include <QDialog>
#include "ui_dialogsetup.h"
#include "basecamera.h"
#include <common.h>
#include <camera_glue.h>
#include <output_statistic.h>
#include <change_shift.h>
@ -14,7 +14,10 @@ signals :
void sendMsgToShift(QTime timeA, QTime timeB, QTime timeC);
void sendMsgToOutput();
void sendMsgToConfig(int ptr[][3]);
#ifdef __DEBUG
void _testimg();
void _testimgs();
#endif
private slots :
void on_toolButton_keyboard_released();
void on_pushButton_exit_released();
@ -39,6 +42,10 @@ private slots :
void recMsgFromDialogConfig(int ptr[][3]);
void recMsgFromChangeShift(QTime timeA, QTime timeB, QTime timeC);
#ifdef __DEBUG
void on_pushButton_testimg_released();
void on_pushButton_testimgs_released();
#endif
public:
DialogSetup(QWidget * parent = Q_NULLPTR);
~DialogSetup();

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>679</width>
<height>800</height>
<width>690</width>
<height>830</height>
</rect>
</property>
<property name="font">
@ -28,11 +28,17 @@
<property name="geometry">
<rect>
<x>0</x>
<y>-10</y>
<width>681</width>
<height>831</height>
<y>0</y>
<width>690</width>
<height>830</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
@ -46,15 +52,21 @@
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>670</width>
<height>880</height>
<y>-72</y>
<width>675</width>
<height>900</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>670</width>
<height>880</height>
<height>900</height>
</size>
</property>
<widget class="QGroupBox" name="groupBox_startSets">
@ -1991,6 +2003,46 @@
<string>清理图片</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_testimg">
<property name="geometry">
<rect>
<x>530</x>
<y>820</y>
<width>131</width>
<height>21</height>
</rect>
</property>
<property name="font">
<font>
<family>微软雅黑</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>测试单张图片</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_testimgs">
<property name="geometry">
<rect>
<x>530</x>
<y>850</y>
<width>131</width>
<height>21</height>
</rect>
</property>
<property name="font">
<font>
<family>微软雅黑</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>测试多张图片</string>
</property>
</widget>
</widget>
</widget>
</widget>

Loading…
Cancel
Save