Files
ds-628/BaseModules/Hd_LogicDll_module/test.h
T

258 lines
9.8 KiB
C++
Raw Normal View History

2024-09-27 14:31:22 +08:00
#pragma once;
#define _CRT_SECURE_NO_DEPRECATE
#include <iostream>
#include <io.h>
#include <windows.h>
#include "cstdlib"
#include<time.h>
#include<filesystem>
#include <halconcpp/HalconCpp.h>
#include <halconcpp/HDevThread.h>
#include <hdevengine/HDevEngineCpp.h>
#include <direct.h>
#include "toolkit.h"
#include <QtConcurrent> //异步线程
#include <QFuture>
#include <QFutureWatcher>
using namespace HalconCpp;
cv::Mat GetOneImages(cv::Mat& oriImg, cv::Mat& oriImg2)
{
int width = oriImg.cols;
int height = oriImg.rows;
int channel = oriImg.channels();
int actualwidth = width * channel;
//纵向
cv::Mat result = cv::Mat::zeros(oriImg.rows * 2, oriImg.cols, oriImg.type());
if (height % 2)height = height - 1;
for (int i = 0; i < height; i++)
{
oriImg(cv::Rect(0, i, width, 1)).copyTo(result(cv::Rect(0, i * 2, oriImg.cols, 1)));
oriImg2(cv::Rect(0, i, width, 1)).copyTo(result(cv::Rect(0, (i * 2) + 1, oriImg.cols, 1)));
}
return result;
}
int test() {
QFutureWatcher<void>* pwatcher = nullptr;
pwatcher = new QFutureWatcher<void>;
//把扫描到的信息输出
QFuture<void> future = QtConcurrent::run([=]()
{
//InitThreads(int StationNo, int img2D3D)
//参数1 工位 ->1,2,3,4,5
//参数2 0 2D+3D+切图 6个大面
// 1 3D+切图 8个棱边
// 2 2D+切图 2个极柱
// 3 2D 1个防爆阀
InitThreads(1, 0);
InitModels(1, 0);
//CloseThreads(1, 0);
//DestroyModels(1, 0);
//return 0;
//string filePath = "\\\\192.168.1.120\\szh(大盘)\\错检图";
string name = "";
vector<string> files;
string format = ""; //查找文件的格式
QStringList app = addNextDirectory(QString::fromUtf8("E:\\分图\\2022_12_19\\工位一"));
int size = app.size();
//int deli = 10;
int count_ = 0;
int i = 0;//
int run_count = 150;
int slp = 1000;
while (size)
{
QStringList f2 = addSubFolderDirectory(app.at(i));
i++;
cv::Mat TF_tz_img, TR_tz_img;
cv::Mat TF_tiff, TF_LMI_bmp_img,
TR_tiff, TR_LMI_bmp_img, DE2_bmp, DE2_tiff, DE3_bmp, DE3_tiff;
cv::Mat TF_xg_img, TR_xg_img;
QString TF_name, TR_name, SN_TF, SN_TR;
for (int j = 0; j < f2.size(); j++)
{
//TF
if (f2.at(j).indexOf("TF_同轴") != -1 && f2.at(j).indexOf("bmp") != -1) {
TF_tz_img = cv::imread(f2.at(j).toLocal8Bit().toStdString(), 0);
TF_name = (f2.at(j).mid(10, f2.at(j).lastIndexOf("."))).mid(f2.at(j).lastIndexOf("\\") + 1);
if (f2.at(j).indexOf("0IQCB") != -1)
SN_TF = (f2.at(j).mid(0, f2.at(j).lastIndexOf("_") + 1)).mid(f2.at(j).indexOf("0IQCB"));
if (f2.at(j).indexOf("04QCB") != -1)
SN_TF = (f2.at(j).mid(0, f2.at(j).lastIndexOf("_") + 1)).mid(f2.at(j).indexOf("04QCB"));
//SN_TF = (f2.at(j).mid(0, f2.at(j).lastIndexOf("_")+1)).mid(f2.at(j).indexOf("NG"));
}
else if (f2.at(j).indexOf("TF_线光") != -1 && f2.at(j).indexOf("bmp") != -1)
{
TF_xg_img = cv::imread(f2.at(j).toLocal8Bit().toStdString(), 0);
}
else if (f2.at(j).indexOf("TF") != -1 && f2.at(j).indexOf("tiff") != -1)
{
TF_tiff = cv::imread(f2.at(j).toLocal8Bit().toStdString(), 2);
}
else if (f2.at(j).indexOf("TF") != -1 && f2.at(j).indexOf("bmp") != -1)
{
TF_LMI_bmp_img = cv::imread(f2.at(j).toLocal8Bit().toStdString(), 0);
}
//TR
else if (f2.at(j).indexOf("同轴") != -1 && f2.at(j).indexOf("TR") != -1 && f2.at(j).indexOf("bmp") != -1)
{
TR_tz_img = cv::imread(f2.at(j).toLocal8Bit().toStdString(), 0);
TR_name = (f2.at(j).mid(0, f2.at(j).lastIndexOf("."))).mid(f2.at(j).lastIndexOf("\\") + 1);
//SN_TR = (f2.at(j).mid(0, f2.at(j).lastIndexOf("_") + 1)).mid(f2.at(j).indexOf("0IQCB"));
if (f2.at(j).indexOf("0IQCB") != -1)
SN_TR = (f2.at(j).mid(0, f2.at(j).lastIndexOf("_") + 1)).mid(f2.at(j).indexOf("0IQCB"));
if (f2.at(j).indexOf("04QCB") != -1)
SN_TR = (f2.at(j).mid(0, f2.at(j).lastIndexOf("_") + 1)).mid(f2.at(j).indexOf("04QCB"));
}
else if (f2.at(j).indexOf("线光") != -1 && f2.at(j).indexOf("TR") != -1 && f2.at(j).indexOf("bmp") != -1)
{
TR_xg_img = cv::imread(f2.at(j).toLocal8Bit().toStdString(), 0);
}
else if (f2.at(j).indexOf("TR") != -1 && f2.at(j).indexOf("tiff") != -1)
{
TR_tiff = cv::imread(f2.at(j).toLocal8Bit().toStdString(), 2);
}
else if (f2.at(j).indexOf("TR") != -1 && f2.at(j).indexOf("bmp") != -1)
{
TR_LMI_bmp_img = cv::imread(f2.at(j).toLocal8Bit().toStdString(), 0);
}
//DE2
else if (f2.at(j).indexOf("DE2") != -1 && f2.at(j).indexOf("bmp") != -1)
{
DE2_bmp = cv::imread(f2.at(j).toLocal8Bit().toStdString(), -1);
}
else if (f2.at(j).indexOf("DE2") != -1 && f2.at(j).indexOf("tiff") != -1)
{
DE2_tiff = cv::imread(f2.at(j).toLocal8Bit().toStdString(), -1);
}
//DE3
else if (f2.at(j).indexOf("DE3") != -1 && f2.at(j).indexOf("bmp") != -1)
{
DE3_bmp = cv::imread(f2.at(j).toLocal8Bit().toStdString(), -1);
}
else if (f2.at(j).indexOf("DE3") != -1 && f2.at(j).indexOf("tiff") != -1)
{
DE3_tiff = cv::imread(f2.at(j).toLocal8Bit().toStdString(), -1);
}
}
//
//if (TF_tiff.empty() || TF_LMI_bmp_img.empty() || TF_tz_img.empty() || TR_tiff.empty() || TR_LMI_bmp_img.empty() || TR_tz_img.empty())
//{
// std::cout << "__________第" << i << "个文件夹____缺失图片" << std::endl;
// continue;
//}
cv::Mat bigimg = GetOneImages(TF_tz_img, TF_xg_img);
cv::Mat bigimg2 = GetOneImages(TR_tz_img, TR_xg_img);
stringstream str, str_TF_name, str_TR_name,
str_3D_SN_TF, str_3D_SN_TR,
str_2D_SN_TF, str_2D_SN_TR;
str << i << "___000";
str_TF_name << SN_TF.toLocal8Bit().toStdString();
str_TR_name << SN_TR.toLocal8Bit().toStdString();
str_2D_SN_TF << "E:\\离线_output_img1\\" << SN_TF.toLocal8Bit().toStdString() << "\\";
str_3D_SN_TF << "E:\\离线_output_img1\\" << SN_TF.toLocal8Bit().toStdString() << "\\";
str_2D_SN_TR << "E:\\离线_output_img1\\" << SN_TR.toLocal8Bit().toStdString() << "\\";
str_3D_SN_TR << "E:\\离线_output_img1\\" << SN_TR.toLocal8Bit().toStdString() << "\\";
//std::string ssss = "D:\\Ori\\2022-10-28\\13H\\2022-10-" + to_string(deli) + "-13-09-40-0882_0IQCB17940000HCAK9001863_2\\Station1";
//str_2D_SN_TF << ssss;
//str_3D_SN_TF << ssss;
//str_2D_SN_TR << ssss;
//str_3D_SN_TR << ssss;
//deli++;
//str_2D_SN_TF << "E:\\离线_output_img\\" << "TTR" << "\\";
//str_3D_SN_TF << "E:\\离线_output_img\\" << "TTR" << "\\";
//str_2D_SN_TR << "E:\\离线_output_img\\" << "TTR" << "\\";
//str_3D_SN_TR << "E:\\离线_output_img\\" << "TTR" << "\\";
GetStation1TFThreeD(TF_tiff, TF_LMI_bmp_img, bigimg,
str_2D_SN_TF.str().c_str(), str_3D_SN_TF.str().c_str(), str_TF_name.str().c_str(), " ");
GetStation1TRThreeD(TR_tiff, TR_LMI_bmp_img, bigimg2,
str_2D_SN_TR.str().c_str(), str_3D_SN_TR.str().c_str(), str_TR_name.str().c_str(), " ");
str.str("");
str_TF_name.str("");
str_TR_name.str("");
str_2D_SN_TF.str("");
str_3D_SN_TF.str("");
str_2D_SN_TR.str("");
str_3D_SN_TR.str("");
std::cout << "_______________" << count_++ << "________________" << std::endl;
Sleep(slp);
//i = 0;
if (i == run_count)
{
Sleep(3000);
std::cout << "_______________" << 1111111111111111 << "________________" << std::endl;
break;
}
if (i == files.size())
{
//i = 0;
Sleep(4000);
std::cout << "_______________" << 1111111111111111 << "________________" << std::endl;
break;
}
}
CloseThreads(1, 0);
DestroyModels(1, 0);
cv::waitKey();
});
pwatcher->setFuture(future);
return 0;
}