补传文件

main
CJ980606 1 year ago
parent e9233bd88c
commit aa9e765f26

Binary file not shown.

@ -5,8 +5,6 @@ VisualStudioVersion = 17.3.32929.385
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Cigarette", "Cigarette\Cigarette.vcxproj", "{B12702AD-ABFB-343A-A199-8E24837244A3}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CigaretteSingle", "CigaretteSingle\CigaretteSingle.vcxproj", "{795A8611-044A-46D3-8DD9-13A338925BC4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
@ -23,20 +21,12 @@ Global
{B12702AD-ABFB-343A-A199-8E24837244A3}.Release|x64.Build.0 = Release|x64
{B12702AD-ABFB-343A-A199-8E24837244A3}.Release|x86.ActiveCfg = Release|Win32
{B12702AD-ABFB-343A-A199-8E24837244A3}.Release|x86.Build.0 = Release|Win32
{795A8611-044A-46D3-8DD9-13A338925BC4}.Debug|x64.ActiveCfg = Debug|x64
{795A8611-044A-46D3-8DD9-13A338925BC4}.Debug|x64.Build.0 = Debug|x64
{795A8611-044A-46D3-8DD9-13A338925BC4}.Debug|x86.ActiveCfg = Debug|x64
{795A8611-044A-46D3-8DD9-13A338925BC4}.Debug|x86.Build.0 = Debug|x64
{795A8611-044A-46D3-8DD9-13A338925BC4}.Release|x64.ActiveCfg = Release|x64
{795A8611-044A-46D3-8DD9-13A338925BC4}.Release|x64.Build.0 = Release|x64
{795A8611-044A-46D3-8DD9-13A338925BC4}.Release|x86.ActiveCfg = Release|x64
{795A8611-044A-46D3-8DD9-13A338925BC4}.Release|x86.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
Qt5Version = 5.15.2_msvc2019_64
SolutionGuid = {0AF1A30E-A12C-4014-ACD5-65A1E6D54D46}
Qt5Version = 5.15.2_msvc2019_64
EndGlobalSection
EndGlobal

@ -259,17 +259,18 @@ void CaptureThreadHIK::process( void )
MVCC_INTVALUE_EX stIntValue = { 0 };
nRet = MV_CC_GetIntValueEx(CamHandle, "PayloadSize", &stIntValue);
if (nRet) { std::cout << "Get PayloadSize error" << std::endl; }
nDataSize = stIntValue.nCurValue;
nDataSize = stIntValue.nCurValue*3;///
MV_CC_StartGrabbing(CamHandle);
Ready = true;
while(!boTerminated_)
{
nRet = MV_CC_GetOneFrameTimeout(CamHandle, g_pImage_buf, nDataSize, &stFrameInfo, 200);
//nRet = MV_CC_GetOneFrameTimeout(CamHandle, g_pImage_buf, nDataSize, &stFrameInfo, 200);
nRet = MV_CC_GetImageForBGR(CamHandle, g_pImage_buf, nDataSize, &stFrameInfo, 200);
if (MV_OK == nRet)
{
m_cntGrabbedImages++;
cv::Mat openCVImage(stFrameInfo.nHeight, stFrameInfo.nWidth, CV_8UC1, g_pImage_buf);
cv::Mat openCVImage(stFrameInfo.nHeight, stFrameInfo.nWidth, CV_8UC3, g_pImage_buf);
cv::Mat image_clone = openCVImage.clone();
if (!g_debug_mode)
{

Binary file not shown.

@ -1,5 +1,8 @@
#include "alg_jd.h"
#include <direct.h> //所需的库文件
#include "common.h"
// 主界面基本参数配置文件
#define CONFIGURE_FILE "D:/conf/conf.txt"
extern SysConf g_sys_conf;
// 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);
@ -12,27 +15,59 @@ static std::vector<cv::String> getOutputsNames(const cv::dnn::Net& net);
static void drawPred(int classId, float conf, int left, int top, int right, int bottom, cv::Mat& frame);
// Initialize the parameters
static float confThreshold = 0.1; // Confidence threshold
static float confThreshold = g_sys_conf.ConfThreshold*0.01; // Confidence threshold
static float nmsThreshold = 0.4; // Non-maximum suppression threshold
static int inpWidth = 416; // Width of network's input image
static int inpHeight = 416; // Height of network's input image
static std::vector<std::string> classes;
bool AlgJd::init(QString path_model, QString path_jpg)
bool AlgJd::init()
{
QString model_path;
QString jpg_path;
std::fstream cfg_file;
cfg_file.open(CONFIGURE_FILE);
if (!cfg_file.is_open())
{
std::cout << "Error: Open config file " << CONFIGURE_FILE << 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";
std::string classesFile = "D:/model/jd.names";
// Give the configuration and weight files for the model
cv::String modelConfiguration = "../model/jd.cfg";
cv::String modelConfiguration = "D:/model/jd.cfg";
cv::String modelWeights;
if (path_model.length() > 0) {
modelWeights = path_model.toStdString();
if (model_path.length() > 0) {
modelWeights = model_path.toStdString();
}
else {
modelWeights = "../model/jd.weights";
modelWeights = "D:/model/jd.weights";
}
std::ifstream classNamesFile(classesFile.c_str());
@ -54,11 +89,11 @@ bool AlgJd::init(QString path_model, QString path_jpg)
//cv::Mat image = cv::imread("alg_jd.jpg");
cv::Mat image;
if (path_jpg.length() > 0) {
image = cv::imread(path_jpg.toStdString());
if (jpg_path.length() > 0) {
image = cv::imread(jpg_path.toStdString());
}
else {
image = cv::imread("alg_jd.jpg");
image = cv::imread("D:/Release/alg_jd.bmp");
}
//识别一张图测试模型是否正确并且完成GPU数据加载
if (!image.data) return false; //判断测试图片是否正常读取
@ -281,6 +316,7 @@ void AlgJd::detect_batch(std::vector<cv::Mat>& vec_in, std::vector<cv::Mat> &vec
static void post_process_batch(std::vector<cv::Mat>& vec_frame, std::vector<cv::Mat>& outs, std::vector<std::vector<std::pair<int, cv::Rect> > > &vec_results)
{
int batch = vec_frame.size();
double confidence;///
for (int k = 0; k < batch; k++)
{
std::vector<int> classIds;
@ -305,7 +341,7 @@ static void post_process_batch(std::vector<cv::Mat>& vec_frame, std::vector<cv::
{
cv::Mat scores = m0.row(j).colRange(5, m0.cols);
cv::Point classIdPoint;
double confidence;
//double confidence;
// Get the value and location of the maximum score
cv::minMaxLoc(scores, 0, &confidence, 0, &classIdPoint);
@ -335,13 +371,16 @@ static void post_process_batch(std::vector<cv::Mat>& vec_frame, std::vector<cv::
{
int idx = indices[i];
cv::Rect box = boxes[idx];
//识别框宽度大于15显示识别小于认为无胶点NG处理
if (box.width > 15)
if (confidences[idx] > g_sys_conf.ConfThreshold * 0.01)///识别度低于阈值NG处理
{
if (box.width > 15)
{//识别框宽度大于15显示识别小于认为无胶点NG处理
drawPred(classIds[idx], confidences[idx], box.x, box.y,
box.x + box.width, box.y + box.height, vec_frame[k]);
results.push_back(std::make_pair(classIds[idx], box));
}
}
}
vec_results.push_back(results);

@ -8,11 +8,11 @@
#include <opencv2/highgui.hpp>
#include <iostream>
#include <fstream>
#include "common.h"
class AlgJd
{
public:
bool init(QString path_model, QString path_jpg);
bool init();
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,7 +7,23 @@
#include <QtCore\qcryptographichash.h>
#include <QtCore\qprocess.h>
// 主界面基本参数配置文件
#define CONFIGURE_FILE "D:/conf/conf.txt"
// 相机旋转角度配置文件
#define ROTATE_FILE "D:/conf/rotate.txt"
#define MODBUS_CONFIGURE_FILE "D:/conf/modbus.txt"
#define PLC_CONFIG_FILE "D:/conf/plc.txt"
#define SELECT_RECTS_FILE "D:/conf/SelectRects%d%d.txt"
#define STATISTIC_FILE "D:/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秒
@ -25,9 +41,7 @@ QDateTime g_ts_start;
extern SingleCamInfoStruct SingleCamInfo[NumberOfSupportedCameras];
AlgJd alg_jd[NumberOfSupportedCameras]; //检测胶点的AI算法
#ifdef __DEBUG
AlgJd alg_test;//test AI算法
#endif
QThread* pThread[NumberOfSupportedCameras];
//巴鲁夫相机相关
@ -279,7 +293,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(g_sys_conf.path_model,g_sys_conf.path_jpg))
if (!alg_jd[i].init())
{
QMessageBox::information(NULL, QStringLiteral("系统自检失败"), QStringLiteral("AI模型1初始化失败请检查程序完整性"), QMessageBox::Ok);
exit(-1);
@ -287,9 +301,7 @@ Cigarette::Cigarette(QWidget *parent)
CreatWorkThread(SingleCamInfo[i].CamClass, i, this);
}
}
#ifdef __DEBUG
alg_test.init(g_sys_conf.path_model,g_sys_conf.path_jpg);
#endif
//自动打开所有相机
if (g_sys_conf.auto_open == 1)
{
@ -324,7 +336,7 @@ Cigarette::Cigarette(QWidget *parent)
clean_pTimer = new QTimer(this);
connect(clean_pTimer,SIGNAL(timeout()), this, SLOT(CleanThreadStartAuto()));
clean_pTimer->start(86400000);
clean_pTimer->start(3600000);
connect(ui.label_alarm, SIGNAL(QlabelDoubleClick()), this, SLOT(OnCancelAlarm()));//报警标签双击消警
@ -639,10 +651,6 @@ 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);
@ -651,60 +659,7 @@ 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()
{
@ -1878,7 +1833,7 @@ void Cigarette::on_pushButton_clear_released()//
QString Cigarette::read_pswd()
{
std::fstream cfg_file;
cfg_file.open("pswd.txt");
cfg_file.open("D:/Release/pswd.txt");
if (!cfg_file.is_open())
{
std::cout << "Error: Open config file pswd.txt"<< std::endl;
@ -1910,7 +1865,7 @@ QString Cigarette::read_pswd()
QString Cigarette::read_op_pswd()
{
std::fstream cfg_file;
cfg_file.open("pswd_op.txt");
cfg_file.open("D:/Release/pswd_op.txt");
if (!cfg_file.is_open())
{
std::cout << "Error: Open config file pswd_op.txt" << std::endl;
@ -1970,15 +1925,19 @@ bool Cigarette::read_sys_config(SysConf &conf)
{ /// 照片保存天数
conf.save_days = atoi(line.substr(pos + 1).c_str());
}
else if (tmp_key == "FREESIZE") {
else if (tmp_key == "FREESIZE")
{
/// 清理图片设定最小空间值
conf.freesize = atoi(line.substr(pos + 1).c_str());
}
else if (tmp_key == "ComPort")
{/// COM口
{ /// COM口
conf.ComPort = line.substr(pos + 1);
}
else if (tmp_key == "CONFTHRESHOLD")
{ ///相似度
conf.ConfThreshold = atoi(line.substr(pos + 1).c_str());
}
else if (tmp_key == "AUTO_OPEN")
{ /// 是否自动打开相机0否1是
conf.auto_open = atoi(line.substr(pos + 1).c_str());
@ -2028,7 +1987,7 @@ bool Cigarette::read_sys_config(SysConf &conf)
}
else if (tmp_key == "MODELPATH")
{
conf.path_model = line.substr(pos + 1).c_str();
conf.path = line.substr(pos + 1).c_str();
}
else if (tmp_key == "JPGPATH")
{

@ -42,9 +42,10 @@
#include <QFileInfoList>
#include <Windows.h>
#include <QSignalMapper>
#include <QSharedPointer>
#include <common.h>
class QTimer;
#define OPEN true
@ -116,11 +117,8 @@ 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,8 +1,6 @@
#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;
@ -116,246 +114,3 @@ 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,19 +2,15 @@
#include <iostream>
#include <vector>
#include <mutex>
#include "basecamera.h"
#include <mutex>
#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文件校验
@ -35,30 +31,8 @@
#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:
@ -68,6 +42,7 @@ public:
int save_days; ///照片保存天数
int freesize; /// 设定清理图片最小空间
std::string ComPort; ///COM口
int ConfThreshold; //识别率
int auto_open; //是否自动打开相机0否1是
int auto_work; //是否自动开始工作0否1是
int auto_shift; //是否自动换班0否1是
@ -76,7 +51,7 @@ public:
QTime shiftB; //B换班时间
QTime shiftC; //C换班时间
QString location; // 所在地
QString path_model; // 模型路径
QString path; // 模型路径
QString path_jpg; // 图片路径
int timing_shift; //是否定时换班0否1是
int expo[NumberOfSupportedCameras]; //相机曝光时间,单位微秒
@ -99,15 +74,16 @@ public:
save=0; //图片是否保存0不保存1保存NG, 2全部保存
MisMatchAct=1; //错位行为1NG,0ok
save_days = 1; ///照片保存天数
freesize = 10;
ComPort = "COM1";
freesize = 10; /// 设定清理图片最小空间
ComPort = "COM1"; ///COM口
ConfThreshold = 1; ///百分比识别率
auto_open=1; //是否自动打开相机0否1是
auto_work=1; //是否自动开始工作0否1是
auto_shift=0; //是否自动换班0否1是
shift_byhand = 1;
timing_shift=0; //是否定时换班0否1是
location = "";
path_model = "";
path = "";
path_jpg = "";
shiftA.setHMS(0, 0, 0);
shiftB.setHMS(0, 0, 0);
@ -224,5 +200,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);

@ -28,7 +28,7 @@ void task_osk()
DialogSetup::DialogSetup(QWidget * parent) : QDialog(parent) {
ui.setupUi(this);
InitPtrMat();
this->setWindowFlags(Qt::FramelessWindowHint);//窗口可移动
//this->setWindowFlags(Qt::FramelessWindowHint);//窗口可移动
for(int i=0;i<NumberOfSupportedCameras;i++)
{
@ -70,10 +70,6 @@ DialogSetup::DialogSetup(QWidget * parent) : QDialog(parent) {
break;
}
//
#ifndef __DEBUG
ui.pushButton_testimg->setVisible(false);
ui.pushButton_testimgs->setVisible(false);
#endif
}
DialogSetup::~DialogSetup() {
@ -261,7 +257,7 @@ void DialogSetup::on_toolButton_choose_path_released() {
else {
if (ui.comboBox->findText(WeightsPath) == -1) {
ui.comboBox->addItem(WeightsPath); // 在comboBox中显示文件路径
g_sys_conf.path_model = WeightsPath; // 将选择的路径写入conf配置文件中
g_sys_conf.path = WeightsPath; // 将选择的路径写入conf配置文件中
}
}
}
@ -282,7 +278,7 @@ void DialogSetup::on_toolButton_choose_path_jpg_released() {
void DialogSetup::write_pswd()
{
std::fstream cfg_file;
cfg_file.open("pswd.txt", std::ios::out | std::ios::trunc);
cfg_file.open("D:/Release/pswd.txt", std::ios::out | std::ios::trunc);
if (cfg_file.good())
{
char buf[256];
@ -295,7 +291,7 @@ void DialogSetup::write_pswd()
void DialogSetup::write_pswd_op()
{
std::fstream cfg_file;
cfg_file.open("pswd_op.txt", std::ios::out | std::ios::trunc);
cfg_file.open("D:/Release/pswd_op.txt", std::ios::out | std::ios::trunc);
if (cfg_file.good())
{
char buf[256];
@ -308,7 +304,7 @@ void DialogSetup::write_pswd_op()
void DialogSetup::write_config()
{
std::fstream cfg_file;
cfg_file.open("../conf/conf.txt", std::ios::out | std::ios::trunc);
cfg_file.open("D:/conf/conf.txt", std::ios::out | std::ios::trunc);
if (cfg_file.good())
{
char buf[256];
@ -324,6 +320,12 @@ void DialogSetup::write_config()
memset(buf, 0, 256);///
sprintf(buf, "FREESIZE=%d\n", g_sys_conf.freesize);
cfg_file.write(buf, strlen(buf));
memset(buf, 0, 256);///
sprintf(buf, "ComPort=%s\n", g_sys_conf.ComPort);
cfg_file.write(buf, strlen(buf));
memset(buf, 0, 256);///
sprintf(buf, "CONFTHRESHOLD=%d\n", g_sys_conf.ConfThreshold);
cfg_file.write(buf, strlen(buf));
memset(buf, 0, 256);
sprintf(buf, "AUTO_OPEN=%d\n", g_sys_conf.auto_open);
cfg_file.write(buf, strlen(buf));
@ -352,7 +354,7 @@ void DialogSetup::write_config()
sprintf(buf, "LOCATION=%s\n", g_sys_conf.location.toStdString().c_str());
cfg_file.write(buf, strlen(buf));
memset(buf, 0, 256);
sprintf(buf, "MODELPATH=%s\n", g_sys_conf.path_model.toStdString().c_str());
sprintf(buf, "MODELPATH=%s\n", g_sys_conf.path.toStdString().c_str());
cfg_file.write(buf, strlen(buf));
memset(buf, 0, 256);
sprintf(buf, "JPGPATH=%s\n", g_sys_conf.path_jpg.toStdString().c_str());
@ -621,13 +623,3 @@ 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,10 +14,7 @@ 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();
@ -42,10 +39,6 @@ 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>690</width>
<height>830</height>
<width>679</width>
<height>800</height>
</rect>
</property>
<property name="font">
@ -28,17 +28,11 @@
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>690</width>
<height>830</height>
<y>-10</y>
<width>681</width>
<height>831</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>
@ -52,21 +46,15 @@
<property name="geometry">
<rect>
<x>0</x>
<y>-72</y>
<width>675</width>
<height>900</height>
<y>0</y>
<width>670</width>
<height>880</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>900</height>
<height>880</height>
</size>
</property>
<widget class="QGroupBox" name="groupBox_startSets">
@ -2003,46 +1991,6 @@
<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>

@ -9,14 +9,14 @@
int main(int argc, char *argv[])
{
#if defined LICENSE_VERIFY
if(!VerifyLicense(addtime))
if(!VerifyLicense())
{
exit(0);
}
#endif
qRegisterMetaType<cv::Mat>("cv::Mat");
QApplication a(argc, argv);
QPixmap pixmap("splash.jpg");
QPixmap pixmap("D:/Release/splash.jpg");
QSplashScreen splash(pixmap);
splash.show();
a.processEvents();

@ -53,6 +53,7 @@ void WorkThread::run()
local_SysConf.save = g_sys_conf.save;
local_SysConf.shoot[local_camera_number] = g_sys_conf.shoot[local_camera_number];
local_SysConf.MisMatchAct = g_sys_conf.MisMatchAct;
local_SysConf.ConfThreshold = g_sys_conf.ConfThreshold;//
for (int i = 0; i < 3; i++)local_SysConf.no[local_camera_number][i] = g_sys_conf.no[local_camera_number][i];
std::lock_guard<std::mutex> locker2(g_display_label_conf[local_camera_number].lock);
@ -132,8 +133,9 @@ void WorkThread::run()
bool IsNG = false;
for(int index=0;index<unit_count;index++)
{
//if(vec_results[index].size() < local_SysConf.no[local_camera_number][index])IsNG |= true;
if (vec_results[index].size() != 1)IsNG |= true;//·´ÏòѵÁ·
if(vec_results[index].size() < local_SysConf.no[local_camera_number][index])IsNG |= true;
//if (vec_results[index].size() != 1)IsNG |= true;//·´ÏòѵÁ·
if (local_SysConf.ConfThreshold == 0)IsNG = false;
if (local_SysConf.save == 2)//ÈýÕÅÕÕƬ·Ö±ð´æ´¢
{
cv::Mat m = vec_in[index].clone();
@ -175,14 +177,12 @@ void WorkThread::run()
if ((local_SysConf.save == 2) || (local_SysConf.save == 1))
{
for(int index=0;index<unit_count;index++)
{
if ((vec_results[index].size() < local_SysConf.no[local_camera_number][index]))
{
cv::Mat m = vec_in[index].clone();
QString file_name = "D:/image/" +
now_ts.toString("yyyy-MM-dd") +
"/" + QString::number(local_camera_number + 1) +
"/ng/" + QString::number(index)+ "/" +
"/ng/" + QString::number(index) + "/" +
now_ts.toString("yyyy-MM-dd_HH-mm-ss_zzz_") + "_" + QString::number(index) + ".bmp";
g_save_queue->put(std::make_pair(file_name.toStdString(), m));
@ -190,13 +190,12 @@ void WorkThread::run()
file_name = "D:/image/" +
now_ts.toString("yyyy-MM-dd") +
"/" + QString::number(local_camera_number + 1) +
"/ng_result/" + QString::number(index)+ "/" +
"/ng_result/" + QString::number(index) + "/" +
now_ts.toString("yyyy-MM-dd_HH-mm-ss_zzz_") + "_" + QString::number(index) + ".bmp";
g_save_queue->put(std::make_pair(file_name.toStdString(), m));
}
}
}
}
emit display_check_total(local_camera_number, ++frame_total);

@ -1,75 +1,76 @@
SAVE=0
MISMATCHACT=1
SAVE_DAYS=1
SAVE_DAYS=7
FREESIZE=10
ComPort=COM2
ComPort=COM1
CONFTHRESHOLD=1
AUTO_OPEN=1
AUTO_WORK=1
AUTO_SHIFT=0
TIMING_SHIFT=0
TIMING_SHIFT=1
SHIFT_BYHAND=1
SHIFT_A=1|0
SHIFT_B=2|0
SHIFT_C=3|0
LOCATION=CDTHV1.0
MODELPATH=D:/model/jd.weights
JPGPATH=D:/Release455/alg_jd.jpg
SHIFT_A=10|19
SHIFT_B=10|21
SHIFT_C=10|23
LOCATION=CDTHV1.0.1
MODELPATH=
JPGPATH=
*****************************************
EXPO1=500
EXPO1=1000
GAIN1=0
FILTER1=500
USERID1=0
NO1=3|0|0
SHOOT1=1
USERID1=1
NO1=1|1|1
SHOOT1=3
*****************************************
EXPO2=500
GAIN2=0
FILTER2=500
USERID2=1
NO2=2|1|0
SHOOT2=1
USERID2=4
NO2=0|0|0
SHOOT2=3
*****************************************
EXPO3=500
GAIN3=0
FILTER3=500
USERID3=2
NO3=2|1|0
SHOOT3=1
USERID3=255
NO3=0|0|0
SHOOT3=3
*****************************************
EXPO4=500
GAIN4=0
FILTER4=500
USERID4=3
USERID4=2
NO4=0|0|0
SHOOT4=1
SHOOT4=3
*****************************************
EXPO5=555
EXPO5=2000
GAIN5=0
FILTER5=500
USERID5=4
USERID5=255
NO5=0|0|0
SHOOT5=1
SHOOT5=3
*****************************************
EXPO6=555
EXPO6=2000
GAIN6=0
FILTER6=500
USERID6=5
USERID6=255
NO6=0|0|0
SHOOT6=1
SHOOT6=3
*****************************************
EXPO7=555
EXPO7=2000
GAIN7=0
FILTER7=500
USERID7=6
USERID7=255
NO7=0|0|0
SHOOT7=1
SHOOT7=3
*****************************************
EXPO8=555
GAIN8=2
FILTER8=666
USERID8=7
EXPO8=2000
GAIN8=0
FILTER8=500
USERID8=255
NO8=0|0|0
SHOOT8=1
SHOOT8=3
*****************************************
MonitorIP=192.168.1.118
MonitorIP=192.168.1.144
MonitorPort=1234

@ -1,7 +1,7 @@
KICK1=46112
KICK1=46118
KICK2=46114
KICK3=46116
KICK4=46118
KICK4=46112
KICK5=46120
KICK6=46122
KICK7=46124
@ -9,6 +9,7 @@ KICK8=46126
QUANTITY=46008
SHIFT=30100
WORK=30101
SEND_MESSAGE=30200
NO_KICK=37102
DEBUG=30103
RESET=30104

@ -1,13 +1,13 @@
以下数据实验使用|0|0|********************
脉冲速度|46712|6000|范围0Hz~200KHz
脉冲速度|46712|1600|范围0Hz~200KHz
相机校验ON|47000|450|上升沿
相机校验OFF|47002|900|下降沿
1#相机拍照1ON|47004|500|上升沿
1#相机拍照1OFF|47006|520|下降沿
1#相机拍照2ON|47008|1650|上升沿
1#相机拍照2OFF|47010|1670|下降沿
1#相机拍照3ON|47012|1800|上升沿
1#相机拍照3OFF|47014|1820|下降沿
1#相机拍照2ON|47008|600|上升沿
1#相机拍照2OFF|47010|620|下降沿
1#相机拍照3ON|47012|700|上升沿
1#相机拍照3OFF|47014|720|下降沿
以下数据视现场情况自行修改|0|0|********************
开始/暂停|30101|0|1开始0暂停
报警|46018|0|0无报警非零参考报警代码
@ -24,4 +24,3 @@
2通道亮度|46610|80|范围0~255
3通道亮度|46620|111|范围0~255
4通道亮度|46630|111|范围0~255

@ -1 +1 @@
1,2,1,3,1,2,1,0,1,3,1,3,1,3,1,3,
0,3,0,3,0,3,0,3,0,3,0,3,0,3,0,3,
Loading…
Cancel
Save