八相机多模型版

main
seiyu 1 year ago
parent 79d7bb38c5
commit a4a9b3f7e1

@ -133,7 +133,7 @@
<TreatWChar_tAsBuiltInType>true</TreatWChar_tAsBuiltInType>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<LanguageStandard>stdcpp14</LanguageStandard>
<Optimization>Disabled</Optimization>
<Optimization>MaxSpeed</Optimization>
<SupportJustMyCode>false</SupportJustMyCode>
<DisableSpecificWarnings>4819;%(DisableSpecificWarnings)</DisableSpecificWarnings>
</ClCompile>
@ -141,7 +141,7 @@
<SubSystem>Console</SubSystem>
<OutputFile>$(OutDir)\$(ProjectName).exe</OutputFile>
<AdditionalLibraryDirectories>$(QTDIR)\lib;$(ProjectDir)OpenCV455Simple\win64\vc15\lib;$(ProjectDir)Pylon6.2\lib\Win64;$(ProjectDir)MvIMPACT\lib\win64;$(ProjectDir)MVS3.2.1\lib\win64;$(ProjectDir)modbus;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
<GenerateDebugInformation>false</GenerateDebugInformation>
<AdditionalDependencies>qtmain.lib;Qt5Core.lib;Qt5Widgets.lib;Qt5Gui.lib;opencv_world455.lib;modbus.lib;mvDeviceManager.lib;MvCameraControl.lib;Qt5Network.lib;%(AdditionalDependencies)</AdditionalDependencies>
<IgnoreSpecificDefaultLibraries>
</IgnoreSpecificDefaultLibraries>
@ -151,6 +151,7 @@
<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" />
@ -393,6 +394,7 @@
</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,6 +257,9 @@
<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">
@ -417,5 +420,8 @@
<ClInclude Include="tinyxml2.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="alg_jd_ng.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

@ -152,7 +152,6 @@ 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,6 +15,7 @@ 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);
@ -31,5 +32,10 @@ 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

@ -0,0 +1,517 @@
#include "alg_jd_ng.h"
#include <direct.h> //所需的库文件
extern SysConf g_sys_conf;
// Initialize the parameters
static float 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_ng::init_ng(QString model_path, QString model_name)
{
// Load names of classes
std::string classesFile;
cv::String modelConfiguration;
cv::String modelWeights;
QString image_path;
modelWeights = model_path.toStdString() + "/" + model_name.toStdString();
modelConfiguration = model_path.toStdString() + "/jd_ng.cfg";
classesFile = model_path.toStdString() + "/jd_ng.names";
image_path = model_path + "/" + "alg_jd_ng.bmp";
std::ifstream classNamesFile(classesFile.c_str());
if (classNamesFile.is_open())
{
std::string className = "";
while (std::getline(classNamesFile, className))
classes.push_back(className);
}
else{
return false;
}
// Load the network
net_ng = cv::dnn::readNetFromDarknet(modelConfiguration, modelWeights);
net_ng.setPreferableBackend(cv::dnn::DNN_BACKEND_CUDA);
net_ng.setPreferableTarget(cv::dnn::DNN_TARGET_CUDA);
//cv::Mat image = cv::imread("alg_jd.bmp");
cv::Mat image = cv::imread(image_path.toStdString());
//识别一张图测试模型是否正确并且完成GPU数据加载
if (!image.data) return false; //判断测试图片是否正常读取
std::vector<std::pair<int, cv::Rect> > results;
detect_ng(image, image, results);
if (results.size() > 0)
return true; //检测到目标,则初始化成功
else
return false; //否则初始化失败
}
bool AlgJd_ng::test_detect_ng()
{
cv::Mat m1;
m1 = cv::Mat(544, 728, CV_8UC3, cv::Scalar(0, 0, 0));
std::vector<std::pair<int, cv::Rect> > results;
double t = (double)cv::getTickCount();
detect_ng(m1, m1, results);
t = ((double)cv::getTickCount() - t) / cv::getTickFrequency();
DEBUG(" test_detect time process:%f\n", t);
return true;
}
bool AlgJd_ng::test_detect_batcht_ng(int shoot)
{
std::vector<cv::Mat> vec_in;
std::vector<cv::Mat> vec_out;
std::vector<std::vector<std::pair<int, cv::Rect> > > vec_results;
cv::Mat m1, m2, m3;
m1 = cv::Mat(544, 728, CV_8UC3, cv::Scalar(0, 0, 0));
m2 = cv::Mat(544, 728, CV_8UC3, cv::Scalar(0, 0, 0));
m3 = cv::Mat(544, 728, CV_8UC3, cv::Scalar(0, 0, 0));
double t = (double)cv::getTickCount();
switch(shoot){
case 1:{
std::vector<std::pair<int, cv::Rect> > results;
detect_ng(m1, m1, results);
break;
}
case 3:vec_in.push_back(m3);
case 2:vec_in.push_back(m2);
default:{
vec_in.push_back(m1);
detect_batch_ng(vec_in, vec_out, vec_results);
}
}
t = ((double)cv::getTickCount() - t) / cv::getTickFrequency();
DEBUG(" test_detect_batcht time process:%f\n", t);
return true;
}
int AlgJd_ng::detect_ng(cv::Mat& _frame, cv::Mat &out, std::vector<std::pair<int, cv::Rect> > &results)
{
cv::Mat frame = _frame.clone();
cv::Mat image_clone=frame.clone();
// Process frames.
// Create a 4D blob from a frame.
cv::Mat blob;
cv::dnn::blobFromImage(frame, blob, 1/255.0, cv::Size(inpWidth, inpHeight), cv::Scalar(0,0,0), true, false);
//Sets the input to the network
net_ng.setInput(blob);
// Runs the forward pass to get output of the output layers
std::vector<cv::Mat> outs;
net_ng.forward(outs, getOutputsNames_ng(net_ng));
// Remove the bounding boxes with low confidence
post_process_ng(frame, outs, results);
// Write the frame with the detection boxes
cv::Mat detectedFrame;
frame.convertTo(detectedFrame, CV_8U);
//show detectedFrame
out=detectedFrame.clone();
return results.size();
}
int AlgJd_ng::detect_ng(cv::Mat& _frame, cv::Mat& draw_frame, cv::Mat& out, std::vector<std::pair<int, cv::Rect>>& results)
{
cv::Mat frame = _frame.clone();
// Process frames.
// Create a 4D blob from a frame.
// 创建4D的blob用于网络输入
cv::Mat blob;
cv::dnn::blobFromImage(frame, blob, 1 / 255.0, cv::Size(inpWidth, inpHeight), cv::Scalar(0, 0, 0), true, false);
//Sets the input to the network
net_ng.setInput(blob);
// Runs the forward pass to get output of the output layers
std::vector<cv::Mat> outs;
net_ng.forward(outs, getOutputsNames_ng(net_ng));
// Remove the bounding boxes with low confidence
// 删除低置信度的边界框
post_process_ng(draw_frame, outs, results);
// Write the frame with the detection boxes
cv::Mat detectedFrame;
draw_frame.convertTo(detectedFrame, CV_8U);
//show detectedFrame
out = detectedFrame.clone();
return results.size();
}
void AlgJd_ng::CircleImagePro_ng(cv::Mat src, cv::Mat dst, std::vector<float> radius) {
QStringList TestData;
src.copyTo(dst);
float c = float(20.5) / float(68.9);
std::vector<std::vector<cv::Point>> contours;
// 图像预处理
cv::Mat img;
cv::cvtColor(dst, img, cv::COLOR_BGR2GRAY);
GaussianBlur(img, img, cv::Size(3, 3), 1);
Canny(img, img, 50, 150, 3);
imshow("img", img);
cv::Mat kernel = cv::getStructuringElement(cv::MORPH_RECT, cv::Size(3, 3)); // 获取卷积核
dilate(img, img, kernel, cv::Point(-1, -1), 2);
findContours(img, contours, cv::RETR_EXTERNAL, cv::CHAIN_APPROX_SIMPLE);
img.release();
std::vector<cv::Point2f> center(contours.size());
std::vector<float> rad(contours.size());
if (contours.size() == 0) {
std::cout << "未找到检测物" << std::endl;
return;
}
for (size_t i = 0; i < contours.size(); ++i) {
minEnclosingCircle(contours[i], center[i], rad[i]);
radius.push_back(rad[i] * c);
}
for (size_t j = 0; j < center.size(); ++j) {
std::string str = "radius: ";
std::string str1;
float r = 0.0;
circle(dst, center[j], rad[j], cv::Scalar(0, 0, 255), 1);
r = rad[j] * c;
str1 = format("%.4f", r);
str.insert(str.end(), str1.begin(), str1.end());
TestData.append(QString::fromStdString(str));
cv::imshow("dst", dst);
cv::putText(dst, str, center[j], 1, 2, cv::Scalar(0, 255, 0), 2, 8);
cv::waitKey(1);
}
TestData.clear();
}
void AlgJd_ng::analyse_ng(cv::Mat vec_in, std::vector<std::pair<int, cv::Rect>>& vec_results)
{
bool IsNG = false;
std::vector<cv::Rect> vec_jd_results; // 0 胶点
std::vector<cv::Rect> vec_kz_results; // 1 卡纸距离
for (int i = 0; i < vec_results.size(); i++)
{
if (vec_results[i].first == 0) // jd
{
vec_jd_results.push_back(vec_results[i].second);
}
else if (vec_results[i].first == 1) // 卡纸距离
{
vec_kz_results.push_back(vec_results[i].second);
}
}
std::sort(vec_jd_results.begin(), vec_jd_results.end(), sort_rect_by_y_center_ng);//升序排列,//jinhuan+
//jinhuan+
if (vec_jd_results.size() && vec_kz_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_kz_results[0].tl().y;
//卡纸的下边沿y值
int bottom_kz_y = vec_kz_results[0].br().y;
//if(abs(top_jd_y- top_kz_y)>50);//50个像素
//if (abs(bottom_kz_y - bottom_jd_y)>40);//40个像素
} else {
IsNG = true;//卡纸和胶点数量不够
}
//if (vec_kz_results.size() != 1) {//卡纸有褶皱
// IsNG = true;
//}
//jinhuan-
cv::waitKey(1);
}
// Get the names of the output layers
std::vector<cv::String> AlgJd_ng::getOutputsNames_ng(const cv::dnn::Net& net)
{
std::vector<cv::String> names;
if (names.empty())
{
//Get the indices of the output layers, i.e. the layers with unconnected outputs
std::vector<int> outLayers = net.getUnconnectedOutLayers();
//get the names of all the layers in the network
std::vector<cv::String> layersNames = net.getLayerNames();
// Get the names of the output layers in names
names.resize(outLayers.size());
for (size_t i = 0; i < outLayers.size(); ++i)
names[i] = layersNames[outLayers[i] - 1];
}
return names;
}
void AlgJd_ng::post_process_ng(cv::Mat& frame, std::vector<cv::Mat>& outs, std::vector<std::pair<int, cv::Rect> > &results)
{
std::vector < std::vector<int>> classIds(classes.size());
std::vector < std::vector<float>> confidences(classes.size());
std::vector < std::vector<cv::Rect>> boxes(classes.size());
for (size_t i = 0; i < outs.size(); ++i)
{
// Scan through all the bounding boxes output from the network and keep only the
// ones with high confidence scores. Assign the box's class label as the class
// with the highest score for the box.
// 得到每个输出的数据
float* data = (float*)outs[i].data;
for (int j = 0; j < outs[i].rows; ++j, data += outs[i].cols)
{
// 得到每个输出的所有类别的分数
cv::Mat scores = outs[i].row(j).colRange(5, outs[i].cols);
cv::Point classIdPoint;
double confidence;
// Get the value and location of the maximum score
cv::minMaxLoc(scores, 0, &confidence, 0, &classIdPoint);
//if (confidence > g_sys_conf.ConfThresholds[classIdPoint.x]*0.0001)
if (confidence > confThreshold)
{
int centerX = (int)(data[0] * frame.cols);
int centerY = (int)(data[1] * frame.rows);
int width = (int)(data[2] * frame.cols);
int height = (int)(data[3] * frame.rows);
int left = centerX - width / 2;
int top = centerY - height / 2;
classIds[classIdPoint.x].push_back(classIdPoint.x);
confidences[classIdPoint.x].push_back((float)confidence);
boxes[classIdPoint.x].push_back(cv::Rect(left, top, width, height));
}
}
}
// Perform non maximum suppression to eliminate redundant overlapping boxes with
// lower confidences
for (size_t i = 0; i < classes.size(); ++i)
{
std::vector<int> indices;
cv::dnn::NMSBoxes(boxes[i], confidences[i], confThreshold, nmsThreshold, indices);
for (size_t j = 0; j < indices.size(); ++j)
{
int idx = indices[j];
cv::Rect box = boxes[i][idx];
//if (classIds[i][idx] == 2) continue;
//else if (classIds[i][idx] == 3) continue;
drawPred_ng(classIds[i][idx], confidences[i][idx], box.x, box.y,
box.x + box.width, box.y + box.height, frame);
results.push_back(std::make_pair(classIds[i][idx], box));
}
}
}
// Draw the predicted bounding box
void AlgJd_ng::drawPred_ng(int classId, float conf, int left, int top, int right, int bottom, cv::Mat& frame)
{
cv::Scalar color;
if (classId == 0) //jd
color = cv::Scalar(0, 0, 255); // 绿色
else if (classId == 1) // kz
color = cv::Scalar(0, 255, 0); //
else if (classId == 2) // bm
color = cv::Scalar(0, 255, 0);
else if (classId == 3) // kzx
color = cv::Scalar(0, 255, 0);
else
color = cv::Scalar(255, 255, 255); // 白色
//Draw a rectangle displaying the bounding box
cv::rectangle(frame, cv::Point(left, top), cv::Point(right, bottom), color, 4);
//Get the label for the class name and its confidence
std::string label = cv::format("%.2f%%", (conf*100));///
if (!classes.empty())
{
CV_Assert(classId < (int)classes.size());
label = classes[classId] + ": " + label;
}
else
{
std::cout<<"classes is empty..."<<std::endl;
}
//Display the label at the top of the bounding box
int baseLine;
cv::Size labelSize = cv::getTextSize(label, cv::FONT_HERSHEY_SIMPLEX, 1, 1, &baseLine);
top = std::max(top, labelSize.height);
cv::putText(frame, label, cv::Point(left, top-5), cv::FONT_HERSHEY_SIMPLEX, 0.8, color, 1);
}
void AlgJd_ng::detect_batch_ng(std::vector<cv::Mat>& vec_in, std::vector<cv::Mat> &vec_out, std::vector<std::vector<std::pair<int, cv::Rect>>> &vec_results)
{
cv::Mat blobs;
std::vector<cv::Mat> image;
cv::dnn::blobFromImages(vec_in, blobs, 1 / 255.0, cv::Size(inpWidth, inpHeight), cv::Scalar(0, 0, 0), true, false);
//Sets the input to the network
net_ng.setInput(blobs);
// Runs the forward pass to get output of the output layers
std::vector<cv::Mat> outs;
net_ng.forward(outs, getOutputsNames_ng(net_ng));
for (int i = 0; i < vec_in.size(); i++)
{
image.push_back(vec_in[i].clone());
}
// Remove the bounding boxes with low confidence
post_process_batch_ng(image, outs, vec_results);
// Write the frame with the detection boxes
for (int i = 0; i < vec_in.size(); i++)
{
cv::Mat detectedFrame, out;
image[i].convertTo(detectedFrame, CV_8U);
out = detectedFrame.clone();
vec_out.push_back(out);
}
}
void AlgJd_ng::detect_batch_ng(std::vector<cv::Mat>& vec_in, std::vector<cv::Mat>& transits, std::vector<cv::Mat>& vec_out, std::vector<std::vector<std::pair<int, cv::Rect> > >& vec_results)
{
cv::Mat blobs;
//std::vector<cv::Mat> image= transits;
cv::dnn::blobFromImages(vec_in, blobs, 1 / 255.0, cv::Size(inpWidth, inpHeight), cv::Scalar(0, 0, 0), true, false);
//Sets the input to the network
net_ng.setInput(blobs);
// Runs the forward pass to get output of the output layers
std::vector<cv::Mat> outs;
net_ng.forward(outs, getOutputsNames_ng(net_ng));
//for (int i = 0; i < vec_in.size(); i++)
//{
// //image.push_back(vec_in[i].clone());
// transits.push_back(vec_in[i].clone());
//}
// Remove the bounding boxes with low confidence
//post_process_batch_ng(image, outs, vec_results);
post_process_batch_ng(transits, outs, vec_results);
// Write the frame with the detection boxes
for (int i = 0; i < vec_in.size(); i++)
{
cv::Mat detectedFrame, out;
//image[i].convertTo(detectedFrame, CV_8U);
transits[i].convertTo(detectedFrame, CV_8U);
out = detectedFrame.clone();
vec_out.push_back(out);
}
}
void AlgJd_ng::post_process_batch_ng(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 < std::vector<int>> classIds(classes.size());
std::vector < std::vector<float>> confidences(classes.size());
std::vector < std::vector<cv::Rect>> boxes(classes.size());
//std::cout << "outs.size()\t" << outs.size() << std::endl;
//std::cout << "Type\t" << outs[0].type() << std::endl;
for (size_t i = 0; i < outs.size(); ++i)
{
//std::cout << "outs.dims\t" << outs[i].dims << std::endl;
//std::cout << "outs[" << i << "].rows\t" << outs[i].size[0] << std::endl;
//std::cout << "outs[" << i << "].cols\t" << outs[i].size[1] << std::endl;
//std::cout << "outs[" << i << "].cols\t" << outs[i].size[2] << std::endl;
// Scan through all the bounding boxes output from the network and keep only the
// ones with high confidence scores. Assign the box's class label as the class
//
cv::Mat m0(outs[i].size[1], outs[i].size[2], CV_32F, outs[i].data + outs[i].step[0] * k);
// with the highest score for the box.
float* data = (float*)m0.data;
for (int j = 0; j < m0.rows; ++j, data += m0.cols)
{
cv::Mat scores = m0.row(j).colRange(5, m0.cols);
cv::Point classIdPoint;
//double confidence;
// Get the value and location of the maximum score
cv::minMaxLoc(scores, 0, &confidence, 0, &classIdPoint);
//if (confidence > g_sys_conf.ConfThresholds[classIdPoint.x]*0.0001)
if (confidence > confThreshold)
{
int centerX = (int)(data[0] * vec_frame[k].cols);
int centerY = (int)(data[1] * vec_frame[k].rows);
int width = (int)(data[2] * vec_frame[k].cols);
int height = (int)(data[3] * vec_frame[k].rows);
int left = centerX - width / 2;
int top = centerY - height / 2;
classIds[classIdPoint.x].push_back(classIdPoint.x);
confidences[classIdPoint.x].push_back((float)confidence);
boxes[classIdPoint.x].push_back(cv::Rect(left, top, width, height));
}
}
}
std::vector<std::pair<int, cv::Rect> > results;
// Perform non maximum suppression to eliminate redundant overlapping boxes with
// lower confidences
for (size_t i = 0; i < classes.size(); ++i)
{
std::vector<int> indices;
cv::dnn::NMSBoxes(boxes[i], confidences[i], confThreshold, nmsThreshold, indices);
for (size_t j = 0; j < indices.size(); ++j)
{
int idx = indices[j];
cv::Rect box = boxes[i][idx];
drawPred_ng(classIds[i][idx], confidences[i][idx], box.x, box.y,
box.x + box.width, box.y + box.height, vec_frame[k]);
results.push_back(std::make_pair(classIds[i][idx], box));
}
}
vec_results.push_back(results);
}
}
//jinhuan+
bool sort_rect_by_x_center_ng(cv::Rect r1, cv::Rect r2)
{
return (r1.x + r1.width / 2) < (r2.x + r2.width / 2);
}
bool sort_rect_by_y_center_ng(cv::Rect r1, cv::Rect r2)
{
return (r1.y + r1.height / 2) < (r2.y + r2.height / 2);
}
bool sort_rect_by_height_ng(cv::Rect r1, cv::Rect r2)
{
return (r1.height) < (r2.height);
}
bool sort_rect_by_width_ng(cv::Rect r1, cv::Rect r2)
{
return (r1.width) < (r2.width);
}
//jinhuan-

@ -0,0 +1,42 @@
#ifndef _CIGARETTE_JD_ng
#define _CIGARETTE_JD_ng
#include <opencv2/opencv.hpp>
#include <opencv2/dnn.hpp>
#include <opencv2/dnn/shape_utils.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
#include <iostream>
#include <fstream>
#include "common.h"
class AlgJd_ng
{
public:
bool init_ng(QString model_path, QString model_name);
bool test_detect_ng();
bool test_detect_batcht_ng(int shoot);
int detect_ng(cv::Mat& in, cv::Mat &draw_frame, cv::Mat &out, std::vector<std::pair<int, cv::Rect>> &results);
int detect_ng(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_ng(cv::Mat& frame, std::vector<cv::Mat>& outs, std::vector<std::pair<int, cv::Rect>> &results);
void CircleImagePro_ng(cv::Mat src, cv::Mat dst, std::vector<float> radius);
void detect_batch_ng(std::vector<cv::Mat>& vec_in, std::vector<cv::Mat> &vec_out, std::vector<std::vector<std::pair<int, cv::Rect> > > &vec_results);
void detect_batch_ng(std::vector<cv::Mat>& vec_in, std::vector<cv::Mat> &transits, std::vector<cv::Mat> &vec_out, std::vector<std::vector<std::pair<int, cv::Rect>>> &vec_results);
// Remove the bounding boxes with low confidence using non-maxima suppression
void post_process_batch_ng(std::vector<cv::Mat>& vec_frame, std::vector<cv::Mat>& outs, std::vector<std::vector<std::pair<int, cv::Rect>>> &vec_results);
void analyse_ng(cv::Mat vec_in, std::vector<std::pair<int, cv::Rect> > & vec_results);
// Get the names of the output layers
std::vector<cv::String> getOutputsNames_ng(const cv::dnn::Net& net);
// Draw the predicted bounding box
void drawPred_ng(int classId, float conf, int left, int top, int right, int bottom, cv::Mat& frame);
private:
cv::dnn::Net net_ng;
std::vector<std::string> classes_ng;
};
//jinhuan+
bool sort_rect_by_x_center_ng(cv::Rect r1, cv::Rect r2);
bool sort_rect_by_y_center_ng(cv::Rect r1, cv::Rect r2);
bool sort_rect_by_height_ng(cv::Rect r1, cv::Rect r2);
bool sort_rect_by_width_ng(cv::Rect r1, cv::Rect r2);
//jinhuan-
#endif //end of _CIGARETTE_JD

@ -28,8 +28,10 @@ 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];
@ -90,6 +92,7 @@ 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]);
}
}
}
@ -102,7 +105,6 @@ 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);
@ -312,26 +314,36 @@ Cigarette::Cigarette(QWidget *parent)
{
if(SingleCamInfo[i].Detect){
cam_status_mat[i]->setStyleSheet(tr("background-color: rgb(0, 170, 0);"));
QString model_path, model_name;
QString model_path, model1_name, model2_name;
if (g_sys_conf.model_path.isEmpty()) {
model_path = "D:/model";
g_sys_conf.model_path = "D:/model";
//g_sys_conf.model_path = model_path;
}
else
model_path = g_sys_conf.model_path;
if (g_sys_conf.model_name.isEmpty()) {
model_name = "jd.weights";
g_sys_conf.model_name = "jd.weights";
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;
}
else
model_name = g_sys_conf.model_name;
if (!alg_jd[i].init(model_path, model_name))
if (!alg_jd[i].init(model_path, model1_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 {
@ -378,7 +390,8 @@ Cigarette::Cigarette(QWidget *parent)
}
#ifdef __DEBUG
alg_test.init(g_sys_conf.model_path, g_sys_conf.model_name);//test AIËã·¨
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);
#endif
//自动打开所有相机
@ -779,7 +792,14 @@ void Cigarette::TestImg()
}
std::vector<std::pair<int, cv::Rect> > results;
cv::Mat output;
alg_test.detect(imagein, output,results);
// 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);
std::string WindowName = "TestImg";
cv::namedWindow(WindowName, cv::WINDOW_NORMAL);
cv::imshow(WindowName, output);
@ -815,12 +835,17 @@ void Cigarette::TestImgs()
}
cv::Mat output;
cv::Mat transit = imagein.clone();
std::vector<std::pair<int, cv::Rect> > results;
alg_test.detect(imagein, output,results);
std::string WindowName = "TestImg";
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";
cv::namedWindow(WindowName, cv::WINDOW_NORMAL);
cv::imshow(WindowName, output);
int k = cv::waitKeyEx(1);
cv::imshow(WindowName, transit);
int k = cv::waitKeyEx(100);
if (k == 27)break;//ESC键
#ifdef __ExportData
alg_test.analyse(imagein, results);
@ -2385,6 +2410,26 @@ 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());
@ -2438,7 +2483,11 @@ bool Cigarette::read_sys_config(SysConf &conf, QString conf_path)
}
else if (tmp_key == "MODELNAME")
{
conf.model_name = line.substr(pos + 1).c_str();
conf.model1_name = line.substr(pos + 1).c_str();
}
else if (tmp_key == "KZMODELNAME")
{
conf.model2_name = line.substr(pos + 1).c_str();
}
else if (tmp_key == "JPGPATH")
{

@ -7,6 +7,7 @@
#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(0, 0, 255),
cv::Scalar(127, 255, 0),
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(0, 0, 255),
cv::Scalar(127, 255, 0),
4);
}
}

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

@ -0,0 +1,2 @@
CONF_PATH=D:/conf-test
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.model_name.isEmpty()) {
if (!g_sys_conf.model1_name.isEmpty()) {
// 如果曾选择过模型则在comboBox显示选择模型的文件名
ui.comboBox_model_path->setCurrentText(g_sys_conf.model_name);
ui.comboBox_model_path->setCurrentText(g_sys_conf.model1_name);
}
delete dirinfo, dirinfo = nullptr;
}
else {
// 如果未曾选择过模型文件夹
if (!g_sys_conf.model_name.isEmpty()) {
if (!g_sys_conf.model1_name.isEmpty()) {
// 如果曾经选择过模型文件
ui.comboBox_model_path->addItem(g_sys_conf.model_name);
ui.comboBox_model_path->addItem(g_sys_conf.model1_name);
}
}
// 更换模型事件
@ -175,7 +175,7 @@ void DialogSetup::onComboBoxSelect(int index) {
// 获取comboBox当前内容
QString ct = ui.comboBox_model_path->currentText();
// 保存到配置文件中
g_sys_conf.model_name = ct;
g_sys_conf.model1_name = ct;
}
void DialogSetup::on_toolButton_keyboard_released()
@ -392,7 +392,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.model_name is " << g_sys_conf.model_name.toStdString().c_str() << std::endl;
//std::cout << "g_sys_conf.model1_name is " << g_sys_conf.model1_name.toStdString().c_str() << std::endl;
if (dirName.isEmpty()) {
if (g_sys_conf.model_path.isEmpty())
@ -402,7 +402,7 @@ void DialogSetup::on_toolButton_choose_model_path_released() {
ui.comboBox_model_path->addItem(dirName);
g_sys_conf.model_path = dirName;
g_sys_conf.model_name = "jd.weights";
g_sys_conf.model1_name = "jd.weights";
}
QDir* dirinfo = new QDir(dirName);
if (!dirinfo->exists())
@ -411,7 +411,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.model_name = "jd.weights";
g_sys_conf.model1_name = "jd.weights";
}
else
g_sys_conf.model_path = dirName;
@ -421,7 +421,7 @@ void DialogSetup::on_toolButton_choose_model_path_released() {
ui.comboBox_model_path->clear();
ui.comboBox_model_path->addItems(fileList);
//g_sys_conf.model_name = ui.comboBox_model_path->currentText();
//g_sys_conf.model1_name = ui.comboBox_model_path->currentText();
connect(ui.comboBox_model_path, SIGNAL(currentIndexChanged(int)), this, SLOT(onComboBoxSelect(int)));
delete dirinfo, dirinfo = nullptr;
@ -536,6 +536,15 @@ 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));
@ -570,6 +579,9 @@ void DialogSetup::write_config()
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());
cfg_file.write(buf, strlen(buf));
memset(buf, 0, 256);
sprintf(buf, "JPGPATH=%s\n", g_sys_conf.model_jpg_path.toStdString().c_str());
cfg_file.write(buf, strlen(buf));
memset(buf, 0, 256);

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>682</width>
<height>900</height>
<width>660</width>
<height>992</height>
</rect>
</property>
<property name="font">
@ -24,26 +24,17 @@
<property name="styleSheet">
<string notr="true">background-color: rgb(240, 240, 240);</string>
</property>
<widget class="QWidget" name="widget" native="true">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>683</width>
<height>900</height>
</rect>
</property>
<widget class="QScrollArea" name="scrollArea">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>681</width>
<height>901</height>
<width>661</width>
<height>1000</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -61,9 +52,9 @@
<property name="geometry">
<rect>
<x>0</x>
<y>-122</y>
<y>0</y>
<width>670</width>
<height>1000</height>
<height>977</height>
</rect>
</property>
<property name="sizePolicy">
@ -75,7 +66,7 @@
<property name="minimumSize">
<size>
<width>670</width>
<height>1000</height>
<height>900</height>
</size>
</property>
<widget class="QGroupBox" name="groupBox_startSets">
@ -2175,7 +2166,6 @@
</widget>
</widget>
</widget>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources>
<include location="cigarette.qrc"/>

@ -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 {

@ -1,5 +1,6 @@
#include "workthread.h"
#include "alg_jd.h"
#include "alg_jd_ng.h"
#include "common.h"
#include "balluffcamera.h"
#include "baslercamera.h"
@ -8,6 +9,8 @@
#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];
@ -59,6 +62,9 @@ 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
@ -73,7 +79,6 @@ void WorkThread::run()
#endif
}
QDateTime now_ts = QDateTime::currentDateTime();
std::pair<int, cv::Mat> element;
local_g_image_queue->take(element);
@ -96,6 +101,7 @@ void WorkThread::run()
{
cv::cvtColor(image, image, CV_BGR2RGB); //灰度图像转为彩色图像
}
if (local_SysConf.shoot[local_camera_number] == unit_count)
{
exportDataInfo.shotCounts = unit_count;
@ -116,23 +122,39 @@ 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;
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;
//std::vector<std::pair<int, cv::Rect>> results_ng;
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);
}else{
vec_results_ng.push_back(results_ng);
}
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;
@ -149,10 +171,10 @@ void WorkThread::run()
UDPSendInfo.JD = jd_no;
bool IsNG = false;
bool IsNG_model2[3] = { 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 (local_SysConf.ConfThreshold == 0)IsNG = false;
if (local_SysConf.save == 2)//三张照片分别存储
{
@ -167,7 +189,7 @@ void WorkThread::run()
}
if (unit_count >= 2){
image1 = vec_out[(result_index) % 2].clone();
image1 = vec_out[0].clone();
#ifdef DRAW_RECT
IsNG|=CheckSelectRects(image1,vec_results,(result_index) % 2,local_DisplayLabelConf,0);
#endif
@ -189,16 +211,54 @@ void WorkThread::run()
#endif
}
result_index++;
exportDataInfo.isNg = IsNG;
//exportDataInfo.isNg = IsNG;
if (!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 (!g_debug_mode)
if (results_ng.size() != 0 || vec_results_ng[index].size() != 0) {//ng模型检测有ng
IsNG = true;
IsNG_model2[index] = IsNG;
}
}
if (!IsNG)
{
emit event_ok(local_camera_number);
local_g_result_queue->put(true);
}
}
else
{
if (!g_debug_mode)
@ -210,6 +270,8 @@ 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])|| IsNG_model2[index])
{
cv::Mat m = vec_in[index].clone();
QString file_name = g_conf_path.save_pics_path + "/ng/" +
@ -217,14 +279,16 @@ 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));
/*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));
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));*/
}
}
}
}

@ -1,77 +0,0 @@
SAVE=0
MISMATCHACT=1
SAVE_DAYS=1
FREESIZE=10
ComPort=COM3
CONFTHRESHOLD=80
AUTO_OPEN=1
AUTO_WORK=1
AUTO_SHIFT=0
TIMING_SHIFT=1
SHIFT_BYHAND=1
SHIFT_A=13|43
SHIFT_B=13|44
SHIFT_C=13|45
LOCATION=CDTHV1.0.1
MODELPATH=D:/model
MODELNAME=jd.weights
JPGPATH=
*****************************************
EXPO1=2000
GAIN1=0
FILTER1=500
USERID1=5
NO1=0|0|0
SHOOT1=1
*****************************************
EXPO2=2000
GAIN2=0
FILTER2=500
USERID2=255
NO2=0|0|0
SHOOT2=3
*****************************************
EXPO3=2000
GAIN3=0
FILTER3=500
USERID3=255
NO3=0|0|0
SHOOT3=3
*****************************************
EXPO4=2000
GAIN4=0
FILTER4=500
USERID4=255
NO4=0|0|0
SHOOT4=3
*****************************************
EXPO5=2000
GAIN5=0
FILTER5=500
USERID5=255
NO5=0|0|0
SHOOT5=3
*****************************************
EXPO6=2000
GAIN6=0
FILTER6=500
USERID6=255
NO6=0|0|0
SHOOT6=3
*****************************************
EXPO7=2000
GAIN7=0
FILTER7=500
USERID7=255
NO7=0|0|0
SHOOT7=3
*****************************************
EXPO8=2000
GAIN8=0
FILTER8=500
USERID8=255
NO8=0|0|0
SHOOT8=3
*****************************************
MonitorIP=192.168.1.144
MonitorPort=1234

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

@ -1,26 +0,0 @@
以下数据实验使用|0|0|********************
脉冲速度|46712|1600|范围0Hz~200KHz
相机校验ON|47000|450|上升沿
相机校验OFF|47002|900|下降沿
1#相机拍照1ON|47004|500|上升沿
1#相机拍照1OFF|47006|520|下降沿
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无报警非零参考报警代码
当班产量|46008|0|当班产量
剔除总数|46004|0|NG总数
换班|30100|0|写1换班
停机数|46718|20|连续NG报警
硬件自检开关|37105|0|写1关闭/0打开一般情况下无需改动
声开关|37106|1|写1关闭/0打开蜂鸣器
光开关|37107|1|写1关闭/0打开报警灯
光源时间控制|46710|50|默认5秒
光源通讯|30160|0|写1开启通讯
1通道亮度|46600|80|范围0~255
2通道亮度|46610|80|范围0~255
3通道亮度|46620|111|范围0~255
4通道亮度|46630|111|范围0~255

@ -1 +0,0 @@
0,3,0,3,0,3,0,3,0,3,0,3,0,3,0,3,

@ -1 +0,0 @@
此文件夹文件请根据现场情况进行更改
Loading…
Cancel
Save