690 lines
22 KiB
C++
690 lines
22 KiB
C++
#include <algorithmThread.h>
|
|
#include <ReadBarcode.h>
|
|
#include "camera_thread.h"
|
|
#include "myiothread.h"
|
|
#include "FrontendBackendBridge.h"
|
|
#include <myTools.h>
|
|
|
|
bool showOk = true;//显示ok缺陷的框
|
|
std::string fileSavePath("D://CCD//");
|
|
struct _2Dto3D_strcut
|
|
{
|
|
double out_meanValue = -99;
|
|
double out_maxValue = -99;
|
|
double out_minValue = -99;
|
|
Point ltPos;
|
|
Point rdPos;
|
|
};
|
|
//////////////////////
|
|
void writeToData_xxxCsvOkNgNew(detData* rdata, QString OKNG, ngNoteCls* note)
|
|
{
|
|
QDateTime currentDateTime = QDateTime::currentDateTime();
|
|
std::string ymd = currentDateTime.toString("yyyy-MM-dd").toStdString();
|
|
QString filePath = QString::fromStdString(fileSavePath + "//result//" + ymd + "//Data_" + ymd + ".csv");
|
|
/* QString searchString = QString::fromStdString(rdata->getSN() + "_" + to_string(rdata->snCountIndex));*/
|
|
QString searchString = QString::fromStdString(rdata->SNcode);
|
|
QFile file(filePath);
|
|
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
|
qDebug() << "Error opening file.";
|
|
}
|
|
|
|
QStringList headers;
|
|
QList<QStringList> data;
|
|
|
|
QTextStream in(&file);
|
|
while (!in.atEnd()) {
|
|
QString line = in.readLine();
|
|
QStringList fields = line.split(',');
|
|
|
|
if (headers.isEmpty()) {
|
|
// 如果headers为空,则当前行为标题行
|
|
headers = fields;
|
|
}
|
|
else {
|
|
data.append(fields);
|
|
}
|
|
}
|
|
|
|
file.close();
|
|
|
|
// 在data中进行字符串检索并修改匹配的行
|
|
int modifiedRowCount = 0;
|
|
for (int i = data.size() - 1; i > 0; --i) {
|
|
QStringList& row = data[i];
|
|
//if (row.size()<3||row.isEmpty())
|
|
//{
|
|
// break;
|
|
//}
|
|
// 在当前行中检索字符串
|
|
try
|
|
{
|
|
if (row.size() >= 6)
|
|
if (row[1].contains(searchString, Qt::CaseInsensitive)) {
|
|
// 匹配到字符串,进行修改
|
|
row[3] = OKNG;
|
|
row[4] += note->getNgSummaryStr();
|
|
row[5] += note->getOkSummaryStr();
|
|
modifiedRowCount++;
|
|
}
|
|
}
|
|
catch (...)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
|
|
// 将修改后的数据写回文件
|
|
QFile writeFile(filePath);
|
|
if (!writeFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
|
qDebug() << "Error opening file for writing.";
|
|
}
|
|
|
|
QTextStream out(&writeFile);
|
|
// 写入标题行
|
|
out << headers.join(",") << "\n";
|
|
|
|
// 写入修改后的数据行
|
|
for (const auto& row : data) {
|
|
out << row.join(",") << "\n";
|
|
}
|
|
|
|
writeFile.close();
|
|
|
|
qDebug() << "Modified rows:" << modifiedRowCount;
|
|
qDebug() << "Data modified and saved to data_modified.csv";
|
|
|
|
//return 0;
|
|
}
|
|
void writeToData_xxxCSVNew(detData* resData, string OKNG, ngNoteCls* note)
|
|
{
|
|
QDateTime currentDateTime = QDateTime::currentDateTime();
|
|
std::string ymd = currentDateTime.toString("yyyy-MM-dd").toStdString();
|
|
int hour = currentDateTime.time().hour();
|
|
|
|
QString filePath = QString::fromStdString(fileSavePath + "//result//" + ymd + "//Data_" + ymd + ".csv");
|
|
//string sn(resData->SNcode + "-" + to_string(resData->snCountIndex));
|
|
string sn(resData->SNcode);
|
|
/*std::string str(to_string(hour) + "H//" + sn + "-" + to_string(resData->snCountIndex) + "//" + ymd
|
|
+ "-" + to_string(hour) + "_" + resData->getSN() + "-" + to_string(resData->snCountIndex));*/
|
|
std::string str(to_string(hour) + "H//" + sn + "//" + ymd
|
|
+ "-" + to_string(hour) + "_" + sn);
|
|
bool fileExist = false;
|
|
QStringList dataList;
|
|
if (hour < 10)
|
|
dataList.append("0" + QString::number(hour) + "H");
|
|
else
|
|
dataList.append(QString::number(hour) + "H");
|
|
dataList.append(QString::fromStdString(sn));
|
|
dataList.append(QString::fromStdString(str));
|
|
dataList.append(QString::fromStdString(OKNG));
|
|
dataList.append(note->getNgSummaryStr());
|
|
dataList.append(note->getOkSummaryStr());
|
|
// 创建CSV文件
|
|
QFile file(filePath);
|
|
if (!file.exists())
|
|
{
|
|
// 创建目录(如果不存在)
|
|
QDir dir;
|
|
if (!dir.mkpath(QFileInfo(filePath).absolutePath()))
|
|
{
|
|
//qWarning() << "无法创建目录:" << QFileInfo(filePath).absolutePath();
|
|
return;
|
|
}
|
|
fileExist = true;
|
|
}
|
|
// 打开CSV文件并写入数据
|
|
if (file.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text)) {
|
|
QTextStream stream(&file);
|
|
if (fileExist == true)
|
|
{
|
|
stream << "Time,";
|
|
stream << "SN,";
|
|
stream << "Path,";
|
|
stream << "Result,";
|
|
stream << "summuryResult,";
|
|
stream << "\n";
|
|
}
|
|
// 将数据写入CSV文件
|
|
for (const QString& data : dataList) {
|
|
stream << data << ",";
|
|
}
|
|
stream << "\n";
|
|
|
|
file.close();
|
|
qDebug() << "CSV文件写入成功";
|
|
}
|
|
//else
|
|
// qWarning() << "无法打开CSV文件:" << filePath;
|
|
|
|
}
|
|
void algoThread::getAllFiles(string path, vector<string>& files, string format)
|
|
{
|
|
intptr_t hFile = 0;//恅璃曆梟
|
|
struct _finddata_t fileinfo;//恅璃陓洘
|
|
string p;
|
|
if ((hFile = _findfirst(p.assign(path).append("\\*" + format).c_str(), &fileinfo)) != -1) //恅璃湔婓
|
|
{
|
|
do
|
|
{
|
|
if ((fileinfo.attrib & _A_SUBDIR))//瓚剿岆瘁峈恅璃標
|
|
{
|
|
if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0)//恅璃標靡笢祥漪"."睿".."
|
|
{
|
|
files.push_back(p.assign(path).append("\\").append(fileinfo.name)); //悵湔恅璃標靡
|
|
getAllFiles(p.assign(path).append("\\").append(fileinfo.name), files, format); //菰寥梢盪恅璃標
|
|
}
|
|
}
|
|
else
|
|
{
|
|
files.push_back(p.assign(path).append("\\").append(fileinfo.name));//彆祥岆恅璃標ㄛ揣湔恅璃靡
|
|
}
|
|
} while (_findnext(hFile, &fileinfo) == 0);
|
|
_findclose(hFile);
|
|
}
|
|
}
|
|
|
|
inline string getFileName(string path)
|
|
{
|
|
return path.substr(path.find_last_of("\\") + 1, path.find_last_of(".") - path.find_last_of("\\") - 1);
|
|
}
|
|
void drawContoursOverlap(cv::Mat& image, const std::vector<std::vector<cv::Point>>& contours) {
|
|
cv::Mat mask = cv::Mat::zeros(image.size(), CV_8U);
|
|
|
|
// 绘制轮廓在掩码上
|
|
cv::drawContours(mask, contours, -1, cv::Scalar(255), cv::FILLED);
|
|
|
|
// 将图像中与掩码不重叠的区域涂黑
|
|
cv::Mat result;
|
|
image.copyTo(result, mask);
|
|
image.setTo(cv::Scalar(0, 0, 0), ~mask);
|
|
}
|
|
void drawContourOnImage(Mat seg, cv::Mat& imgInput, Size offset = Size(0, 0)) {
|
|
if (seg.empty() || imgInput.empty()) {
|
|
std::cerr << "Empty contour or input image." << std::endl;
|
|
return;
|
|
}
|
|
cv::Mat imgWithAlpha;
|
|
cv::cvtColor(imgInput, imgWithAlpha, cv::COLOR_BGR2BGRA);
|
|
std::vector<std::vector<cv::Point>>contours;
|
|
if (offset.width != 0 && offset.height != 0)
|
|
{
|
|
Mat offsetImg(offset.width + seg.rows, offset.height + seg.cols, CV_8UC1, Scalar(0));
|
|
seg.copyTo(offsetImg(Rect(offset.width, offset.height, seg.rows, seg.cols)));
|
|
offsetImg.copyTo(seg);
|
|
}
|
|
cv::findContours(seg, contours, cv::noArray(), cv::RETR_EXTERNAL, cv::CHAIN_APPROX_NONE);
|
|
for (auto& contour : contours)
|
|
{
|
|
cv::Scalar color(0, 255, 0, 128);
|
|
cv::polylines(imgWithAlpha, contour, true, color);
|
|
cv::cvtColor(imgWithAlpha, imgInput, cv::COLOR_BGRA2BGR);
|
|
}
|
|
}
|
|
/////Specified function////////////////
|
|
void writeSpecificStatement(Mat& Paint, const wchar_t* Text, rectAndData& data, int amount, int limit, Scalar& color)
|
|
{
|
|
wstring MM(to_wstring(max(data.defectHeight, data.defectWidth)));
|
|
MM = MM.substr(0, MM.find_first_of(L".") + 2);
|
|
putTextHusky(Paint, (WString2String(Text + to_wstring(amount)
|
|
+ L"/" + to_wstring(limit) + L"|" +
|
|
MM + L"mm")).c_str(),
|
|
cv::Point(data.rect.x, data.rect.y - 20), color, 20);
|
|
}
|
|
/// <summary>
|
|
/// 专门給-10的3号相机查找电池位置用的
|
|
/// </summary>
|
|
/// <param name="src">图</param>
|
|
/// <param name="rectReturn">返回rect</param>
|
|
/// <returns></returns>
|
|
///
|
|
/////////////////////ALGOTHREAD/////////////////////////
|
|
struct offsets
|
|
{
|
|
string camera1Top = "./temple/1_1";
|
|
string camera1Mid = "./temple/1_2";
|
|
string camera1Bottom = "./temple/1_3";
|
|
|
|
string camera2Top = "./temple/2_1";
|
|
string camera2Mid = "./temple/2_2";
|
|
string camera2Bottom = "./temple/2_3";
|
|
|
|
string camera3Top = "./temple/3_1";
|
|
string camera3Mid = "./temple/3_2";
|
|
string camera3Bottom = "./temple/3_3";
|
|
|
|
string camera4Top = "./temple/4_1";
|
|
string camera4Mid = "./temple/4_2";
|
|
string camera4Bottom = "./temple/4_3";
|
|
};
|
|
struct offsets2
|
|
{
|
|
string camera1Top = "./temple2/1_1";
|
|
string camera1Mid = "./temple2/1_2";
|
|
string camera1Bottom = "./temple2/1_3";
|
|
|
|
string camera2Top = "./temple2/2_1";
|
|
string camera2Mid = "./temple2/2_2";
|
|
string camera2Bottom = "./temple2/2_3";
|
|
|
|
string camera3Top = "./temple2/3_1";
|
|
string camera3Mid = "./temple2/3_2";
|
|
string camera3Bottom = "./temple2/3_3";
|
|
|
|
string camera4Top = "./temple2/4_1";
|
|
string camera4Mid = "./temple2/4_2";
|
|
string camera4Bottom = "./temple2/4_3";
|
|
};
|
|
bool algoThread::addDetTask(detData* data)
|
|
{
|
|
detQueueMutex.lock();
|
|
detQueue.append(data);
|
|
detQueueMutex.unlock();
|
|
this->start();
|
|
return false;
|
|
}
|
|
bool algoThread::waitForImg(detData* data,int timeOutSet=10000)
|
|
{
|
|
int timeOut = 0;
|
|
int sleepMs = 100;
|
|
while (1)
|
|
{
|
|
int imgSize = data->imgs.size();
|
|
int imgAmountMin = data->imgAmountMin;
|
|
if (imgSize >= imgAmountMin)
|
|
return true;
|
|
timeOut+= sleepMs;
|
|
if (timeOut > timeOutSet)
|
|
return false;
|
|
QThread::msleep(sleepMs);
|
|
}
|
|
}
|
|
void algoThread::run()
|
|
{
|
|
while (m_runFlag == true)
|
|
{
|
|
while (detQueue.size() > 0)
|
|
{
|
|
|
|
detQueueMutex.lock();
|
|
detData* data = detQueue.dequeue();//取出数据
|
|
detQueueMutex.unlock();
|
|
if (waitForImg(data) == false)
|
|
{
|
|
qDebug() << "取图失败";
|
|
cout << "get img err" << endl;
|
|
break;
|
|
}
|
|
oriSaveThread->saveOriImg(data);//保存原图
|
|
for (int cnt =0; cnt < data->imgs.size(); cnt++)
|
|
{
|
|
bridge.front.showImg("Camera", data->imgs[cnt], data->oriShowIndex + cnt);//显示原图
|
|
//cout << "showImg" << data->oriShowIndex + cnt << endl;
|
|
}
|
|
int threadId = data->algoThreadIndex;//获取线程id
|
|
//算法
|
|
switch (threadId % 3)
|
|
{
|
|
case 0:
|
|
algoCameraTop(data);
|
|
break;
|
|
case 1:
|
|
algoCameraMid(data);
|
|
break;
|
|
case 2:
|
|
algoCameraBottom(data);
|
|
break;
|
|
}
|
|
if (data->resultImgs.size() > 0)
|
|
{
|
|
for (int cnt = 0; cnt < data->resultImgs.size(); cnt++)
|
|
{
|
|
bridge.front.showImg("Algorithm", data->resultImgs[cnt], data->oriShowIndex + cnt);//显示原图
|
|
}
|
|
resSaveThread->saveResImg(data);//保存结果图
|
|
}
|
|
if (!data->SNcode.compare(snDatas->snErrorsnError))
|
|
data->SNcode = snDatas->waitForSn(data->timeCode);
|
|
sqlDataStruct sqlDataStruct;//定义sql数据
|
|
sqlDataStruct.SN = data->SNcode;//
|
|
for (auto sqlData : data->sqlVec)//将算法中的数据导入到数据结构中
|
|
sqlDataStruct.dataVec.push_back(sql->sqlDatasInit(sqlData.first, sqlData.second));
|
|
sql->addData(sqlDataStruct);//将数据插入数据库
|
|
//delete data;
|
|
detDataController* dController = data->dController;
|
|
data->dController->deleteDetData(data->timeCode);
|
|
}
|
|
QThread::msleep(10);
|
|
}
|
|
}
|
|
void algoThread::algoCameraTop(detData* data)
|
|
{
|
|
if (data->imgs.size() < 2)
|
|
{
|
|
qDebug() << "algoCamera1 img size <2";
|
|
return;
|
|
}
|
|
cv::Mat leftSrc = data->imgs[0];
|
|
cv::Mat rightSrc = data->imgs[1];
|
|
cv::Mat leftPaint;
|
|
cv::Mat rightPaint;
|
|
//leftSrc.copyTo(leftPaint);
|
|
//rightSrc.copyTo(rightPaint);
|
|
cvtColor(leftSrc, leftPaint, COLOR_GRAY2BGR);
|
|
cvtColor(rightSrc, rightPaint, COLOR_GRAY2BGR);
|
|
double pix1 = 0.0058;
|
|
string camre_distan_up;
|
|
if (getOffSetTimes() == 0)
|
|
{
|
|
offsets offset;
|
|
switch (data->algoThreadIndex)
|
|
{
|
|
case 0:
|
|
camre_distan_up = offset.camera1Top;
|
|
Indexs = 1;
|
|
break;
|
|
case 3:
|
|
camre_distan_up = offset.camera2Top;
|
|
Indexs = 2;
|
|
break;
|
|
case 6:
|
|
camre_distan_up = offset.camera3Top;
|
|
Indexs = 3;
|
|
break;
|
|
case 9:
|
|
camre_distan_up = offset.camera4Top;
|
|
Indexs = 4;
|
|
break;
|
|
}
|
|
}
|
|
else if (getOffSetTimes() == 1)
|
|
{
|
|
offsets2 offset;
|
|
switch (data->algoThreadIndex)
|
|
{
|
|
case 0:
|
|
camre_distan_up = offset.camera1Top;
|
|
Indexs = 1;
|
|
break;
|
|
case 3:
|
|
camre_distan_up = offset.camera2Top;
|
|
Indexs = 2;
|
|
break;
|
|
case 6:
|
|
camre_distan_up = offset.camera3Top;
|
|
Indexs = 3;
|
|
break;
|
|
case 9:
|
|
camre_distan_up = offset.camera4Top;
|
|
Indexs = 4;
|
|
break;
|
|
}
|
|
}
|
|
///////////////////////////////////
|
|
//algoMutex->lock();
|
|
HObject ho_Image1;
|
|
simpleAlgo::MatToHObject(leftSrc, ho_Image1);
|
|
//QThread::msleep(10);
|
|
HObject ho_Image2;
|
|
simpleAlgo::MatToHObject(rightSrc, ho_Image2);
|
|
//algoMutex->unlock();
|
|
HTuple hv_Out_line1;
|
|
HTuple hv_Out_line2;
|
|
HTuple hv_Mean_distance1;
|
|
HTuple hv_Make;
|
|
HTuple hv_Path;
|
|
HTuple hv_Diameter{46};
|
|
HTuple hv_Model{0};
|
|
hv_Path = camre_distan_up.c_str();
|
|
_952_15_Distance_UP( ho_Image1, ho_Image2, hv_Path, hv_Model,
|
|
hv_Diameter, & hv_Out_line1, & hv_Out_line2, & hv_Mean_distance1,
|
|
& hv_Make);
|
|
double distance_up = -99;
|
|
if (hv_Make.D() != -1)
|
|
{
|
|
cv::line(leftPaint, cv::Point(hv_Out_line1[1].D(), hv_Out_line1[0].D()), cv::Point(hv_Out_line1[3].D(), hv_Out_line1[2].D()), Scalar(0, 255, 0), 3);
|
|
cv::line(leftPaint, cv::Point(hv_Out_line1[5].D(), hv_Out_line1[4].D()), cv::Point(hv_Out_line1[7].D(), hv_Out_line1[6].D()), Scalar(0, 255, 0), 3);
|
|
distance_up = hv_Mean_distance1.D();
|
|
//cv::putText(leftPaint, "hv_Mean_distance1:" + to_string(hv_Mean_distance1.D()), cv::Point(100, 100), 1, 10, Scalar(0, 255, 0), 10);
|
|
cv::line(rightPaint, cv::Point(hv_Out_line2[1].D(), hv_Out_line2[0].D()), cv::Point(hv_Out_line2[3].D(), hv_Out_line2[2].D()), Scalar(0, 255, 0), 3);
|
|
cv::line(rightPaint, cv::Point(hv_Out_line2[5].D(), hv_Out_line2[4].D()), cv::Point(hv_Out_line2[7].D(), hv_Out_line2[6].D()), Scalar(0, 255, 0), 3);
|
|
//cv::putText(rightPaint, "hv_Mean_distance2:" + to_string(hv_Mean_distance2.D()), cv::Point(100, 100), 1, 5, Scalar(0, 255, 0), 10);
|
|
cout << "distance_up"<< Indexs<< " " << distance_up << endl;
|
|
cv::putText(leftPaint, "distance_up:" + to_string(distance_up), cv::Point(100, 200), 1, 5, Scalar(0, 255, 0), 10);
|
|
cv::putText(rightPaint, "distance_up:" + to_string(distance_up), cv::Point(100, 200), 1, 5, Scalar(0, 255, 0), 10);
|
|
if (!data->SNcode.compare(snDatas->snErrorsnError))
|
|
data->SNcode = snDatas->waitForSn(data->timeCode);
|
|
int res = avgDatasPtr->insertData(data->SNcode, avgDataCls::top, distance_up);
|
|
if (res == 3)
|
|
{
|
|
double batterylenth = avgDatasPtr->getAvg(data->SNcode);
|
|
cv::putText(leftPaint, to_string(res) + "times/avg:" + to_string(batterylenth), cv::Point(100, 300), 1, 5, Scalar(0, 255, 0), 10);
|
|
cv::putText(rightPaint, to_string(res) + "times/avg:" + to_string(batterylenth), cv::Point(100, 300), 1, 5, Scalar(0, 255, 0), 10);
|
|
data->sqlVec.push_back({ "batteryLenth",(int)(batterylenth * 1000) });
|
|
}
|
|
}
|
|
else
|
|
{
|
|
cout << "algo error "<<data->algoThreadName.toStdString() << endl;
|
|
}
|
|
|
|
|
|
data->resultImgs.push_back(leftPaint);
|
|
data->resultImgs.push_back(rightPaint);
|
|
|
|
|
|
}
|
|
void algoThread::algoCameraMid(detData* data)
|
|
{
|
|
if (data->imgs.size() < 2)
|
|
{
|
|
qDebug() << "algoCamera1 img size <2";
|
|
return;
|
|
}
|
|
cv::Mat leftSrc = data->imgs[0];
|
|
cv::Mat rightSrc = data->imgs[1];
|
|
cv::Mat leftPaint;
|
|
cv::Mat rightPaint;
|
|
cvtColor(leftSrc, leftPaint, COLOR_GRAY2BGR);
|
|
cvtColor(rightSrc, rightPaint, COLOR_GRAY2BGR);
|
|
double Pix2 = 0.0058;
|
|
string camre_distan_zhong;
|
|
if (getOffSetTimes() == 0)
|
|
{
|
|
offsets offset;
|
|
switch (data->algoThreadIndex)
|
|
{
|
|
case 1:
|
|
camre_distan_zhong = offset.camera1Mid;
|
|
Indexs = 1;
|
|
break;
|
|
case 4:
|
|
camre_distan_zhong = offset.camera2Mid;
|
|
Indexs = 2;
|
|
break;
|
|
case 7:
|
|
camre_distan_zhong = offset.camera3Mid;
|
|
Indexs = 3;
|
|
break;
|
|
case 10:
|
|
camre_distan_zhong = offset.camera4Mid;
|
|
Indexs = 4;
|
|
break;
|
|
}
|
|
}
|
|
else if (getOffSetTimes() == 1)
|
|
{
|
|
offsets2 offset;
|
|
switch (data->algoThreadIndex)
|
|
{
|
|
case 1:
|
|
camre_distan_zhong = offset.camera1Mid;
|
|
Indexs = 1;
|
|
break;
|
|
case 4:
|
|
camre_distan_zhong = offset.camera2Mid;
|
|
Indexs = 2;
|
|
break;
|
|
case 7:
|
|
camre_distan_zhong = offset.camera3Mid;
|
|
Indexs = 3;
|
|
break;
|
|
case 10:
|
|
camre_distan_zhong = offset.camera4Mid;
|
|
Indexs = 4;
|
|
break;
|
|
}
|
|
}
|
|
///////////////////////////////////
|
|
HObject ho_Image1;
|
|
simpleAlgo::MatToHObject(leftSrc, ho_Image1);
|
|
//QThread::msleep(10);
|
|
HObject ho_Image2;
|
|
simpleAlgo::MatToHObject(rightSrc, ho_Image2);
|
|
double Pix3 = 0.0058;
|
|
HTuple hv_Out_line1;
|
|
HTuple hv_Out_line2;
|
|
HTuple hv_Mean_distance1;
|
|
HTuple hv_Make;
|
|
HTuple hv_Path;
|
|
HTuple hv_Diameter{46};
|
|
HTuple hv_Model{0};
|
|
hv_Path= camre_distan_zhong.c_str();
|
|
_952_15_Distance_Zhong( ho_Image1,ho_Image2,hv_Path,
|
|
hv_Model,hv_Diameter, &hv_Out_line1, & hv_Out_line2,
|
|
& hv_Mean_distance1, &hv_Make);
|
|
double distance_Zhong = -99;
|
|
if (hv_Make.D() != -1)
|
|
{
|
|
cv::line(leftPaint, cv::Point(hv_Out_line1[1].D(), hv_Out_line1[0].D()), cv::Point(hv_Out_line1[3].D(), hv_Out_line1[2].D()), Scalar(0, 255, 0), 3);
|
|
cv::line(leftPaint, cv::Point(hv_Out_line1[5].D(), hv_Out_line1[4].D()), cv::Point(hv_Out_line1[7].D(), hv_Out_line1[6].D()), Scalar(0, 255, 0), 3);
|
|
//cv::putText(leftPaint, "hv_Mean_distance1:" + to_string(hv_Mean_distance1.D()), cv::Point(100, 100), 1, 10, Scalar(0, 255, 0), 10);
|
|
distance_Zhong = hv_Mean_distance1.D();
|
|
cv::line(rightPaint, cv::Point(hv_Out_line2[1].D(), hv_Out_line2[0].D()), cv::Point(hv_Out_line2[3].D(), hv_Out_line2[2].D()), Scalar(0, 255, 0), 3);
|
|
cv::line(rightPaint, cv::Point(hv_Out_line2[5].D(), hv_Out_line2[4].D()), cv::Point(hv_Out_line2[7].D(), hv_Out_line2[6].D()), Scalar(0, 255, 0), 3);
|
|
//cv::putText(rightPaint, "hv_Mean_distance2:" + to_string(hv_Mean_distance2.D()), cv::Point(100, 100), 1, 5, Scalar(0, 255, 0), 10);
|
|
cout << "distance_Zhong"<< Indexs<<" " << distance_Zhong << endl;
|
|
cv::putText(leftPaint, "distance_zhong:" + to_string(distance_Zhong), cv::Point(100, 200), 1, 5, Scalar(0, 255, 0), 10);
|
|
cv::putText(rightPaint, "distance_zhong:" + to_string(distance_Zhong), cv::Point(100, 200), 1, 5, Scalar(0, 255, 0), 10);
|
|
if (!data->SNcode.compare(snDatas->snErrorsnError))
|
|
data->SNcode = snDatas->waitForSn(data->timeCode);
|
|
int res = avgDatasPtr->insertData(data->SNcode, avgDataCls::mid, distance_Zhong);
|
|
if (res == 3)
|
|
{
|
|
double batterylenth = avgDatasPtr->getAvg(data->SNcode);
|
|
cv::putText(leftPaint, to_string(res) + "times/avg:" + to_string(batterylenth), cv::Point(100, 300), 1, 5, Scalar(0, 255, 0), 10);
|
|
cv::putText(rightPaint, to_string(res) + "times/avg:" + to_string(batterylenth), cv::Point(100, 300), 1, 5, Scalar(0, 255, 0), 10);
|
|
data->sqlVec.push_back({ "batteryLenth",(int)(batterylenth * 1000) });
|
|
}
|
|
}
|
|
|
|
data->resultImgs.push_back(leftPaint);
|
|
data->resultImgs.push_back(rightPaint);
|
|
}
|
|
void algoThread::algoCameraBottom(detData* data)
|
|
{
|
|
if (data->imgs.size() < 2)
|
|
{
|
|
qDebug() << "algoCamera1 img size <2";
|
|
return;
|
|
}
|
|
cv::Mat leftSrc = data->imgs[0];
|
|
cv::Mat rightSrc = data->imgs[1];
|
|
cv::Mat leftPaint;
|
|
cv::Mat rightPaint;
|
|
cvtColor(leftSrc, leftPaint, COLOR_GRAY2BGR);
|
|
cvtColor(rightSrc, rightPaint, COLOR_GRAY2BGR);
|
|
double Pix3 = 0.0058;
|
|
string camre_distan_Down;
|
|
if (getOffSetTimes() == 0)
|
|
{
|
|
offsets offset;
|
|
switch (data->algoThreadIndex)
|
|
{
|
|
case 2:
|
|
camre_distan_Down = offset.camera1Bottom;
|
|
Indexs = 1;
|
|
break;
|
|
case 5:
|
|
camre_distan_Down = offset.camera2Bottom;
|
|
Indexs = 2;
|
|
break;
|
|
case 8:
|
|
camre_distan_Down = offset.camera3Bottom;
|
|
Indexs = 3;
|
|
break;
|
|
case 11:
|
|
camre_distan_Down = offset.camera4Bottom;
|
|
Indexs = 4;
|
|
break;
|
|
}
|
|
}
|
|
else if (getOffSetTimes() == 1)
|
|
{
|
|
offsets2 offset;
|
|
switch (data->algoThreadIndex)
|
|
{
|
|
case 2:
|
|
camre_distan_Down = offset.camera1Bottom;
|
|
Indexs = 1;
|
|
break;
|
|
case 5:
|
|
camre_distan_Down = offset.camera2Bottom;
|
|
Indexs = 2;
|
|
break;
|
|
case 8:
|
|
camre_distan_Down = offset.camera3Bottom;
|
|
Indexs = 3;
|
|
break;
|
|
case 11:
|
|
camre_distan_Down = offset.camera4Bottom;
|
|
Indexs = 4;
|
|
break;
|
|
}
|
|
}
|
|
///////////////////////////////////
|
|
HObject ho_Image1;
|
|
simpleAlgo::MatToHObject(leftSrc, ho_Image1);
|
|
//QThread::msleep(10);
|
|
HObject ho_Image2;
|
|
simpleAlgo::MatToHObject(rightSrc, ho_Image2);
|
|
HTuple hv_Out_line1;
|
|
HTuple hv_Out_line2;
|
|
HTuple hv_Mean_distance1;
|
|
HTuple hv_Make;
|
|
HTuple hv_Path;
|
|
HTuple hv_Diameter{46};
|
|
HTuple hv_Model{0};
|
|
hv_Path = camre_distan_Down.c_str();
|
|
_952_15_Distance_Down( ho_Image1,ho_Image2, hv_Path,
|
|
hv_Model,hv_Diameter, &hv_Out_line1, &hv_Out_line2,
|
|
& hv_Mean_distance1,& hv_Make);
|
|
double distance_Dowm=-99;
|
|
if (hv_Make.D() != -1)
|
|
{
|
|
cv::line(leftPaint, cv::Point(hv_Out_line1[1].D(), hv_Out_line1[0].D()), cv::Point(hv_Out_line1[3].D(), hv_Out_line1[2].D()), Scalar(0, 255, 0), 3);
|
|
cv::line(leftPaint, cv::Point(hv_Out_line1[5].D(), hv_Out_line1[4].D()), cv::Point(hv_Out_line1[7].D(), hv_Out_line1[6].D()), Scalar(0, 255, 0), 3);
|
|
//cv::putText(leftPaint, "hv_Mean_distance1:" + to_string(hv_Mean_distance1.D()), cv::Point(100, 100), 1, 10, Scalar(0, 255, 0), 10);
|
|
distance_Dowm =hv_Mean_distance1.D();
|
|
cv::line(rightPaint, cv::Point(hv_Out_line2[1].D(), hv_Out_line2[0].D()), cv::Point(hv_Out_line2[3].D(), hv_Out_line2[2].D()), Scalar(0, 255, 0), 3);
|
|
cv::line(rightPaint, cv::Point(hv_Out_line2[5].D(), hv_Out_line2[4].D()), cv::Point(hv_Out_line2[7].D(), hv_Out_line2[6].D()), Scalar(0, 255, 0), 3);
|
|
//cv::putText(rightPaint, "hv_Mean_distance2:" + to_string(hv_Mean_distance2.D()), cv::Point(100, 100), 1, 5, Scalar(0, 255, 0), 10);
|
|
cout << "distance_Dowm"<< Indexs<<" " << distance_Dowm << endl;
|
|
cv::putText(leftPaint, "distance_Dowm:" + to_string(distance_Dowm), cv::Point(100, 200), 1, 5, Scalar(0, 255, 0), 10);
|
|
cv::putText(rightPaint, "distance_Dowm:" + to_string(distance_Dowm), cv::Point(100, 200), 1, 5, Scalar(0, 255, 0), 10);
|
|
if (!data->SNcode.compare(snDatas->snErrorsnError))
|
|
data->SNcode = snDatas->waitForSn(data->timeCode);
|
|
int res = avgDatasPtr->insertData(data->SNcode, avgDataCls::btm, distance_Dowm);
|
|
if (res == 3)
|
|
{
|
|
double batterylenth = avgDatasPtr->getAvg(data->SNcode);
|
|
cv::putText(leftPaint, to_string(res) + "times/avg:" + to_string(batterylenth), cv::Point(100, 300), 1, 5, Scalar(0, 255, 0), 10);
|
|
cv::putText(rightPaint, to_string(res) + "times/avg:" + to_string(batterylenth), cv::Point(100, 300), 1, 5, Scalar(0, 255, 0), 10);
|
|
data->sqlVec.push_back({ "batteryLenth",(int)(batterylenth * 1000) });
|
|
}
|
|
}
|
|
|
|
data->resultImgs.push_back(leftPaint);
|
|
data->resultImgs.push_back(rightPaint);
|
|
|
|
|
|
} |