修改部分中文路径读取文件异常的问题

main
seiyu 1 year ago
parent a4a9b3f7e1
commit dfacffd891

@ -151,7 +151,6 @@
<ClCompile Include="alarmdialog.cpp" />
<ClCompile Include="AlarmInfo.cpp" />
<ClCompile Include="alg_jd.cpp" />
<ClCompile Include="alg_jd_ng.cpp" />
<ClCompile Include="ASyncQueue.cpp" />
<ClCompile Include="balluffcamera.cpp" />
<ClCompile Include="basecamera.cpp" />
@ -394,7 +393,6 @@
</CustomBuild>
</ItemGroup>
<ItemGroup>
<ClInclude Include="alg_jd_ng.h" />
<ClInclude Include="tinyxml2.h" />
<CustomBuild Include="threadReceive.h">
<AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(QTDIR)\bin\moc.exe;%(FullPath)</AdditionalInputs>

@ -257,9 +257,6 @@
<ClCompile Include="tinyxml2.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="alg_jd_ng.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<CustomBuild Include="cigarette.h">
@ -420,8 +417,5 @@
<ClInclude Include="tinyxml2.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="alg_jd_ng.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

@ -152,6 +152,7 @@ void AlgJd::analyse(cv::Mat vec_in, std::vector<std::pair<int, cv::Rect> >& vec_
cv::imshow("analyse", topography);
cv::waitKey(1);
}
}
// Get the names of the output layers

@ -15,7 +15,6 @@ class AlgJd
bool init(QString model_path, QString model_name);
bool test_detect();
bool test_detect_batcht(int shoot);
int detect(cv::Mat& in, cv::Mat &draw_frame, cv::Mat& out, std::vector<std::pair<int, cv::Rect> >& results);
int detect(cv::Mat& in, cv::Mat &out, std::vector<std::pair<int, cv::Rect> > &results);
// Remove the bounding boxes with low confidence using non-maxima suppression
void post_process(cv::Mat& frame, std::vector<cv::Mat>& outs, std::vector<std::pair<int, cv::Rect> > &results);
@ -32,10 +31,5 @@ class AlgJd
cv::dnn::Net net;
std::vector<std::string> classes;
};
//jinhuan+
bool sort_rect_by_x_center(cv::Rect r1, cv::Rect r2);
bool sort_rect_by_y_center(cv::Rect r1, cv::Rect r2);
bool sort_rect_by_height(cv::Rect r1, cv::Rect r2);
bool sort_rect_by_width(cv::Rect r1, cv::Rect r2);
//jinhuan-
#endif //end of _CIGARETTE_JD

@ -28,10 +28,8 @@ QDateTime g_ts_start;
extern SingleCamInfoStruct SingleCamInfo[NumberOfSupportedCameras];
AlgJd alg_jd[NumberOfSupportedCameras]; //检测胶点的AI算法
AlgJd_ng alg_jd_ng[NumberOfSupportedCameras]; // 检测卡纸、薄膜褶皱
#ifdef __DEBUG
AlgJd alg_test;//test AI算法
AlgKz alg_kz_test;
#endif
QThread* pThread[NumberOfSupportedCameras];
@ -48,7 +46,7 @@ Pylon::CBaslerUniversalInstantCamera* BaslerCamHandle[NumberOfSupportedCameras];
void *HIKCamHandle[NumberOfSupportedCameras];
CaptureThreadHIK* pHIKCaptureThread[NumberOfSupportedCameras];
SyncQueue<std::pair<std::string, cv::Mat> > *g_save_queue; //图片保存队列
SyncQueue<std::pair<std::string, cv::Mat>> *g_save_queue; //ͼƬ±£´æ¶ÓÁÐ
SyncQueue<std::pair<int, cv::Mat> > *g_image_queue[NumberOfSupportedCameras]; //int表示一个目标拍了几张
ASyncQueue<bool> *g_shooted_queue[NumberOfSupportedCameras]; //
ASyncQueue<bool> *g_result_wait_queue[NumberOfSupportedCameras]; //
@ -92,7 +90,6 @@ VOID BeforeWork(int shoot[])
{
if (SingleCamInfo[i].Detect && SingleCamInfo[i].IsOpen) {
alg_jd[i].test_detect_batcht(shoot[i]);
alg_jd_ng[i].test_detect_batcht_ng(shoot[i]);
}
}
}
@ -105,6 +102,7 @@ Cigarette::Cigarette(QWidget *parent)
ui.setupUi(this);
InitPtrMat();
read_conf(g_conf_path);
if (!g_conf_path.config_path.isEmpty()) {
// 如果非空
QDir* dirinfo = new QDir(g_conf_path.config_path);
@ -276,7 +274,6 @@ Cigarette::Cigarette(QWidget *parent)
m_PLCDevice = new PLCDevice;
PLCDevice::init_plc(m_PLCDevice);
if(m_PLCDevice->g_plc_ok)
{
printf("Connected to dev!\n");
@ -314,36 +311,26 @@ Cigarette::Cigarette(QWidget *parent)
{
if(SingleCamInfo[i].Detect){
cam_status_mat[i]->setStyleSheet(tr("background-color: rgb(0, 170, 0);"));
QString model_path, model1_name, model2_name;
QString model_path, model_name;
if (g_sys_conf.model_path.isEmpty()) {
model_path = "D:/model";
//g_sys_conf.model_path = model_path;
g_sys_conf.model_path = "D:/model";
}
else
model_path = g_sys_conf.model_path;
if (g_sys_conf.model1_name.isEmpty()) {
model1_name = "jd.weights";
g_sys_conf.model1_name = model1_name;
model2_name = "jd_ng.weights";
g_sys_conf.model2_name = model2_name;
}
else {
model1_name = g_sys_conf.model1_name;
model2_name = g_sys_conf.model2_name;
if (g_sys_conf.model_name.isEmpty()) {
model_name = "jd.weights";
g_sys_conf.model_name = "jd.weights";
}
if (!alg_jd[i].init(model_path, model1_name))
else
model_name = g_sys_conf.model_name;
if (!alg_jd[i].init(model_path, model_name))
{
QMessageBox::information(NULL, QStringLiteral("系统自检失败"), QStringLiteral("AI模型1初始化失败请检查程序完整性"), QMessageBox::Ok);
exit(-1);
}
else if (!alg_jd_ng[i].init_ng(model_path, model2_name))
{
QMessageBox::information(NULL, QStringLiteral("系统自检失败"), QStringLiteral("AI模型2初始化失败请检查程序完整性"), QMessageBox::Ok);
exit(-1);
}
CreatWorkThread(SingleCamInfo[i].CamClass, i, this);
}
else {
@ -390,8 +377,7 @@ Cigarette::Cigarette(QWidget *parent)
}
#ifdef __DEBUG
alg_test.init(g_sys_conf.model_path, g_sys_conf.model1_name);//test AI算法
alg_kz_test.init(g_sys_conf.model_path, g_sys_conf.model2_name);
alg_test.init(g_sys_conf.model_path, g_sys_conf.model_name);//test AIËã·¨
#endif
//自动打开所有相机
@ -792,14 +778,7 @@ void Cigarette::TestImg()
}
std::vector<std::pair<int, cv::Rect> > results;
cv::Mat output;
// alg_test.detect(imagein, output, results);
//alg_kz_test.detect(imagein, output, results);
cv::Mat transit = imagein.clone();
//std::vector<std::pair<int, cv::Rect> > results;
alg_test.detect(imagein, transit, output, results);
alg_kz_test.detect(imagein, transit, output, results);
alg_test.detect(imagein, output,results);
std::string WindowName = "TestImg";
cv::namedWindow(WindowName, cv::WINDOW_NORMAL);
cv::imshow(WindowName, output);
@ -835,17 +814,12 @@ void Cigarette::TestImgs()
}
cv::Mat output;
cv::Mat transit = imagein.clone();
std::vector<std::pair<int, cv::Rect> > results;
std::vector<cv::Rect> vec_jd_results;
std::vector<cv::Rect> vec_bm_results;
alg_test.detect(imagein, transit, output, results);
alg_kz_test.detect(imagein, transit, output, results);
std::string WindowName = "TestImgs";
alg_test.detect(imagein, output,results);
std::string WindowName = "TestImg";
cv::namedWindow(WindowName, cv::WINDOW_NORMAL);
cv::imshow(WindowName, transit);
int k = cv::waitKeyEx(100);
cv::imshow(WindowName, output);
int k = cv::waitKeyEx(1);
if (k == 27)break;//ESC键
#ifdef __ExportData
alg_test.analyse(imagein, results);
@ -2410,26 +2384,6 @@ bool Cigarette::read_sys_config(SysConf &conf, QString conf_path)
{ ///相似度
conf.ConfThreshold = atoi(line.substr(pos + 1).c_str());
}
else if (tmp_key == "CONFTHRESHOLDS")
{ ///相似度
std::vector<std::string> vec_info;
string_split(line.substr(pos + 1), "|",vec_info);
if (vec_info.size() == 4)
{
conf.ConfThresholds[0]=atoi(vec_info[0].c_str());// 0 胶点
conf.ConfThresholds[1]=atoi(vec_info[1].c_str());// 1 卡纸
conf.ConfThresholds[2]=atoi(vec_info[2].c_str());// 2 薄膜
conf.ConfThresholds[3]=atoi(vec_info[3].c_str());// 3 卡纸下
}
}
else if (tmp_key == "UP_JD_SPACE")
{ /// 是否自动打开相机0否1是
conf.Up_jd_Space= atoi(line.substr(pos + 1).c_str());
}
else if (tmp_key == "DOWN_JD_SPACE")
{ /// 是否自动打开相机0否1是
conf.Down_jd_Space = 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());
@ -2483,11 +2437,7 @@ bool Cigarette::read_sys_config(SysConf &conf, QString conf_path)
}
else if (tmp_key == "MODELNAME")
{
conf.model1_name = line.substr(pos + 1).c_str();
}
else if (tmp_key == "KZMODELNAME")
{
conf.model2_name = line.substr(pos + 1).c_str();
conf.model_name = line.substr(pos + 1).c_str();
}
else if (tmp_key == "JPGPATH")
{
@ -3006,11 +2956,13 @@ void Cigarette::read_plc_items()
std::fstream cfg_file;
QString plc_file = g_conf_path.config_path + "/" + PLC_CONFIG_FILE;
cfg_file.open(plc_file.toLocal8Bit().constData());
if (!cfg_file.is_open())
{
std::cout << "Error: Open production file " << PLC_CONFIG_FILE << std::endl;
return;
}
while (!cfg_file.eof())
{
char tmp[1024] = "";
@ -3844,18 +3796,25 @@ void Cigarette::CleanThreadStartAuto()
void Cigarette::record_output_statistic(qint64 quantity, int Kick[NumberOfSupportedCameras], int shift)
{
QString file_name, file_path;
for (int i = 0; i < NumberOfSupportedCameras; i++)
{
if (SingleCamInfo[i].IsOpen && quantity > 0) {
std::fstream cfg_file;
char str[256];
memset(str, 0, 256);
sprintf(str, STATISTIC_FILE, i);
//char str[256];
//memset(str, 0, 256);
//sprintf(str, STATISTIC_FILE, i);
//char buf[256];
//memset(buf, 0, 256);
//sprintf(buf, "%s/%s", g_conf_path.config_path.toLocal8Bit().constData(), str);
file_name = QString(STATISTIC_FILE).arg(i);
file_path = g_conf_path.config_path + "/" + file_name;
char buf[256];
memset(buf, 0, 256);
sprintf(buf, "%s/%s", g_conf_path.config_path.toLocal8Bit().constData(), str);
sprintf(buf, "%s", file_path.toLocal8Bit().constData());
//std::cout<<"===buf>"<<buf<<std::endl;
cfg_file.open(buf, std::ios::app);
if (cfg_file.good())
{
@ -4058,14 +4017,18 @@ void Cigarette::recMsgFromUdp(QString data)
}
else if (data == "GETCONF")
{
QString file_name, file_path;
sThread.sendFile(g_conf_path.config_path, g_sys_conf.FilePort);
for(int i=0;i<NumberOfSupportedCameras;i++)
{
char buf[256];
memset(buf, 0, 256);
sprintf(buf, STATISTIC_FILE, i);
QString str(buf);
sThread.sendFile(str.toLocal8Bit().constData(), g_sys_conf.FilePort);
//char buf[256];
//memset(buf, 0, 256);
//sprintf(buf, STATISTIC_FILE, i);
//QString str(buf);
file_name = QString(STATISTIC_FILE).arg(i);
file_path = g_conf_path.config_path + "/" + file_name;
sThread.sendFile(file_path.toLocal8Bit().constData(), g_sys_conf.FilePort);
}
}

@ -7,7 +7,6 @@
#include "dialogsetup.hpp"
#include "plcsetup.hpp"
#include "alg_jd.h"
#include "alg_jd_ng.h"
#include "balluffcamera.h"
#include "baslercamera.h"
#include "hikcamera.h"

@ -56,7 +56,7 @@ void DrawSelectRects(cv::Mat input,DisplayLabelConf &t_DisplayLabelConf,int Cnt)
cv::Point(
t_DisplayLabelConf.processPoint.x * input.cols,
t_DisplayLabelConf.processPoint.y * input.rows),
cv::Scalar(127, 255, 0),
cv::Scalar(0, 0, 255),
4);
}
for (int i = 0; i < t_DisplayLabelConf.RectVet[Cnt].size(); i++) {
@ -68,7 +68,7 @@ void DrawSelectRects(cv::Mat input,DisplayLabelConf &t_DisplayLabelConf,int Cnt)
cv::Point(
t_DisplayLabelConf.RectVet[Cnt][i].BR.x * input.cols,
t_DisplayLabelConf.RectVet[Cnt][i].BR.y * input.rows),
cv::Scalar(127, 255, 0),
cv::Scalar(0, 0, 255),
4);
}
}

@ -85,10 +85,7 @@ public:
int save_days; ///照片保存天数
int freesize; /// 设定清理图片最小空间
std::string ComPort; ///COM口
int ConfThreshold; //识别率
int ConfThresholds[4]; //四类别识别率
int Up_jd_Space; //上方胶点到卡纸上边间距
int Down_jd_Space; //下方胶点到卡纸下边间距
int ConfThreshold; //ʶ±ðÂÊ
int auto_open; //是否自动打开相机0否1是
int auto_work; //是否自动开始工作0否1是
int auto_shift; //是否自动换班0否1是
@ -98,8 +95,7 @@ public:
QTime shiftC; //C换班时间
QString location; // 所在地
QString model_path; // 模型文件夹路径
QString model1_name; // 模型名
QString model2_name;
QString model_name; // Ä£ÐÍÃû
QString model_jpg_path; // 模型图片路径
int timing_shift; //是否定时换班0否1是
int expo[NumberOfSupportedCameras]; //相机曝光时间,单位微秒
@ -125,9 +121,6 @@ public:
freesize = 10; /// 设定清理图片最小空间
ComPort = "COM1"; ///COM口
ConfThreshold = 1; ///百分比识别率
ConfThresholds[4] = 0; ///四类别百分比识别率
Up_jd_Space = 0; //上方胶点到卡纸上边间距
Down_jd_Space = 0; //下方胶点到卡纸下边间距
auto_open=1; //是否自动打开相机0否1是
auto_work=1; //是否自动开始工作0否1是
auto_shift=0; //是否自动换班0否1是
@ -135,8 +128,7 @@ public:
timing_shift = 0; //是否定时换班0否1是
location = "";
model_path = "";
model1_name = "";
model2_name = "";
model_name = "";
model_jpg_path = "";
shiftA.setHMS(0, 0, 0);
shiftB.setHMS(0, 0, 0);

@ -1,2 +1,2 @@
CONF_PATH=D:/conf-test
SAVE_PICS_PATH=D:/image
CONF_PATH=D:/conf-模型1
SAVE_PICS_PATH=D:/image-中文测试

@ -90,17 +90,17 @@ DialogSetup::DialogSetup(QWidget * parent) : QDialog(parent) {
fileList.removeOne("..");
ui.comboBox_model_path->clear();
ui.comboBox_model_path->addItems(fileList);
if (!g_sys_conf.model1_name.isEmpty()) {
if (!g_sys_conf.model_name.isEmpty()) {
// 如果曾选择过模型则在comboBox显示选择模型的文件名
ui.comboBox_model_path->setCurrentText(g_sys_conf.model1_name);
ui.comboBox_model_path->setCurrentText(g_sys_conf.model_name);
}
delete dirinfo, dirinfo = nullptr;
}
else {
// 如果未曾选择过模型文件夹
if (!g_sys_conf.model1_name.isEmpty()) {
if (!g_sys_conf.model_name.isEmpty()) {
// 如果曾经选择过模型文件
ui.comboBox_model_path->addItem(g_sys_conf.model1_name);
ui.comboBox_model_path->addItem(g_sys_conf.model_name);
}
}
// 更换模型事件
@ -114,9 +114,8 @@ DialogSetup::DialogSetup(QWidget * parent) : QDialog(parent) {
dirinfo->mkdir(g_conf_path.save_pics_path);
}
ui.comboBox_save_pics_path->clear();
//ui.comboBox_save_pics_path->clear();
ui.comboBox_save_pics_path->addItem(g_conf_path.save_pics_path);
delete dirinfo, dirinfo = nullptr;
}
else {
@ -124,7 +123,7 @@ DialogSetup::DialogSetup(QWidget * parent) : QDialog(parent) {
QDir *dirinfo = new QDir(dirPath);
if (!dirinfo->exists())
delete dirinfo, dirinfo = nullptr;
ui.comboBox_save_pics_path->clear();
//ui.comboBox_save_pics_path->clear();
ui.comboBox_save_pics_path->setCurrentText(dirPath);
g_conf_path.save_pics_path = dirPath;
}
@ -175,7 +174,7 @@ void DialogSetup::onComboBoxSelect(int index) {
// 获取comboBox当前内容
QString ct = ui.comboBox_model_path->currentText();
// 保存到配置文件中
g_sys_conf.model1_name = ct;
g_sys_conf.model_name = ct;
}
void DialogSetup::on_toolButton_keyboard_released()
@ -392,7 +391,7 @@ void DialogSetup::on_toolButton_choose_model_path_released() {
QString dirName = QFileDialog::getExistingDirectory(this, QStringLiteral("请选择模型所在文件夹"), "./");
//std::cout << "dirName is " << dirName.toStdString().c_str() << std::endl;
//std::cout << "g_sys_conf.dir_path is " << g_sys_conf.dir_path.toStdString().c_str() << std::endl;
//std::cout << "g_sys_conf.model1_name is " << g_sys_conf.model1_name.toStdString().c_str() << std::endl;
//std::cout << "g_sys_conf.model_name is " << g_sys_conf.model_name.toStdString().c_str() << std::endl;
if (dirName.isEmpty()) {
if (g_sys_conf.model_path.isEmpty())
@ -402,7 +401,7 @@ void DialogSetup::on_toolButton_choose_model_path_released() {
ui.comboBox_model_path->addItem(dirName);
g_sys_conf.model_path = dirName;
g_sys_conf.model1_name = "jd.weights";
g_sys_conf.model_name = "jd.weights";
}
QDir* dirinfo = new QDir(dirName);
if (!dirinfo->exists())
@ -411,7 +410,7 @@ void DialogSetup::on_toolButton_choose_model_path_released() {
QStringList fileList = dirinfo->entryList(QDir::Files);
if (fileList.count() == 0) {
g_sys_conf.model_path = "D:/model";
g_sys_conf.model1_name = "jd.weights";
g_sys_conf.model_name = "jd.weights";
}
else
g_sys_conf.model_path = dirName;
@ -421,7 +420,7 @@ void DialogSetup::on_toolButton_choose_model_path_released() {
ui.comboBox_model_path->clear();
ui.comboBox_model_path->addItems(fileList);
//g_sys_conf.model1_name = ui.comboBox_model_path->currentText();
//g_sys_conf.model_name = ui.comboBox_model_path->currentText();
connect(ui.comboBox_model_path, SIGNAL(currentIndexChanged(int)), this, SLOT(onComboBoxSelect(int)));
delete dirinfo, dirinfo = nullptr;
@ -436,7 +435,7 @@ void DialogSetup::on_toolButton_choose_save_pics_path_released() {
dirName = "D:/image";
else
dirName = g_conf_path.save_pics_path;
ui.comboBox_save_pics_path->addItem(dirName);
//ui.comboBox_save_pics_path->addItem(dirName);
//return;
}
@ -444,14 +443,17 @@ void DialogSetup::on_toolButton_choose_save_pics_path_released() {
if (!dirinfo->exists())
delete dirinfo, dirinfo = nullptr;
ui.comboBox_save_pics_path->clear();
ui.comboBox_save_pics_path->addItem(dirName);
//g_conf_path.save_pics_path = dirName;
QFileInfo fileInfo(dirName);
if (fileInfo.isDir() && ui.comboBox_save_pics_path->findText(fileInfo.absoluteFilePath())) {
ui.comboBox_save_pics_path->addItem(fileInfo.absoluteFilePath());
ui.comboBox_save_pics_path->setCurrentText(fileInfo.absoluteFilePath());
}
connect(ui.comboBox_save_pics_path, SIGNAL(currentIndexChanged(int)), this, SLOT(onComboBoxPicsPathSelect(int)));
g_conf_path.save_pics_path = dirName;
delete dirinfo, dirinfo = nullptr;
connect(ui.comboBox_save_pics_path, SIGNAL(currentIndexChanged(int)), this, SLOT(onComboBoxPicsPathSelect(int)));
write_conf_path();
delete dirinfo, dirinfo = nullptr;
}
void DialogSetup::on_toolButton_choose_path_jpg_released() {
@ -536,15 +538,6 @@ void DialogSetup::write_config()
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, "CONFTHRESHOLDS=%d|%d|%d|%d\n", g_sys_conf.ConfThresholds[0], g_sys_conf.ConfThresholds[1], g_sys_conf.ConfThresholds[2], g_sys_conf.ConfThresholds[3]);
cfg_file.write(buf, strlen(buf));
memset(buf, 0, 256);
sprintf(buf, "UP_JD_SPACE=%d\n", g_sys_conf.Up_jd_Space);
cfg_file.write(buf, strlen(buf));
memset(buf, 0, 256);
sprintf(buf, "DOWN_JD_SPACE=%d\n", g_sys_conf.Down_jd_Space);
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));
@ -576,10 +569,7 @@ void DialogSetup::write_config()
sprintf(buf, "MODELPATH=%s\n", g_sys_conf.model_path.toStdString().c_str());
cfg_file.write(buf, strlen(buf));
memset(buf, 0, 256);
sprintf(buf, "MODELNAME=%s\n", g_sys_conf.model1_name.toStdString().c_str());
cfg_file.write(buf, strlen(buf));
memset(buf, 0, 256);
sprintf(buf, "KZMODELNAME=%s\n", g_sys_conf.model2_name.toStdString().c_str());
sprintf(buf, "MODELNAME=%s\n", g_sys_conf.model_name.toStdString().c_str());
cfg_file.write(buf, strlen(buf));
memset(buf, 0, 256);
sprintf(buf, "JPGPATH=%s\n", g_sys_conf.model_jpg_path.toStdString().c_str());

File diff suppressed because it is too large Load Diff

@ -82,11 +82,11 @@ void output_statistic::recMsgFromDialogSetup()
for (int i = 0; i < NumberOfSupportedCameras; i++) {
file_name = QString(STATISTIC_FILE).arg(i);
file_path = g_conf_path.config_path + "/" + file_name;
//std::cout << "===>" << file_path.toStdString() << std::endl;
file.setFileName(file_path);
if (file.open(QIODevice::ReadOnly | QIODevice::Text))
{
QTextStream in(&file);
//in.setCodec("UTF-8");
textBrowser_mat[i]->setText(in.readAll());
}
else {

@ -244,7 +244,10 @@ void PlcSetup::handleTimeout()
void PlcSetup::read_plc_items()
{
std::fstream cfg_file;
cfg_file.open(g_conf_path.config_path.toStdString() + "/" + PLC_ITEM_FILE);
QString plc_file = g_conf_path.config_path + "/" + PLC_CONFIG_FILE;
cfg_file.open(plc_file.toLocal8Bit().constData());
if (!cfg_file.is_open())
{
std::cout << "Error: Open production file " << PLC_ITEM_FILE << std::endl;
@ -277,7 +280,8 @@ void PlcSetup::read_plc_items()
void PlcSetup::save_plc_items()
{
std::fstream cfg_file;
cfg_file.open(g_conf_path.config_path.toStdString() + "/" + PLC_ITEM_FILE, std::ios::out | std::ios::trunc);
QString plc_file = g_conf_path.config_path + "/" + PLC_CONFIG_FILE;
cfg_file.open(plc_file.toLocal8Bit().constData(), std::ios::out | std::ios::trunc);
if (cfg_file.good())
{
for (int i = 0; i < m_plc_items.size(); i++)

@ -55,7 +55,6 @@ protected:
std::pair<std::string, cv::Mat> element;
g_save_queue->take(element);
std::string file_name = element.first;
//std::cout << file_name << std::endl;
image = element.second;
if (image.data)
{
@ -78,7 +77,9 @@ protected:
}
if (!b_find)
{
QString dir_str = QString::fromStdString(dir_path);
//QString dir_str = QString::fromStdString(dir_path);
QString dir_str = QString::fromLocal8Bit(QByteArray::fromRawData(dir_path.c_str(), dir_path.size()));
QDir dir;
if (!dir.exists(dir_str))
{

@ -1,6 +1,5 @@
#include "workthread.h"
#include "alg_jd.h"
#include "alg_jd_ng.h"
#include "common.h"
#include "balluffcamera.h"
#include "baslercamera.h"
@ -9,8 +8,6 @@
#include "exportData.h"
extern AlgJd alg_jd[NumberOfSupportedCameras]; //检测胶点的AI算法
extern AlgJd_ng alg_jd_ng[NumberOfSupportedCameras]; // ng模型
extern ConfPath g_conf_path;
extern SysConf g_sys_conf; //系统配置参数
extern DisplayLabelConf g_display_label_conf[NumberOfSupportedCameras];
@ -18,8 +15,8 @@ extern DisplayLabelConf g_display_label_conf[NumberOfSupportedCameras];
extern int rotationAngle[NumberOfSupportedCameras]; //图片旋转角度
extern bool isNeedRotate[NumberOfSupportedCameras];
extern SyncQueue<std::pair<std::string, cv::Mat>> *g_save_queue; //图片保存队列
extern SyncQueue<std::pair<int, cv::Mat>> *g_image_queue[NumberOfSupportedCameras]; //int表示一个目标拍了几张
extern SyncQueue<std::pair<std::string, cv::Mat> >* g_save_queue; //图片保存队列
extern SyncQueue<std::pair<int, cv::Mat> >* g_image_queue[NumberOfSupportedCameras]; //int表示一个目标拍了几张
extern SyncQueue<_UDPSendInfo> *UDP_Info_queue;
extern SyncQueue<_ExportDataInfo>* export_Data_Info_queue;
extern PLCDevice* m_PLCDevice;
@ -62,9 +59,6 @@ void WorkThread::run()
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;//
local_SysConf.Up_jd_Space = g_sys_conf.Up_jd_Space;
local_SysConf.Down_jd_Space = g_sys_conf.Down_jd_Space;
for (int i = 0; i < 3; i++)local_SysConf.no[local_camera_number][i] = g_sys_conf.no[local_camera_number][i];
#ifdef DRAW_RECT
@ -79,6 +73,7 @@ void WorkThread::run()
#endif
}
QDateTime now_ts = QDateTime::currentDateTime();
std::pair<int, cv::Mat> element;
local_g_image_queue->take(element);
@ -101,19 +96,18 @@ void WorkThread::run()
{
cv::cvtColor(image, image, CV_BGR2RGB); //灰度图像转为彩色图像
}
if (local_SysConf.shoot[local_camera_number] == unit_count)
{
exportDataInfo.shotCounts = unit_count;
std::vector<cv::Mat> vec_in;
int w = image.cols;
int h = image.rows / unit_count;
for (int index = 0; index < unit_count; index++)
for(int index=0;index<unit_count;index++)
{
cv::Rect temp_Rect(0, h * index, w, h);
cv::Mat temp_image = image(temp_Rect).clone();
if (isNeedRotate[local_camera_number]) {
if (rotationAngle[local_camera_number] != (cv::ROTATE_90_COUNTERCLOCKWISE + 1))
if(rotationAngle[local_camera_number] != (cv::ROTATE_90_COUNTERCLOCKWISE + 1))
{
cv::rotate(temp_image, temp_image, rotationAngle[local_camera_number]);
}
@ -122,47 +116,31 @@ void WorkThread::run()
}
std::vector<cv::Mat> vec_out;
//单张
cv::Mat transits;
std::vector<std::pair<int, cv::Rect>> results;
std::vector<std::pair<int, cv::Rect>> results_ng;
//多张
std::vector<cv::Mat> transits_ng;
std::vector<std::vector<std::pair<int, cv::Rect>>> vec_results;
std::vector<std::vector<std::pair<int, cv::Rect>>> vec_results_ng;
std::vector<std::vector<std::pair<int, cv::Rect> > > vec_results;
QDateTime ts_start = QDateTime::currentDateTime();
if (unit_count == 1) {
//std::vector<std::pair<int, cv::Rect>> results;
//std::vector<std::pair<int, cv::Rect>> results_ng;
cv::Mat imagein, imageout;
if(unit_count == 1){
std::vector<std::pair<int, cv::Rect> > results;
cv::Mat imagein,imageout;
imagein = vec_in[0];
alg_jd[local_camera_number].detect(imagein, imageout, results);
transits = imageout.clone();
alg_jd_ng[local_camera_number].detect_ng(imagein, transits, imageout, results_ng);
vec_out.push_back(imageout.clone());
vec_results.push_back(results);
vec_results_ng.push_back(results_ng);
}
else {
}else{
alg_jd[local_camera_number].detect_batch(vec_in, vec_out, vec_results);
for (int i = 0; i < vec_out.size(); i++)
transits_ng.push_back(vec_out[i]);
alg_jd_ng[local_camera_number].detect_batch_ng(vec_in, transits_ng, vec_out, vec_results_ng);
}
QDateTime ts_jd = QDateTime::currentDateTime();
int time_process = ts_start.msecsTo(ts_jd);
emit display_timecost(local_camera_number, time_process);
//UDPSendInfo.timecost = QString::number(time_process);
//exportDataInfo.timeCost = QString::number(time_process).toStdString();
UDPSendInfo.timecost = QString::number(time_process);
exportDataInfo.timeCost = QString::number(time_process).toStdString();
cv::Mat image1;
cv::Mat image2;
QString jd_no;
for (int index = 0; index < unit_count; index++)
for(int index=0;index<unit_count;index++)
{
jd_no += QString::number(vec_results[index].size()) + ",";
jd_no += QString::number(vec_results[index].size())+",";
exportDataInfo.jd[index] = vec_results[index].size();
exportDataInfo.isJdExist[index] = vec_results[index].size() > 0;
}
@ -171,10 +149,10 @@ void WorkThread::run()
UDPSendInfo.JD = jd_no;
bool IsNG = false;
bool IsNG_model2[3] = { false };
for (int index = 0; index < unit_count; index++)
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() < 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)//三张照片分别存储
{
@ -184,12 +162,13 @@ void WorkThread::run()
+ QString::number(local_camera_number + 1) + "/" + QString::number(index + 1) + "/" +
now_ts.toString("yyyy-MM-dd_HH-mm-ss_zzz_") + QString::number(local_camera_number + 1) +
"#" + "_" + QString::number(index + 1) + ".jpg";
g_save_queue->put(std::make_pair(file_name.toStdString(), m));
g_save_queue->put(std::make_pair(file_name.toLocal8Bit().constData(), m));
}
}
if (unit_count >= 2){
image1 = vec_out[0].clone();
image1 = vec_out[(result_index) % 2].clone();
#ifdef DRAW_RECT
IsNG|=CheckSelectRects(image1,vec_results,(result_index) % 2,local_DisplayLabelConf,0);
#endif
@ -211,53 +190,15 @@ void WorkThread::run()
#endif
}
result_index++;
//exportDataInfo.isNg = IsNG;
////jinhuan+
//if (vec_jd_results.size() && vec_kzjl_results.size())
//{
// //从上往下第一个胶点的中心y值
// int top_jd_y = vec_jd_results[0].y + vec_jd_results[0].height / 2;
// //从上往下最后一个胶点的中心y值
// int bottom_jd_y = vec_jd_results[vec_jd_results.size()-1].y + vec_jd_results[vec_jd_results.size()-1].height / 2;
// //卡纸的上边沿y值
// int top_kz_y = vec_kzjl_results[0].tl().y;
// //卡纸的下边沿y值
// int bottom_kz_y = vec_kzjl_results[0].br().y;
// //if (abs(top_jd_y - top_kz_y) < local_SysConf.Up_jd_Space)IsNG=true;//像素
// //if (abs(bottom_kz_y - bottom_jd_y) < local_SysConf.Down_jd_Space)IsNG = true;//像素
//
//}
//else
//{
// IsNG = true;//卡纸和胶点数量不够
//}
//if (vec_kzzz_results.size() != 0) {//卡纸有褶皱
// IsNG = true;
//}
//if (vec_bm_results.size() != 0) {//薄膜有褶皱
// IsNG = true;
//}
//if (vec_qb_results.size() != 0) {//卡纸有翘边
// IsNG = true;
// IsNG_model2[2] = IsNG;
//}
////jinhuan-
for (int index = 0; index < unit_count; index++)
{
if (results_ng.size() != 0 || vec_results_ng[index].size() != 0) {//ng模型检测有ng
IsNG = true;
IsNG_model2[index] = IsNG;
}
}
exportDataInfo.isNg = IsNG;
if (!IsNG)
{
emit event_ok(local_camera_number);
local_g_result_queue->put(true);
if (!g_debug_mode)
{
emit event_ok(local_camera_number);
local_g_result_queue->put(true);
}
}
else
{
@ -271,24 +212,21 @@ void WorkThread::run()
{
for(int index=0;index<unit_count;index++)
{
if ((vec_results[index].size() < local_SysConf.no[local_camera_number][index])|| IsNG_model2[index])
{
cv::Mat m = vec_in[index].clone();
QString file_name = g_conf_path.save_pics_path + "/ng/" +
cv::Mat m = vec_in[index].clone();
QString file_name = g_conf_path.save_pics_path + "/ng/" +
now_ts.toString("yyyy-MM-dd") + "/"
+ QString::number(local_camera_number + 1) + "/" + QString::number(index + 1) + "/" +
now_ts.toString("yyyy-MM-dd_HH-mm-ss_zzz_") + QString::number(local_camera_number + 1) +
"#" + "_" + QString::number(index + 1) + ".jpg";
g_save_queue->put(std::make_pair(file_name.toStdString(), m));
/*m = vec_out[index].clone();
file_name = g_conf_path.save_pics_path + "/ng_result/" +
now_ts.toString("yyyy-MM-dd") + "/"
+ QString::number(local_camera_number + 1) + "/" + QString::number(index + 1) + "/" +
now_ts.toString("yyyy-MM-dd_HH-mm-ss_zzz_") + QString::number(local_camera_number + 1) +
"#" + "_" + QString::number(index + 1) + ".jpg";
g_save_queue->put(std::make_pair(file_name.toStdString(), m));*/
}
/*m = vec_out[index].clone();
file_name = "D:/image/" +
now_ts.toString("yyyy-MM-dd") +
"/" + QString::number(local_camera_number + 1) +
"/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));
g_save_queue->put(std::make_pair(file_name.toLocal8Bit().constData(), m));
}
}
}

Loading…
Cancel
Save