diff --git a/BaseModules/Hd_AI_algo_jixing_cam4/CMakeLists.txt b/BaseModules/Hd_AI_algo_hanHou_T/CMakeLists.txt similarity index 90% rename from BaseModules/Hd_AI_algo_jixing_cam4/CMakeLists.txt rename to BaseModules/Hd_AI_algo_hanHou_T/CMakeLists.txt index 70505c8..be2265d 100644 --- a/BaseModules/Hd_AI_algo_jixing_cam4/CMakeLists.txt +++ b/BaseModules/Hd_AI_algo_hanHou_T/CMakeLists.txt @@ -3,7 +3,7 @@ get_filename_component(CURRENT_FOLDER ${CMAKE_CURRENT_SOURCE_DIR} NAME) string(TIMESTAMP RUN_TIME) message( " model start : " ${CURRENT_FOLDER}:${RUN_TIME}) -set(DLL_NAMES "opencv" "halcon" "Myalgo" "myTools" ) +set(DLL_NAMES "opencv" "halcon" "halconAlgo" "myTools" "handdleAI") foreach(child ${DLL_NAMES}) LIST(APPEND ENV_INCLUDE ${${child}_include}) LIST(APPEND ENV_LIB ${${child}_lib}) @@ -39,7 +39,7 @@ FILE(GLOB UI_FILES "./*.ui") #find_package(Qt5 COMPONENTS Core REQUIRED) find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED) find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED) - +find_package(Qt${QT_VERSION_MAJOR} COMPONENTS network REQUIRED) add_library(${CURRENT_FOLDER} SHARED ${HEAD_FILES} ${SRC_FILES} @@ -58,6 +58,7 @@ set_target_properties(${CURRENT_FOLDER} PROPERTIES LINKER_LANGUAGE C target_link_libraries(${CURRENT_FOLDER} PRIVATE ${ENV_TARGET} Qt${QT_VERSION_MAJOR}::Core + Qt${QT_VERSION_MAJOR}::Network ) diff --git a/BaseModules/Hd_AI_algo_jixing_cam4/Hd_AI_algo_jixing1.cpp b/BaseModules/Hd_AI_algo_hanHou_T/Hd_AI_algo_hanHou.cpp similarity index 65% rename from BaseModules/Hd_AI_algo_jixing_cam4/Hd_AI_algo_jixing1.cpp rename to BaseModules/Hd_AI_algo_hanHou_T/Hd_AI_algo_hanHou.cpp index 7f85c24..5564798 100644 --- a/BaseModules/Hd_AI_algo_jixing_cam4/Hd_AI_algo_jixing1.cpp +++ b/BaseModules/Hd_AI_algo_hanHou_T/Hd_AI_algo_hanHou.cpp @@ -1,94 +1,151 @@ -#include "Hd_AI_algo_jixing1.h" +#include "Hd_AI_algo_hanHou.h" #include -#include + #include #include #include -#include "Myalgo.h" -#include -#include +#include +#include +#include using namespace cv; - -//原图ä¿�存文件夹 -QString oriImgSaveDir = "D:/601线/超声波预焊01机/æž�性检测CCD/原图/"; +QByteArray silieResultText = "0"; +QByteArray fanzheResultText = "0"; +QByteArray jiErWidth = "0"; +QByteArray jiErHeight = "0"; +QByteArray hanYin1 = "0"; +QByteArray hanYin2 = "0"; +//原图ä¿�存文件夹s + QString oriImgSaveDir = "D:/601线/预焊CCD/焊å�Žæ£€æµ‹CCD/原图/"; //原图class图ä¿�存文件夹 -QString classImgSaveDir = "D:/601线/超声波预焊01机/æž�性检测CCD/class图/"; + QString classImgSaveDir = "D:/601线/预焊CCD/焊å�Žæ£€æµ‹CCD/class图/"; //结果ä¿�存文件夹 -QString resImgSaveDir = "D:\\601线\\超声波超声波预焊01机\\æž�性检测CCD\\结果图\\"; + QString resImgSaveDir = "D:/601线/预焊CCD/焊å�Žæ£€æµ‹CCD/结果图/"; //切图的classçš„width,根æ�®é¡¹ç›®å®žé™…设置ï¼� -int sizeW = 150; + int sizeW = 150; //切图的classçš„height,根æ�®é¡¹ç›®å®žé™…设置ï¼� -int sizeH = 150; + int sizeH = 150; //切图的classçš„width,根æ�®é¡¹ç›®å®žé™…设置ï¼�0为黑,255为白; -int fillColour = 0; -int algoResult; + int fillColour = 0; + //检测线程é”� -QMutex* detect_mutex; + QMutex* detect_mutex; //ä¿�存线程é”� -QMutex* saveStruct_mutex; + QMutex* saveStruct_mutex; //检测线程è¿�行标志 -bool ifdetectThread = false; + bool ifdetectThread = false; -QString cameraKey_index = ""; + QString cameraKey_index = ""; -//åˆ�始化å�‚数列表 -QByteArrayList initValueList; -static void createDirectoryIfNotExists(const QString& path) { - QDir dir; - dir.mkpath(path); -} -static std::string getCurrentTime() { + //åˆ�始化å�‚数列表 + QByteArrayList initValueList; + static void createDirectoryIfNotExists(const QString& path) { + QDir dir; + dir.mkpath(path); + } + static std::string getCurrentTime() { - // 获å�–当å‰�时间点 - auto now = std::chrono::system_clock::now(); - - // 转æ�¢ä¸ºå­—符串 - auto currentTime = std::chrono::system_clock::to_time_t(now); - auto ms = std::chrono::duration_cast(now.time_since_epoch()) % 100; - std::tm* localTime = std::localtime(¤tTime); - std::stringstream ss; - ss << std::put_time(localTime, "%H-%M-%S") << "-" << std::setfill('0') << std::setw(2) << ms.count(); - return ss.str(); -} -static QString getCurrentDate() -{ - QDateTime currentDateTime = QDateTime::currentDateTime(); - return currentDateTime.toString("yyyy-MM-dd"); -} -static QString getCurrentHour() -{ - QDateTime currentDateTime = QDateTime::currentDateTime(); - return QString::number(currentDateTime.time().hour()) + "H"; -} -inline std::string utf8_to_gbk(const std::string& str) -{ - std::wstring_convert> conv; - std::wstring tmp_wstr = conv.from_bytes(str); - //GBK locale name in windows - const char* GBK_LOCALE_NAME = ".936"; - std::wstring_convert> convert(new std::codecvt_byname(GBK_LOCALE_NAME)); - return convert.to_bytes(tmp_wstr); -} - -QString byteArrayToUnicode(const QByteArray array) { - - // state用于ä¿�存转æ�¢çжæ€�,它的æˆ�员invalidChars,å�¯ç”¨æ�¥åˆ¤æ–­æ˜¯å�¦è½¬æ�¢æˆ�功 - // 如果转æ�¢æˆ�功,则值为0,如果值大于0,则说明转æ�¢å¤±è´¥ - QTextCodec::ConverterState state; - // å…ˆå°�试使用utf-8的方å¼�把QByteArray转æ�¢æˆ�QString - QString text = QTextCodec::codecForName("UTF-8")->toUnicode(array.constData(), array.size(), &state); - // 如果转æ�¢æ—¶æ— æ•ˆå­—符数é‡�大于0,说明编ç �æ ¼å¼�ä¸�对 - if (state.invalidChars > 0) - { - // å†�å°�试使用GBK的方å¼�进行转æ�¢ï¼Œä¸€èˆ¬å°±èƒ½è½¬æ�¢æ­£ç¡®(当然也å�¯èƒ½æ˜¯å…¶å®ƒæ ¼å¼�,但比较少è§�了) - text = QTextCodec::codecForName("GBK")->toUnicode(array); - } - return text; -} + // 获å�–当å‰�时间点 + auto now = std::chrono::system_clock::now(); + // 转æ�¢ä¸ºå­—符串 + auto currentTime = std::chrono::system_clock::to_time_t(now); + auto ms = std::chrono::duration_cast(now.time_since_epoch()) % 100; + std::tm* localTime = std::localtime(¤tTime); + std::stringstream ss; + ss << std::put_time(localTime, "%H-%M-%S") << "-" << std::setfill('0') << std::setw(2) << ms.count(); + return ss.str(); + } + static QString getCurrentDate() + { + QDateTime currentDateTime = QDateTime::currentDateTime(); + return currentDateTime.toString("yyyy-MM-dd"); + } + static QString getCurrentHour() + { + QDateTime currentDateTime = QDateTime::currentDateTime(); + return QString::number(currentDateTime.time().hour())+"H"; + } + QString byteArrayToUnicode(const QByteArray array) { + // state用于ä¿�存转æ�¢çжæ€�,它的æˆ�员invalidChars,å�¯ç”¨æ�¥åˆ¤æ–­æ˜¯å�¦è½¬æ�¢æˆ�功 + // 如果转æ�¢æˆ�功,则值为0,如果值大于0,则说明转æ�¢å¤±è´¥ + QTextCodec::ConverterState state; + // å…ˆå°�试使用utf-8的方å¼�把QByteArray转æ�¢æˆ�QString + QString text = QTextCodec::codecForName("UTF-8")->toUnicode(array.constData(), array.size(), &state); + // 如果转æ�¢æ—¶æ— æ•ˆå­—符数é‡�大于0,说明编ç �æ ¼å¼�ä¸�对 + if (state.invalidChars > 0) + { + // å†�å°�试使用GBK的方å¼�进行转æ�¢ï¼Œä¸€èˆ¬å°±èƒ½è½¬æ�¢æ­£ç¡®(当然也å�¯èƒ½æ˜¯å…¶å®ƒæ ¼å¼�,但比较少è§�了) + text = QTextCodec::codecForName("GBK")->toUnicode(array); + } + return text; + } + static cv::Rect findMaxAreaContour(cv::Mat src) + { + int maxIndex = 0, maxArea = 0; + std::vector>contours; + cv::findContours(src, contours, cv::noArray(), cv::RETR_EXTERNAL, cv::CHAIN_APPROX_NONE); + if (contours.size() == 0) + return cv::Rect(0, 0, 0, 0); + for (int i = 0; i < contours.size(); i++) + { + int Area = cv::contourArea(contours[i]); + if (Area > maxArea) + { + maxArea = Area; + maxIndex = i; + } + } + if (contours.size() != 0) + return cv::boundingRect(contours[maxIndex]); + return cv::Rect(0, 0, 0, 0); + } + inline std::string utf8_to_gbk(const std::string& str) + { + std::wstring_convert> conv; + std::wstring tmp_wstr = conv.from_bytes(str); + //GBK locale name in windows + const char* GBK_LOCALE_NAME = ".936"; + std::wstring_convert> convert(new std::codecvt_byname(GBK_LOCALE_NAME)); + return convert.to_bytes(tmp_wstr); + } + void getAllFiles(std::string path, std::vector& files, std::string format) + { + intptr_t hFile = 0;//文件å�¥æŸ„ + struct _finddata_t fileinfo;//文件信æ�¯ + std::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); + } + } + QString getOriSaveFromat() + { + return oriImgSaveDir + getCurrentDate() + "//" + getCurrentHour() + "//" + + "ORI_" + cameraKey_index + "_" + QString::fromStdString(getCurrentTime()) + ".bmp"; + } + QString getResSaveFromat() + { + return resImgSaveDir + getCurrentDate() + "//" + getCurrentHour() + "//" + + "RES_" + cameraKey_index + "_" + QString::fromStdString(getCurrentTime()) + ".png"; + } // 缺陷信æ�¯ç»“构体 typedef struct { QString defectName = "";//缺陷å��ç§° @@ -223,6 +280,8 @@ void GetStringSize(HDC hdc, const char* str, int* w, int* h) if (h != 0) *h = size.cy; } //在图åƒ�写中文,英文也å�¯ä»¥å†™ + + void putTextZH(cv::Mat& dst, const char* str, cv::Point org, cv::Scalar color, int fontsize, const char* fn = "Arial", bool italic = false, bool underline = false) { @@ -388,7 +447,7 @@ void drawDefects(cv::Mat& sourceMat, QQueue defectInfoList) //判断文件夹是å�¦å­˜åœ¨ï¼Œä¸�存在则创建 -void Hd_AI_algo_jixing1::isDirExist(QString fullDirName) +void Hd_AI_algo_hanHou::isDirExist(QString fullDirName) { QDir* photo = new QDir; bool exist = photo->exists(fullDirName); @@ -406,28 +465,27 @@ void Hd_AI_algo_jixing1::isDirExist(QString fullDirName) photo = nullptr; } -Hd_AI_algo_jixing1* create() +Hd_AI_algo_hanHou* create() { - qDebug() << "[INFO] " << " Hd_AI_algo_jixing1 create success!"; - return new Hd_AI_algo_jixing1; + qDebug() << "[INFO] " << " Hd_AI_algo_hanHou create success!" ; + return new Hd_AI_algo_hanHou; } -void destory(Hd_AI_algo_jixing1* ptr) +void destory(Hd_AI_algo_hanHou* ptr) { - qDebug() << "[INFO] " << "Hd_AI_algo_jixing1 destory success!"; - if (ptr) + qDebug() << "[INFO] " << "Hd_AI_algo_hanHou destory success!"; + if(ptr) { delete ptr; ptr = nullptr; } } -Hd_AI_algo_jixing1::Hd_AI_algo_jixing1() +Hd_AI_algo_hanHou::Hd_AI_algo_hanHou() { detect_mutex = new QMutex; saveStruct_mutex = new QMutex; ifdetectThread = false; - for (int i = 0; i < 4; i++) { QString DirPath = "E:/testImg/source" + QString::number(i); @@ -447,7 +505,7 @@ Hd_AI_algo_jixing1::Hd_AI_algo_jixing1() } } -Hd_AI_algo_jixing1::~Hd_AI_algo_jixing1() +Hd_AI_algo_hanHou::~Hd_AI_algo_hanHou() { ifdetectThread = false; Sleep(10); @@ -461,29 +519,35 @@ Hd_AI_algo_jixing1::~Hd_AI_algo_jixing1() delete saveStruct_mutex; saveStruct_mutex = nullptr; } + handdleAI::DestroySegObj(seg_hanHouSiLie); + handdleAI::DestroySegObj(seg_hanHouFanZhe); /*DestroySegObj(pSeg); DestroyClsObj(pCls);*/ } //从类中读数æ�®åˆ°å®žä¾‹å¯¹è±¡ -bool Hd_AI_algo_jixing1::readData(std::vector& vec_mat, QByteArray& data) +bool Hd_AI_algo_hanHou::readData(std::vector&vec_mat,QByteArray &data) { detect_mutex->lock(); //qDebug() << __FUNCTION__ << " line:" <<__LINE__ << " data len:" << data.length(); - if (resMat.size() > 0) + if (resMat.size()>0) { vec_mat.push_back(resMat[0]); resMat.clear(); } else { - if (HikMat.size() > 0) + if(HikMat.size()>0) vec_mat.push_back(HikMat[0]); //qDebug() << __FUNCTION__ << " line:" << __LINE__ << " resMat.data err:"; } //if (allNum++ % 2 == 0) // data = "2*3*2";// resByte.dequeue(); //else - data = QByteArray::number(algoResult) + "&" + QByteArray::number(algoResult - 1) + "+" + QByteArray::number(algoResult); + data = "1*&" + fanzheResultText + "&" + silieResultText + + "+" + fanzheResultText + "+" + silieResultText + + "+" + jiErWidth + "+" + jiErHeight + + "+" + hanYin1 + "+" + hanYin2 + ;//1OK,2NG resByte.clear(); ////之å�Žæ ¹æ�®ç»“果类修改 //if(resIfNg == true) @@ -491,41 +555,40 @@ bool Hd_AI_algo_jixing1::readData(std::vector& vec_mat, QByteArray& dat //else data = "OK"; detect_mutex->unlock(); /*if(cameraKey_index.contains('_')) - qDebug() << "[INFO] " << __FUNCTION__ << " line:" << __LINE__ << " checkImg getDetectData--CameraName:" + qDebug() << "[INFO] " << __FUNCTION__ << " line:" << __LINE__ << " checkImg getDetectData--CameraName:" << cameraKey_index.split("_")[0] << " imgIndex:" << cameraKey_index.split("_")[1]; else qDebug() << "[INFO] " << __FUNCTION__ << " line:" << __LINE__ << " checkImg getDetectData--CameraName imgIndex:" << cameraKey_index;*/ return true; } //从类中读数æ�®åˆ°å®žä¾‹å¯¹è±¡ -bool Hd_AI_algo_jixing1::encodeResultValue(QVector append_value, QByteArray& resultByte) +bool Hd_AI_algo_hanHou::encodeResultValue(QVector append_value,QByteArray &resultByte) { try { std::string sendMsg; - for (int i = 0; i < append_value.size(); i++) + for(int i = 0 ; i < append_value.size();i++) { std::string value = append_value.at(1); //type int type = 3; std::string m_type; - m_type.insert(0, 4, '1'); - memcpy((void*)m_type.c_str(), (void*)&type, 4); + m_type.insert(0,4,'1'); + memcpy ( (void*)m_type.c_str(),(void*)&type,4 ); sendMsg.append(m_type); //len int len = value.length(); std::string m_len; - m_len.insert(0, 4, '1'); - memcpy((void*)m_len.c_str(), (void*)&len, 4); + m_len.insert(0,4,'1'); + memcpy ( (void*)m_len.c_str(),(void*)&len,4 ); sendMsg.append(m_len); //data x sendMsg.append(value); } resultByte = QByteArray::fromStdString(sendMsg); - } - catch (QString ev) + } catch (QString ev) { qCritical() << "[Error] " << " ev:" << ev; return false; @@ -533,13 +596,13 @@ bool Hd_AI_algo_jixing1::encodeResultValue(QVector append_value, QB return true; } -int myallNum[4] = { 0 }; +int myallNum[4] = {0}; QMap lastImgMap; //接收数æ�® -bool Hd_AI_algo_jixing1::writeData(std::vector& vec_mat, QByteArray& data) +bool Hd_AI_algo_hanHou::writeData(std::vector& vec_mat, QByteArray &data) { //qDebug() << __FUNCTION__ << "line:"<< __LINE__ << " data len" << data.length() ; - if (vec_mat.empty()) + if(vec_mat.empty()) { qCritical() << "[Error] " << " vec_mat is null !"; return false; @@ -547,7 +610,7 @@ bool Hd_AI_algo_jixing1::writeData(std::vector& vec_mat, QByteArray& da detect_mutex->lock(); HikMat.clear(); for (int i = 0; i < vec_mat.size(); i++) - HikMat.enqueue(vec_mat[i]); + HikMat.enqueue(vec_mat[i]); QByteArray source_savePath; QByteArray sData = data; @@ -558,7 +621,7 @@ bool Hd_AI_algo_jixing1::writeData(std::vector& vec_mat, QByteArray& da cameraKey_index = splitDataList[2]; QByteArray saveDir = splitDataList[0] + "/" + splitDataList[1] + "/"; isDirExist(byteArrayToUnicode(saveDir)); //ä¸�存在,创建 - QString sdataTime = QDateTime::currentDateTime().toString("yyyy-MM-dd-hh-mm-ss-zzz"); + QString sdataTime= QDateTime::currentDateTime().toString("yyyy-MM-dd-hh-mm-ss-zzz"); source_savePath = splitDataList[0] + "/" + splitDataList[1] + "/" + sdataTime.toLocal8Bit() + "-" + splitDataList[2] + "-" + splitDataList[3];// +".bmp"; } //int index = -1; @@ -584,11 +647,8 @@ bool Hd_AI_algo_jixing1::writeData(std::vector& vec_mat, QByteArray& da }*/ - - createDirectoryIfNotExists(oriImgSaveDir + getCurrentDate() + "//" + getCurrentHour() + "//"); - addImgToSaveStruct(HikMat[0], "0", oriImgSaveDir + getCurrentDate() + "//" + getCurrentHour() + "//" - "ORI" + cameraKey_index + QString::fromStdString(getCurrentTime()) + ".bmp");//ä¿�存原图 + addImgToSaveStruct(HikMat[0], "0",getOriSaveFromat());//ä¿�存原图 //if (!source_savePath.isEmpty()) //{ // //std::cout << "try savePath::" << savePath.toStdString() << std::endl; @@ -639,7 +699,7 @@ bool Hd_AI_algo_jixing1::writeData(std::vector& vec_mat, QByteArray& da /*saveKey.enqueue("datalist[0]"); Dir2D.enqueue("datalist[1]"); - QStringList SN_dataTime; + QStringList SN_dataTime; SN_dataTime = datalist[3].split('_'); DateTime1 = "SN_dataTime[1]"; SN.enqueue("SN_dataTime[0]");*/ @@ -656,7 +716,7 @@ bool Hd_AI_algo_jixing1::writeData(std::vector& vec_mat, QByteArray& da //ä¼ å…¥initParas函数,格å¼�为:相机key+å�‚æ•°å��1#å�‚数值1#å�‚数值2+å�‚æ•°å��2#å�‚数值1... //åˆ�始化 -bool Hd_AI_algo_jixing1::initParas(QByteArray& byte) +bool Hd_AI_algo_hanHou::initParas(QByteArray& byte) { initValueList = byte.split('+'); QStringList valueiList; @@ -681,13 +741,13 @@ bool Hd_AI_algo_jixing1::initParas(QByteArray& byte) valueiList.append(valuei); } - /*pSeg = CreateSegObjS(pSeg_modulePath, 128, gpuId); pCls = CreateClsObjV3(pCls_modulePath, gpuId, 1);*/ //StationNo = vec_ret.at(0).toInt(); - + seg_hanHouSiLie = handdleAI::CreateSegObjS("./model/seg-yuHanhanHouSiLie.BHD"); + seg_hanHouFanZhe = handdleAI::CreateSegObjS("./model/seg-yuHanhanFanZhe.BHD"); //InitThreads(StationNo, img2D); //InitModels(StationNo, img2D); @@ -696,9 +756,9 @@ bool Hd_AI_algo_jixing1::initParas(QByteArray& byte) //线程检测:结果类完æˆ�时,使用 //ifThreadRunDetect = true; - //QFuture future1 = QtConcurrent::run(this, &Hd_AI_algo_jixing1::detectThread); + //QFuture future1 = QtConcurrent::run(this, &Hd_AI_algo_hanHou::detectThread); //è¿�行存图线程 - QFuture future2 = QtConcurrent::run(this, &Hd_AI_algo_jixing1::saveImgThread); + QFuture future2 = QtConcurrent::run(this, &Hd_AI_algo_hanHou::saveImgThread); //detectThread(); //原图总文件夹 @@ -708,48 +768,149 @@ bool Hd_AI_algo_jixing1::initParas(QByteArray& byte) //结果图总文件夹 isDirExist(resImgSaveDir); - //qDebug() << "[INFO] " << " StationNo:" << StationNo << " img2D:" << img2D ; return true; } // è§£ç � -bool Hd_AI_algo_jixing1::decodeAiValue(QByteArray byte, QVector& vec_ret) +bool Hd_AI_algo_hanHou::decodeAiValue(QByteArray byte,QVector &vec_ret) { - if (byte.isEmpty()) + if(byte.isEmpty()) { qCritical() << "[Error] " << " byte is null!"; return false; } /*******************************************/ - byte.remove(0, 8); - QByteArray mm_data = byte.mid(0, 4); - memcpy((void*)¶mNum, (void*)mm_data.data(), 4); + byte.remove(0,8); + QByteArray mm_data = byte.mid(0,4); + memcpy((void*)¶mNum,(void*)mm_data.data(), 4); qDebug() << "[INFO] " << " paramNum:" << paramNum; - byte.remove(0, 4); + byte.remove(0,4); /*******************************************/ while (!byte.isEmpty()) { int type = 0; - QByteArray m_type = byte.mid(0, 4); - memcpy((void*)&type, (void*)m_type.data(), 4); - byte.remove(0, 4); + QByteArray m_type = byte.mid(0,4); + memcpy((void*)&type,(void*)m_type.data(), 4); + byte.remove(0,4); int len = 0; - QByteArray m_len = byte.mid(0, 4); - memcpy((void*)&len, (void*)m_len.data(), 4); - byte.remove(0, 4); + QByteArray m_len = byte.mid(0,4); + memcpy((void*)&len,(void*)m_len.data(), 4); + byte.remove(0,4); - QByteArray mm_data = byte.mid(0, len); + QByteArray mm_data = byte.mid(0,len); vec_ret.append(mm_data); - byte.remove(0, len); + byte.remove(0,len); } return true; } +void halconAlgoProcess(cv::Mat& img,cv::Mat &Paint)//算法先画 +{ + HObject ho_Image; + HTuple hv_Pix(0.0303); + HTuple hv_out_line; + HTuple hv_out_Soldering_line; + HTuple hv_distance; + HTuple hv_Make; + MatToHObject(img, &ho_Image); + cs_628_jier_T(ho_Image,hv_Pix,&hv_out_line,&hv_out_Soldering_line, + &hv_distance, & hv_Make); + if (hv_Make.D() == 1) + { + cv::line(Paint, + cv::Point(hv_out_line[1].D() / 2, hv_out_line[0].D() / 2), + cv::Point(hv_out_line[3].D() / 2, hv_out_line[2].D() / 2), + cv::Scalar(0, 255, 0), 5); + cv::line(Paint, + cv::Point(hv_out_line[5].D() / 2, hv_out_line[4].D() / 2), + cv::Point(hv_out_line[7].D() / 2, hv_out_line[6].D() / 2), + cv::Scalar(0, 255, 0), 5); + + cv::line(Paint, + cv::Point(hv_out_line[9].D() / 2, hv_out_line[8].D() / 2), + cv::Point(hv_out_line[11].D() / 2, hv_out_line[10].D() / 2), + cv::Scalar(0, 255, 0), 5); + + cv::line(Paint, + cv::Point(hv_out_line[13].D() / 2, hv_out_line[12].D() / 2), + cv::Point(hv_out_line[15].D() / 2, hv_out_line[14].D() / 2), + cv::Scalar(0, 255, 0), 5); + + cv::line(Paint, + cv::Point(hv_out_Soldering_line[1].D() / 2, hv_out_Soldering_line[0].D() / 2), + cv::Point(hv_out_Soldering_line[3].D() / 2, hv_out_Soldering_line[2].D() / 2), + cv::Scalar(0, 255, 0), 5); + + cv::line(Paint, + cv::Point(hv_out_Soldering_line[5].D() / 2, hv_out_Soldering_line[4].D() / 2), + cv::Point(hv_out_Soldering_line[7].D() / 2, hv_out_Soldering_line[6].D() / 2), + cv::Scalar(0, 255, 0), 5); + + double height = hv_distance[0].D(); + double weight = hv_distance[1].D(); + double upEdge = hv_distance[2].D(); + double leftEdge = hv_distance[3].D(); + + jiErWidth = QByteArray::number(weight); + jiErHeight = QByteArray::number(height); + hanYin1 = QByteArray::number(upEdge); + hanYin2 = QByteArray::number(leftEdge); + + putTextHusky(Paint, utf8_to_gbk("æž�耳高" + std::to_string(height)).c_str(), + cv::Point(0, 0), cv::Scalar(0, 255, 0), 300); + putTextHusky(Paint, utf8_to_gbk("æž�耳宽" + std::to_string(weight)).c_str(), + cv::Point(0, 250), cv::Scalar(0, 255, 0), 300); + putTextHusky(Paint, utf8_to_gbk("上间è·�" + std::to_string(upEdge)).c_str(), + cv::Point(0, 500), cv::Scalar(0, 255, 0), 300); + putTextHusky(Paint, utf8_to_gbk("下间è·�" + std::to_string(leftEdge)).c_str(), + cv::Point(0, 750), cv::Scalar(0, 255, 0), 300); + } + else + putTextHusky(Paint, utf8_to_gbk("算法异常1").c_str(), cv::Point(0, 0), cv::Scalar(0, 255, 0), 300); +} +void siLieProcess(cv::Mat& segRes, cv::Mat& Paint,bool& result) +{ + std::vector> contours; + cv::findContours(segRes, contours, cv::RETR_EXTERNAL, CV_CHAIN_APPROX_NONE); + int cnt = 0; + for (auto r : contours) + { + cv::Rect originRect = cv::boundingRect(r); + if (originRect.width < 50 || originRect.height < 50) + continue; + cv::Rect rect = originRect; + //cv::Mat clsImg = cutImg2Cls(rect, img); + //int clsRes = clsPtr->Evaluate(clsImg); + cv::Scalar color = cv::Scalar(0, 0, 255, 30); + cv::rectangle(Paint, originRect, color, 4); + putTextHusky(Paint, utf8_to_gbk("撕裂").c_str(), cv::Point(rect.x - rect.width / 2, rect.y - rect.height / 2), cv::Scalar(0, 255, 0), 100); + result = false; + } +} +void fanZheProcess(cv::Mat& segRes, cv::Mat& Paint, bool& result) +{ + std::vector> contours; + cv::findContours(segRes, contours, cv::RETR_EXTERNAL, CV_CHAIN_APPROX_NONE); + int cnt = 0; + for (auto r : contours) + { + cv::Rect originRect = cv::boundingRect(r); + if (originRect.width < 100 || originRect.height < 50) + continue; + cv::Rect rect = originRect; + //cv::Mat clsImg = cutImg2Cls(rect, img); + //int clsRes = clsPtr->Evaluate(clsImg); + cv::Scalar color = cv::Scalar(0, 0, 255, 30); + cv::rectangle(Paint, originRect, color, 4); + putTextHusky(Paint, utf8_to_gbk("翻折").c_str(), cv::Point(rect.x- rect.width/2, rect.y-rect.height/2), cv::Scalar(0, 255, 0), 100); + result = false; + } +} //---------检测æµ�程,根æ�®å®žé™…项目修改--------- -bool Hd_AI_algo_jixing1::AIdetect(cv::Mat img2D, QString mysaveKey, QString myDir2D, QString mySN, QString myDataTime) +bool Hd_AI_algo_hanHou::AIdetect(cv::Mat img2D, QString mysaveKey, QString myDir2D, QString mySN, QString myDataTime) { try { @@ -779,63 +940,40 @@ bool Hd_AI_algo_jixing1::AIdetect(cv::Mat img2D, QString mysaveKey, QString myDi // csvName.write(lines[i].toStdString().c_str()); // csvName.close(); //} - + //sourceImg = cv::imread("D:\\mySN15-46-33-86.bmp",-1); + sourceImg = cv::imread("D:/1/Image_20241017204025590.bmp", -1); + cv::Mat Paint; + sourceImg.copyTo(Paint); + if(Paint.channels() == 1) + cvtColor(Paint, Paint, COLOR_GRAY2BGR); QQueue defectInfoList; - //æž�性检测 - HObject ho_Image; - HTuple hv_out_Value; - HTuple hv_Make; - //cv::imwrite("C://1.bmp", sourceImg); - MatToHObject(sourceImg, &ho_Image); - _628_1_Polarity_detection(ho_Image, &hv_out_Value, &hv_Make); - //相机1 OK为é“� NG为铜s - if (hv_Make.D() != -1) - { - if (hv_out_Value.D() == 1)//é“� - { - putTextHusky(sourceImg, utf8_to_gbk("é“�æž�").c_str(), cv::Point(0, 0), cv::Scalar(0, 255, 0), 300); - //cv::putText(sourceImg, "Aluminium", cv::Point(0, 240), 2, 10, cv::Scalar(0, 255, 0), 10); - cv::putText(sourceImg, "OK", cv::Point(0, 550), 2, 10, cv::Scalar(0, 255, 0), 10); - algoResult = 1; - //Result = 1 ? 2; - //Result = 1; - } - else if (hv_out_Value.D() == 2)//铜 - { - putTextHusky(sourceImg, utf8_to_gbk("铜æž�").c_str(), cv::Point(0, 0), cv::Scalar(0, 255, 0), 300); - //cv::putText(sourceImg, "Copper", cv::Point(0, 240), 2, 10, cv::Scalar(0, 255, 0), 10); - cv::putText(sourceImg, "NG", cv::Point(0, 550), 2, 10, cv::Scalar(0, 0, 255), 10); - algoResult = 1; - } - else - { - putTextHusky(sourceImg, utf8_to_gbk("算法异常1").c_str(), cv::Point(0, 0), cv::Scalar(0, 255, 0), 300); - // cv::putText(sourceImg, "Algo error1", cv::Point(0, 240), 2, 10, cv::Scalar(0, 0, 255), 10); - //Result = 2; - } - } - else - { - putTextHusky(sourceImg, utf8_to_gbk("算法异常1").c_str(), cv::Point(0, 0), cv::Scalar(0, 255, 0), 300); - // cv::putText(sourceImg, "Algo error2", cv::Point(0, 240), 2, 10, cv::Scalar(0, 0, 255), 10); - } - - ho_Image.Clear(); - hv_out_Value.Clear(); - hv_Make.Clear(); - + detect_mutex->lock(); - //resMat = sourceImg.clone(); - //sourceImg.copyTo(resMat); - resMat.push_back(sourceImg); - //结果图画框和缺陷,在resMat上绘制 - if (resMat.size() > 0) - drawDefects(resMat[0], defectInfoList); + + auto futrue = std::async(std::launch::async, halconAlgoProcess, sourceImg, Paint);//异步执行 + cv::Mat segProcess; + cv::resize(sourceImg, segProcess, cv::Size(), 0.5, 0.5); + //撕裂检测 + cv::Mat siLieSegRes = ~seg_hanHouSiLie->Evaluate(segProcess);//撕裂 + cv::Mat fanZheSegRes = ~seg_hanHouFanZhe->Evaluate(segProcess);//翻折 + futrue.wait();//等待halcon算法完æˆ� + bool silieOk = true, fanZheOk = true; + siLieProcess(siLieSegRes, Paint, silieOk); + fanZheProcess(fanZheSegRes, Paint, fanZheOk); - //QByteArray,根æ�®å®žé™…项目进行解æž� - //å�‚æ•°,例:返回结果图;相机关键字(SN或userID)+ä¿�存路径+缺陷信æ�¯åˆ—表(缺陷å��称,缺陷ä½�ç½®int(x,y,w,h),画框颜色Scalar(a,b,c),缺陷é�¢ç§¯double) + if (silieOk == true)//OK + putTextHusky(Paint, utf8_to_gbk("撕裂OK").c_str(), cv::Point(4800, 50), cv::Scalar(0, 255, 0), 500); + else + putTextHusky(Paint, utf8_to_gbk("撕裂NG").c_str(), cv::Point(4800, 50), cv::Scalar(0, 0, 255), 500); + + if (fanZheOk == true)//OK + putTextHusky(Paint, utf8_to_gbk("翻折OK").c_str(), cv::Point(4800, 300), cv::Scalar(0, 255, 0), 500); + else + putTextHusky(Paint, utf8_to_gbk("翻折NG").c_str(), cv::Point(4800, 300), cv::Scalar(0, 0, 255), 500); + + resMat.push_back(Paint); QJsonArray detaillists; //QByteArrayList resQbyte; for (int i = 0; i < defectInfoList.size(); i++) @@ -857,10 +995,10 @@ bool Hd_AI_algo_jixing1::AIdetect(cv::Mat img2D, QString mysaveKey, QString myDi detailObj.insert("defectRect.width", QString::number(mdefect.defectRect.width)); detailObj.insert("defectRect.height", QString::number(mdefect.defectRect.height)); detailObj.insert("defectScalar0", QString::number(mdefect.defectScalar[0])); - detailObj.insert("defectScalar1", QString::number(mdefect.defectScalar[1])); + detailObj.insert("defectScalar1", QString::number(mdefect.defectScalar[1])); detailObj.insert("defectScalar2", QString::number(mdefect.defectScalar[2])); detailObj.insert("defectArea", QString::number(mdefect.defectArea)); - detailObj.insert("defectLength", QString::number(sqrt(mdefect.defectRect.width * mdefect.defectRect.width + mdefect.defectRect.height * mdefect.defectRect.height))); + detailObj.insert("defectLength", QString::number(sqrt(mdefect.defectRect.width* mdefect.defectRect.width+ mdefect.defectRect.height* mdefect.defectRect.height))); detaillists.append(detailObj); } @@ -873,15 +1011,13 @@ bool Hd_AI_algo_jixing1::AIdetect(cv::Mat img2D, QString mysaveKey, QString myDi //emit sendResultData(resMat, resQbyte); //resQbyte.clear(); - isDirExist(resImgSaveDir + mysaveKey1 + "/"); + //isDirExist(resImgSaveDir + mysaveKey1 + "/"); QString qimgsavePath = resImgSaveDir + mysaveKey1 + "/" + mySN + myDataTime + ".png"; //存图数æ�®å…¥é˜Ÿ,按需 - QString sdataTime = QDateTime::currentDateTime().toString("yyyy-MM-dd-hh-mm-ss-zzz"); - if (resMat.size() > 0) + if (resMat.size() > 0 ) { - createDirectoryIfNotExists(oriImgSaveDir + getCurrentDate() + "//" + getCurrentHour() + "//"); - addImgToSaveStruct(HikMat[0], "0", resImgSaveDir + getCurrentDate() + "//" + getCurrentHour() + "//" - + "RES" + cameraKey_index + QString::fromStdString(getCurrentTime()) + ".png");//ä¿�存原图 + createDirectoryIfNotExists(resImgSaveDir + getCurrentDate() + "//" + getCurrentHour() + "//"); + addImgToSaveStruct(resMat[0], "0", getResSaveFromat());//ä¿�存原图 } detect_mutex->unlock(); @@ -925,7 +1061,7 @@ bool Hd_AI_algo_jixing1::AIdetect(cv::Mat img2D, QString mysaveKey, QString myDi } //存图加入队列 -void Hd_AI_algo_jixing1::addImgToSaveStruct(cv::Mat img2D, QString mysaveKey, QString savePath) +void Hd_AI_algo_hanHou::addImgToSaveStruct(cv::Mat img2D, QString mysaveKey, QString savePath) { //存图数æ�®åŠ ä¿�存队列,加é”�,é�¿å…�æ•°æ�®è®¿é—®å†²çª� saveStruct_mutex->lock(); @@ -937,7 +1073,7 @@ void Hd_AI_algo_jixing1::addImgToSaveStruct(cv::Mat img2D, QString mysaveKey, QS saveStruct.enqueue(mySave); saveStruct_mutex->unlock(); } -void Hd_AI_algo_jixing1::saveImgThread() +void Hd_AI_algo_hanHou::saveImgThread() { while (1) { @@ -953,7 +1089,7 @@ void Hd_AI_algo_jixing1::saveImgThread() saveImgStruct mysaveStruct = saveStruct.dequeue(); saveStruct_mutex->unlock(); stop = clock(); - if (stop - start > 1000) + if(stop-start >1000) std::cout << "lock stop-start >1000::************************" << stop - start << std::endl; start = clock(); if (mysaveStruct.out_Mat.data) @@ -961,17 +1097,17 @@ void Hd_AI_algo_jixing1::saveImgThread() //std::cout << "savePath::" << mysaveStruct.savePath << std::endl; stop = clock(); if (stop - start > 1000) - std::cout << "imwrite stop-start >1000::--------------------------" << stop - start << std::endl; + std::cout << "imwrite stop-start >1000::--------------------------"<< stop - start << std::endl; _sleep(1); } } } //检测线程,应当å�ªè¿�行一次 -void Hd_AI_algo_jixing1::detectThread() +void Hd_AI_algo_hanHou::detectThread() { do { - if (!ifdetectThread)return; + if (!ifdetectThread)return; //此两行代ç �,é�¿å…�程åº�å�¡æ­»ï¼›_sleep的时间根æ�®å®žé™…项目调整 _sleep(2); @@ -1001,9 +1137,9 @@ void Hd_AI_algo_jixing1::detectThread() isDirExist(resImgSaveDir + mysaveKey); } - + //测试相机的, - //while (sourceImg1.cols > 2000)cv::resize(sourceImg1, sourceImg1, cv::Size(), 0.5, 0.5); + // while (sourceImg1.cols > 2000)cv::resize(sourceImg1, sourceImg1, cv::Size(), 0.5, 0.5); //存图数æ�®å…¥é˜Ÿ //addImgToSaveStruct(sourceImg1, mysaveKey, oriImgSaveDir + mysaveKey + "/" + mySN + myDataTime + ".bmp"); @@ -1016,14 +1152,14 @@ void Hd_AI_algo_jixing1::detectThread() myDir2D.clear(); mySN.clear(); myDataTime.clear(); - qApp->processEvents(); + qApp->processEvents(); } while (ifThreadRunDetect); - + } static int runNum = 0; -bool Hd_AI_algo_jixing1::run() +bool Hd_AI_algo_hanHou::run() { clock_t start, stop; start = clock(); @@ -1031,14 +1167,14 @@ bool Hd_AI_algo_jixing1::run() //Sleep(1000); detectThread(); stop = clock(); - qDebug() << __FUNCTION__ << "line:" << __LINE__ << " run start ::runNum::" << runNum++ << " cutTime::" << stop - start; - + qDebug() << __FUNCTION__ << "line:" << __LINE__ << " run start ::runNum::" << runNum++<<" cutTime::"< #include @@ -15,13 +15,11 @@ #include #include #include - #include #include #include "imgproc/imgproc_c.h" - #include "base.h" - +#include "handleAI.h" #pragma execution_character_set("utf-8") @@ -34,14 +32,14 @@ struct saveImgStruct; // std::string savePath; //ä¿�存路径 //}; -//åˆ�始化æµ�程(一次):Hd_AI_algo_jixing1,initParas +//åˆ�始化æµ�程(一次):Hd_AI_algo_hanHou,initParas //è¿�行æµ�程:writeData主线程把数æ�®ä¼ è¿‡æ�¥ï¼Œrun,readData此线程把数æ�®ä¼ ä¸»çº¿ç¨‹ -class Hd_AI_algo_jixing1 :public Base +class Hd_AI_algo_hanHou :public Base { Q_OBJECT public: - Hd_AI_algo_jixing1(); - virtual ~Hd_AI_algo_jixing1(); + Hd_AI_algo_hanHou(); + virtual ~Hd_AI_algo_hanHou(); //从类中读数æ�®åˆ°å®žä¾‹å¯¹è±¡ bool readData(std::vector&,QByteArray&); //实例对象把数æ�®å†™å…¥åˆ°ç±» @@ -56,11 +54,10 @@ public: bool decodeAiValue(QByteArray byte,QVector &vec_ret); //---------检测æµ�程,根æ�®å®žé™…项目修改--------- bool AIdetect(cv::Mat img2D, QString saveKey, QString Dir2D, QString SN, QString DataTime); - - + handdleAI::pSegmentation* seg_hanHouSiLie; + handdleAI::pSegmentation* seg_hanHouFanZhe; private: - int allNum = 0; int StationNo=0; int img2D = 2; @@ -106,8 +103,8 @@ private: extern "C" { - Q_DECL_EXPORT Hd_AI_algo_jixing1 * create(); - Q_DECL_EXPORT void destory(Hd_AI_algo_jixing1 * ptr); + Q_DECL_EXPORT Hd_AI_algo_hanHou * create(); + Q_DECL_EXPORT void destory(Hd_AI_algo_hanHou * ptr); } //ä¿�存图片的结构体 struct saveImgStruct diff --git a/BaseModules/Hd_AI_algo_jixing_cam1/base.h b/BaseModules/Hd_AI_algo_hanHou_T/base.h similarity index 100% rename from BaseModules/Hd_AI_algo_jixing_cam1/base.h rename to BaseModules/Hd_AI_algo_hanHou_T/base.h diff --git a/BaseModules/Hd_AI_algo_jixing_cam3/CMakeLists.txt b/BaseModules/Hd_AI_algo_jixing_L/CMakeLists.txt similarity index 96% rename from BaseModules/Hd_AI_algo_jixing_cam3/CMakeLists.txt rename to BaseModules/Hd_AI_algo_jixing_L/CMakeLists.txt index 70505c8..dae4491 100644 --- a/BaseModules/Hd_AI_algo_jixing_cam3/CMakeLists.txt +++ b/BaseModules/Hd_AI_algo_jixing_L/CMakeLists.txt @@ -3,7 +3,7 @@ get_filename_component(CURRENT_FOLDER ${CMAKE_CURRENT_SOURCE_DIR} NAME) string(TIMESTAMP RUN_TIME) message( " model start : " ${CURRENT_FOLDER}:${RUN_TIME}) -set(DLL_NAMES "opencv" "halcon" "Myalgo" "myTools" ) +set(DLL_NAMES "opencv" "halcon" "halconAlgo""myTools" ) foreach(child ${DLL_NAMES}) LIST(APPEND ENV_INCLUDE ${${child}_include}) LIST(APPEND ENV_LIB ${${child}_lib}) diff --git a/BaseModules/Hd_AI_algo_jixing_cam1/Hd_AI_algo_jixing1.cpp b/BaseModules/Hd_AI_algo_jixing_L/Hd_AI_algo_jixing1.cpp similarity index 98% rename from BaseModules/Hd_AI_algo_jixing_cam1/Hd_AI_algo_jixing1.cpp rename to BaseModules/Hd_AI_algo_jixing_L/Hd_AI_algo_jixing1.cpp index 05c9777..759437e 100644 --- a/BaseModules/Hd_AI_algo_jixing_cam1/Hd_AI_algo_jixing1.cpp +++ b/BaseModules/Hd_AI_algo_jixing_L/Hd_AI_algo_jixing1.cpp @@ -4,9 +4,9 @@ #include #include #include -#include "Myalgo.h" #include #include +#include using namespace cv; //原图ä¿�存文件夹 @@ -14,7 +14,7 @@ using namespace cv; //原图class图ä¿�存文件夹 QString classImgSaveDir = "D:/601线/超声波预焊01机/æž�性检测CCD/class图/"; //结果ä¿�存文件夹 - QString resImgSaveDir = "D:\\601线\\超声波超声波预焊01机\\æž�性检测CCD\\结果图\\"; + QString resImgSaveDir = "D:/601线/超声波超声波预焊01机/æž�性检测CCD/结果图/"; //切图的classçš„width,根æ�®é¡¹ç›®å®žé™…设置ï¼� int sizeW = 150; @@ -71,7 +71,16 @@ int algoResult; std::wstring_convert> convert(new std::codecvt_byname(GBK_LOCALE_NAME)); return convert.to_bytes(tmp_wstr); } - + QString getOriSaveFromat() + { + return oriImgSaveDir + getCurrentDate() + "//" + getCurrentHour() + "//" + + "ORI_" + cameraKey_index + "_" + QString::fromStdString(getCurrentTime()) + ".bmp"; + } + QString getResSaveFromat() + { + return resImgSaveDir + getCurrentDate() + "//" + getCurrentHour() + "//" + + "RES_" + cameraKey_index + "_" + QString::fromStdString(getCurrentTime()) + ".png"; + } QString byteArrayToUnicode(const QByteArray array) { // state用于ä¿�存转æ�¢çжæ€�,它的æˆ�员invalidChars,å�¯ç”¨æ�¥åˆ¤æ–­æ˜¯å�¦è½¬æ�¢æˆ�功 @@ -586,8 +595,7 @@ bool Hd_AI_algo_jixing1::writeData(std::vector& vec_mat, QByteArray &da createDirectoryIfNotExists(oriImgSaveDir + getCurrentDate() + "//" + getCurrentHour() + "//"); - addImgToSaveStruct(HikMat[0], "0", oriImgSaveDir + getCurrentDate() + "//" + getCurrentHour() + "//" - "ORI" +cameraKey_index +QString::fromStdString(getCurrentTime())+".bmp");//ä¿�存原图 + addImgToSaveStruct(HikMat[0], "0", getOriSaveFromat());//ä¿�存原图 //if (!source_savePath.isEmpty()) //{ // //std::cout << "try savePath::" << savePath.toStdString() << std::endl; @@ -879,8 +887,7 @@ bool Hd_AI_algo_jixing1::AIdetect(cv::Mat img2D, QString mysaveKey, QString myDi if (resMat.size() > 0) { createDirectoryIfNotExists(oriImgSaveDir + getCurrentDate() + "//" + getCurrentHour() + "//"); - addImgToSaveStruct(HikMat[0], "0", resImgSaveDir + getCurrentDate() + "//" + getCurrentHour() + "//" - + "RES" + cameraKey_index + QString::fromStdString(getCurrentTime()) + ".png");//ä¿�存原图 + addImgToSaveStruct(resMat[0], "0", getResSaveFromat());//ä¿�存原图 } detect_mutex->unlock(); diff --git a/BaseModules/Hd_AI_algo_jixing_cam1/Hd_AI_algo_jixing1.h b/BaseModules/Hd_AI_algo_jixing_L/Hd_AI_algo_jixing1.h similarity index 100% rename from BaseModules/Hd_AI_algo_jixing_cam1/Hd_AI_algo_jixing1.h rename to BaseModules/Hd_AI_algo_jixing_L/Hd_AI_algo_jixing1.h diff --git a/BaseModules/Hd_AI_algo_jixing_cam2/base.h b/BaseModules/Hd_AI_algo_jixing_L/base.h similarity index 100% rename from BaseModules/Hd_AI_algo_jixing_cam2/base.h rename to BaseModules/Hd_AI_algo_jixing_L/base.h diff --git a/BaseModules/Hd_AI_algo_jixing_cam2/CMakeLists.txt b/BaseModules/Hd_AI_algo_jixing_T/CMakeLists.txt similarity index 96% rename from BaseModules/Hd_AI_algo_jixing_cam2/CMakeLists.txt rename to BaseModules/Hd_AI_algo_jixing_T/CMakeLists.txt index 70505c8..be21793 100644 --- a/BaseModules/Hd_AI_algo_jixing_cam2/CMakeLists.txt +++ b/BaseModules/Hd_AI_algo_jixing_T/CMakeLists.txt @@ -3,7 +3,7 @@ get_filename_component(CURRENT_FOLDER ${CMAKE_CURRENT_SOURCE_DIR} NAME) string(TIMESTAMP RUN_TIME) message( " model start : " ${CURRENT_FOLDER}:${RUN_TIME}) -set(DLL_NAMES "opencv" "halcon" "Myalgo" "myTools" ) +set(DLL_NAMES "opencv" "halcon" "halconAlgo" "myTools" ) foreach(child ${DLL_NAMES}) LIST(APPEND ENV_INCLUDE ${${child}_include}) LIST(APPEND ENV_LIB ${${child}_lib}) diff --git a/BaseModules/Hd_AI_algo_jixing_cam2/Hd_AI_algo_jixing1.cpp b/BaseModules/Hd_AI_algo_jixing_T/Hd_AI_algo_jixing1.cpp similarity index 98% rename from BaseModules/Hd_AI_algo_jixing_cam2/Hd_AI_algo_jixing1.cpp rename to BaseModules/Hd_AI_algo_jixing_T/Hd_AI_algo_jixing1.cpp index 9c12093..0f6ba81 100644 --- a/BaseModules/Hd_AI_algo_jixing_cam2/Hd_AI_algo_jixing1.cpp +++ b/BaseModules/Hd_AI_algo_jixing_T/Hd_AI_algo_jixing1.cpp @@ -4,7 +4,7 @@ #include #include #include -#include "Myalgo.h" +#include #include #include #include @@ -15,7 +15,7 @@ using namespace cv; //原图class图ä¿�存文件夹 QString classImgSaveDir = "D:/601线/超声波预焊01机/æž�性检测CCD/class图/"; //结果ä¿�存文件夹 - QString resImgSaveDir = "D:\\601线\\超声波超声波预焊01机\\æž�性检测CCD\\结果图\\"; + QString resImgSaveDir = "D:/601线/超声波超声波预焊01机/æž�性检测CCD/结果图/"; //切图的classçš„width,根æ�®é¡¹ç›®å®žé™…设置ï¼� int sizeW = 150; @@ -87,7 +87,16 @@ int algoResult; } return text; } - + QString getOriSaveFromat() + { + return oriImgSaveDir + getCurrentDate() + "//" + getCurrentHour() + "//" + + "ORI_" + cameraKey_index + "_" + QString::fromStdString(getCurrentTime()) + ".bmp"; + } + QString getResSaveFromat() + { + return resImgSaveDir + getCurrentDate() + "//" + getCurrentHour() + "//" + + "RES_" + cameraKey_index + "_" + QString::fromStdString(getCurrentTime()) + ".png"; + } // 缺陷信æ�¯ç»“构体 typedef struct { @@ -586,8 +595,7 @@ bool Hd_AI_algo_jixing1::writeData(std::vector& vec_mat, QByteArray &da createDirectoryIfNotExists(oriImgSaveDir + getCurrentDate() + "//" + getCurrentHour() + "//"); - addImgToSaveStruct(HikMat[0], "0", oriImgSaveDir + getCurrentDate() + "//" + getCurrentHour() + "//" - "ORI" +cameraKey_index +QString::fromStdString(getCurrentTime())+".bmp");//ä¿�存原图 + addImgToSaveStruct(HikMat[0], "0", getOriSaveFromat());//ä¿�存原图 //if (myallNum[index] == 1) //{ @@ -862,8 +870,7 @@ bool Hd_AI_algo_jixing1::AIdetect(cv::Mat img2D, QString mysaveKey, QString myDi if (resMat.size() > 0) { createDirectoryIfNotExists(oriImgSaveDir + getCurrentDate() + "//" + getCurrentHour() + "//"); - addImgToSaveStruct(HikMat[0], "0", resImgSaveDir + getCurrentDate() + "//" + getCurrentHour() + "//" - + "RES" + cameraKey_index + QString::fromStdString(getCurrentTime()) + ".png");//ä¿�存原图 + addImgToSaveStruct(resMat[0], "0", getResSaveFromat());//ä¿�存原图 } detect_mutex->unlock(); diff --git a/BaseModules/Hd_AI_algo_jixing_cam2/Hd_AI_algo_jixing1.h b/BaseModules/Hd_AI_algo_jixing_T/Hd_AI_algo_jixing1.h similarity index 100% rename from BaseModules/Hd_AI_algo_jixing_cam2/Hd_AI_algo_jixing1.h rename to BaseModules/Hd_AI_algo_jixing_T/Hd_AI_algo_jixing1.h diff --git a/BaseModules/Hd_AI_algo_jixing_cam3/base.h b/BaseModules/Hd_AI_algo_jixing_T/base.h similarity index 100% rename from BaseModules/Hd_AI_algo_jixing_cam3/base.h rename to BaseModules/Hd_AI_algo_jixing_T/base.h diff --git a/BaseModules/Hd_AI_algo_jixing_cam3/Hd_AI_algo_jixing1.cpp b/BaseModules/Hd_AI_algo_jixing_cam3/Hd_AI_algo_jixing1.cpp deleted file mode 100644 index 3f00e0f..0000000 --- a/BaseModules/Hd_AI_algo_jixing_cam3/Hd_AI_algo_jixing1.cpp +++ /dev/null @@ -1,1029 +0,0 @@ -#include "Hd_AI_algo_jixing1.h" -#include -#include -#include -#include -#include -#include "Myalgo.h" -#include -#include -#include -using namespace cv; - -//原图ä¿�存文件夹 -QString oriImgSaveDir = "D:/601线/超声波预焊01机/æž�性检测CCD/原图/"; -//原图class图ä¿�存文件夹 -QString classImgSaveDir = "D:/601线/超声波预焊01机/æž�性检测CCD/class图/"; -//结果ä¿�存文件夹 -QString resImgSaveDir = "D:\\601线\\超声波超声波预焊01机\\æž�性检测CCD\\结果图\\"; - -//切图的classçš„width,根æ�®é¡¹ç›®å®žé™…设置ï¼� -int sizeW = 150; -//切图的classçš„height,根æ�®é¡¹ç›®å®žé™…设置ï¼� -int sizeH = 150; -//切图的classçš„width,根æ�®é¡¹ç›®å®žé™…设置ï¼�0为黑,255为白; -int fillColour = 0; -int algoResult; - -//检测线程é”� -QMutex* detect_mutex; -//ä¿�存线程é”� -QMutex* saveStruct_mutex; -//检测线程è¿�行标志 -bool ifdetectThread = false; - -QString cameraKey_index = ""; - -//åˆ�始化å�‚数列表 -QByteArrayList initValueList; -static void createDirectoryIfNotExists(const QString& path) { - QDir dir; - dir.mkpath(path); -} -static std::string getCurrentTime() { - - // 获å�–当å‰�时间点 - auto now = std::chrono::system_clock::now(); - - // 转æ�¢ä¸ºå­—符串 - auto currentTime = std::chrono::system_clock::to_time_t(now); - auto ms = std::chrono::duration_cast(now.time_since_epoch()) % 100; - std::tm* localTime = std::localtime(¤tTime); - std::stringstream ss; - ss << std::put_time(localTime, "%H-%M-%S") << "-" << std::setfill('0') << std::setw(2) << ms.count(); - return ss.str(); -} -static QString getCurrentDate() -{ - QDateTime currentDateTime = QDateTime::currentDateTime(); - return currentDateTime.toString("yyyy-MM-dd"); -} -static QString getCurrentHour() -{ - QDateTime currentDateTime = QDateTime::currentDateTime(); - return QString::number(currentDateTime.time().hour()) + "H"; -} -inline std::string utf8_to_gbk(const std::string& str) -{ - std::wstring_convert> conv; - std::wstring tmp_wstr = conv.from_bytes(str); - //GBK locale name in windows - const char* GBK_LOCALE_NAME = ".936"; - std::wstring_convert> convert(new std::codecvt_byname(GBK_LOCALE_NAME)); - return convert.to_bytes(tmp_wstr); -} -QString byteArrayToUnicode(const QByteArray array) { - - // state用于ä¿�存转æ�¢çжæ€�,它的æˆ�员invalidChars,å�¯ç”¨æ�¥åˆ¤æ–­æ˜¯å�¦è½¬æ�¢æˆ�功 - // 如果转æ�¢æˆ�功,则值为0,如果值大于0,则说明转æ�¢å¤±è´¥ - QTextCodec::ConverterState state; - // å…ˆå°�试使用utf-8的方å¼�把QByteArray转æ�¢æˆ�QString - QString text = QTextCodec::codecForName("UTF-8")->toUnicode(array.constData(), array.size(), &state); - // 如果转æ�¢æ—¶æ— æ•ˆå­—符数é‡�大于0,说明编ç �æ ¼å¼�ä¸�对 - if (state.invalidChars > 0) - { - // å†�å°�试使用GBK的方å¼�进行转æ�¢ï¼Œä¸€èˆ¬å°±èƒ½è½¬æ�¢æ­£ç¡®(当然也å�¯èƒ½æ˜¯å…¶å®ƒæ ¼å¼�,但比较少è§�了) - text = QTextCodec::codecForName("GBK")->toUnicode(array); - } - return text; -} - - -// 缺陷信æ�¯ç»“构体 -typedef struct { - QString defectName = "";//缺陷å��ç§° - cv::Rect defectRect = { 0,0,0,0 };//缺陷ä½�ç½® - cv::Scalar defectScalar = cv::Scalar(0, 0, 0);//画框颜色 - double defectArea = 0;//缺陷真实é�¢ç§¯ - double defectDepth = 0;//缺陷深度/高度,3Dä¿¡æ�¯ -}defectInfo; - -//Mat转Halcon图åƒ� -void MatToHObject(cv::Mat& image, HalconCpp::HObject* Hobj) -{ - int hgt = image.rows; - int wid = image.cols; - int i; - if (image.type() == CV_8UC3) - { - HalconCpp::HImage himage = HalconCpp::HImage(); - - std::vector imgchannel; - split(image, imgchannel); - cv::Mat imgB = imgchannel[0]; - cv::Mat imgG = imgchannel[1]; - cv::Mat imgR = imgchannel[2]; - uchar* dataR = new uchar[hgt * wid]; - uchar* dataG = new uchar[hgt * wid]; - uchar* dataB = new uchar[hgt * wid]; - for (i = 0; i < hgt; i++) - { - memcpy(dataR + wid * i, imgR.data + imgR.step * i, wid); - memcpy(dataG + wid * i, imgG.data + imgG.step * i, wid); - memcpy(dataB + wid * i, imgB.data + imgB.step * i, wid); - } - himage.GenImage3("byte", wid, hgt, dataR, dataG, dataB); - HalconCpp::HString tmpType; - Hlong tmpW, tmpH; - void* hImgPtR, * hImgPtG, * hImgPtB; - himage.GetImagePointer3(&hImgPtR, &hImgPtG, &hImgPtB, &tmpType, &tmpW, &tmpH); - - GenImage3(Hobj, "byte", wid, hgt, (Hlong)hImgPtR, (Hlong)hImgPtG, (Hlong)hImgPtB); - delete[]dataR; - delete[]dataG; - delete[]dataB; - dataR = NULL; - dataG = NULL; - dataB = NULL; - } - else if (image.type() == CV_8UC1) - { - //HalconCpp::HImage himage = HalconCpp::HImage(); - - ////uchar* data = new uchar[hgt * wid]; - ////for (i = 0; i < hgt; i++) - ////{ - //// memcpy(data + wid * i, image.data + image.step * i, wid); - ////} - ////gen_image_const - //himage.GenImage1("byte", wid, hgt, image.data); - - //HalconCpp::HString tmpType; - //Hlong tmpW, tmpH; - //void* hImgPt; - //hImgPt = himage.GetImagePointer1(&tmpType, &tmpW, &tmpH); - //GenImage1(&Hobj, "byte", wid, hgt, (Hlong)hImgPt); - GenImage1(Hobj, "byte", wid, hgt, (Hlong)image.data); - - /* delete[] data; - data = NULL;*/ - - } - else if (image.type() == CV_16UC1) - { - HalconCpp::HImage himage = HalconCpp::HImage(); - - ushort* data = new ushort[hgt * wid * 2]; - - memcpy(data, image.data, hgt * wid * 2); - - - himage.GenImage1("uint2", wid, hgt, data); - - HalconCpp::HString tmpType; - Hlong tmpW, tmpH; - void* hImgPt; - hImgPt = himage.GetImagePointer1(&tmpType, &tmpW, &tmpH); - GenImage1(Hobj, "uint2", wid, hgt, (Hlong)hImgPt); - - delete[] data; - data = NULL; - - } - else if (image.type() == CV_16SC1) - { - HalconCpp::HImage himage = HalconCpp::HImage(); - - short* data = new short[hgt * wid * 2]; - - memcpy(data, image.data, hgt * wid * 2); - - - himage.GenImage1("int2", wid, hgt, data); - - HalconCpp::HString tmpType; - Hlong tmpW, tmpH; - void* hImgPt; - hImgPt = himage.GetImagePointer1(&tmpType, &tmpW, &tmpH); - GenImage1(Hobj, "int2", wid, hgt, (Hlong)hImgPt); - - delete[] data; - data = NULL; - - } - -} - -//判断文件是å�¦å­˜åœ¨ï¼Œä¸�存在则创建 -bool isFileExist(QString fullFileName) -{ - QFileInfo fileInfo(fullFileName); - if (fileInfo.isFile()) - { - return true; - } - return false; -} - -void GetStringSize(HDC hdc, const char* str, int* w, int* h) -{ - SIZE size; - GetTextExtentPoint32A(hdc, str, strlen(str), &size); - if (w != 0) *w = size.cx; - if (h != 0) *h = size.cy; -} -//在图åƒ�写中文,英文也å�¯ä»¥å†™ -void putTextZH(cv::Mat& dst, const char* str, cv::Point org, cv::Scalar color, int fontsize, - const char* fn = "Arial", bool italic = false, bool underline = false) -{ - CV_Assert(dst.data != 0 && (dst.channels() == 1 || dst.channels() == 3)); - - - int x, y, r, b; - //å��标点大于图åƒ�宽和高直接返回 - if (org.x > dst.cols || org.y > dst.rows) return; - x = org.x < 0 ? -org.x : 0; - y = org.y < 0 ? -org.y : 0; - - - LOGFONTA lf; - lf.lfHeight = -fontsize; //字体高度 - lf.lfWidth = 0; //å¹³å�‡å®½åº¦ - lf.lfEscapement = 0; //字符排列角度 - lf.lfOrientation = 0; //字符本身旋转的角度 - lf.lfWeight = 5; //设置字体线æ�¡çš„宽度 - lf.lfItalic = italic; //斜体 - lf.lfUnderline = underline; //下划线 - lf.lfStrikeOut = 0; //是å�¦å­—符中央加横线 - lf.lfCharSet = DEFAULT_CHARSET; //字符集 - lf.lfOutPrecision = 0; //字体的精确度 - lf.lfQuality = PROOF_QUALITY; //字体质é‡� - lf.lfPitchAndFamily = 0; //选择字体的间è·�和字体家æ—� - strcpy_s(lf.lfFaceName, fn); //字体的å��ç§° - - - HFONT hf = CreateFontIndirectA(&lf); - HDC hdc = CreateCompatibleDC(0); - HFONT holdfont = (HFONT)SelectObject(hdc, hf); - - - int strBaseW = 0, strBaseH = 0; - int singleRow = 0; - char buf[1 << 12]; - strcpy_s(buf, str); - char* bufT[1 << 12]; //这个用于分隔字符串å�Žå‰©ä½™çš„字符,å�¯èƒ½ä¼šè¶…出。 - - - //处ç�†å¤šè¡Œ - { - int nnh = 0; - int cw, ch; - - - const char* ln = strtok_s(buf, "\n", bufT); - while (ln != 0) - { - GetStringSize(hdc, ln, &cw, &ch); - strBaseW = max(strBaseW, cw); - strBaseH = max(strBaseH, ch); - - - ln = strtok_s(0, "\n", bufT); - nnh++; - } - singleRow = strBaseH; - strBaseH *= nnh; - } - - - if (org.x + strBaseW < 0 || org.y + strBaseH < 0) - { - SelectObject(hdc, holdfont); - DeleteObject(hf); - DeleteObject(hdc); - return; - } - - - r = org.x + strBaseW > dst.cols ? dst.cols - org.x - 1 : strBaseW - 1; - b = org.y + strBaseH > dst.rows ? dst.rows - org.y - 1 : strBaseH - 1; - org.x = org.x < 0 ? 0 : org.x; - org.y = org.y < 0 ? 0 : org.y; - - - BITMAPINFO bmp = { 0 }; - BITMAPINFOHEADER& bih = bmp.bmiHeader; - int strDrawLineStep = strBaseW * 3 % 4 == 0 ? strBaseW * 3 : (strBaseW * 3 + 4 - ((strBaseW * 3) % 4)); - - - bih.biSize = sizeof(BITMAPINFOHEADER); - bih.biWidth = strBaseW; - bih.biHeight = strBaseH; - bih.biPlanes = 1; - bih.biBitCount = 24; - bih.biCompression = BI_RGB; - bih.biSizeImage = strBaseH * strDrawLineStep; - bih.biClrUsed = 0; - bih.biClrImportant = 0; - - - void* pDibData = 0; - HBITMAP hBmp = CreateDIBSection(hdc, &bmp, DIB_RGB_COLORS, &pDibData, 0, 0); - - - CV_Assert(pDibData != 0); - HBITMAP hOldBmp = (HBITMAP)SelectObject(hdc, hBmp); - - - //color.val[2], color.val[1], color.val[0] - SetTextColor(hdc, RGB(255, 255, 255)); - SetBkColor(hdc, 0); - //SetStretchBltMode(hDC, COLORONCOLOR); - - - strcpy_s(buf, str); - const char* ln = strtok_s(buf, "\n", bufT); - int outTextY = 0; - while (ln != 0) - { - TextOutA(hdc, 0, outTextY, ln, strlen(ln)); - outTextY += singleRow; - ln = strtok_s(0, "\n", bufT); - } - uchar* dstData = (uchar*)dst.data; - int dstStep = dst.step / sizeof(dstData[0]); - unsigned char* pImg = (unsigned char*)dst.data + org.x * dst.channels() + org.y * dstStep; - unsigned char* pStr = (unsigned char*)pDibData + x * 3; - for (int tty = y; tty <= b; ++tty) - { - unsigned char* subImg = pImg + (tty - y) * dstStep; - unsigned char* subStr = pStr + (strBaseH - tty - 1) * strDrawLineStep; - for (int ttx = x; ttx <= r; ++ttx) - { - for (int n = 0; n < dst.channels(); ++n) { - double vtxt = subStr[n] / 255.0; - int cvv = vtxt * color.val[n] + (1 - vtxt) * subImg[n]; - subImg[n] = cvv > 255 ? 255 : (cvv < 0 ? 0 : cvv); - } - - - subStr += 3; - subImg += dst.channels(); - } - } - - - SelectObject(hdc, hOldBmp); - SelectObject(hdc, holdfont); - DeleteObject(hf); - DeleteObject(hBmp); - DeleteDC(hdc); -} - -void drawDefects(cv::Mat& sourceMat, QQueue defectInfoList) -{ - for (int i = 0; i < defectInfoList.size(); i++) - { - defectInfo mdefect = defectInfoList[i]; - - cv::rectangle(sourceMat, cv::Point(mdefect.defectRect.x, mdefect.defectRect.y), - cv::Point(mdefect.defectRect.x + mdefect.defectRect.width, mdefect.defectRect.y + mdefect.defectRect.height), mdefect.defectScalar, 3, 8); - - QByteArray path_arr = mdefect.defectName.toLocal8Bit(); - const char* path = path_arr.data(); - putTextZH(sourceMat, path, cv::Point(mdefect.defectRect.x, mdefect.defectRect.y - 50), mdefect.defectScalar, 50, "微软雅黑"); - } -} - - - -//判断文件夹是å�¦å­˜åœ¨ï¼Œä¸�存在则创建 -void Hd_AI_algo_jixing1::isDirExist(QString fullDirName) -{ - QDir* photo = new QDir; - bool exist = photo->exists(fullDirName); - if (exist) - { - //qDebug() << fullDirName << "::已存在"; - } - else - { - //创建photo文件夹 - //qDebug() << fullDirName << "::ä¸�存在,创建"; - photo->mkdir(fullDirName); - } - delete photo; - photo = nullptr; -} - -Hd_AI_algo_jixing1* create() -{ - qDebug() << "[INFO] " << " Hd_AI_algo_jixing1 create success!"; - return new Hd_AI_algo_jixing1; -} - -void destory(Hd_AI_algo_jixing1* ptr) -{ - qDebug() << "[INFO] " << "Hd_AI_algo_jixing1 destory success!"; - if (ptr) - { - delete ptr; - ptr = nullptr; - } -} - -Hd_AI_algo_jixing1::Hd_AI_algo_jixing1() -{ - detect_mutex = new QMutex; - saveStruct_mutex = new QMutex; - ifdetectThread = false; - - for (int i = 0; i < 4; i++) - { - QString DirPath = "E:/testImg/source" + QString::number(i); - QStringList imgFilters; - imgFilters << "*.jpg" << "*.png" << "*.PNG" << "*.gif" << "*.tif" << "*.jpeg" << "*.bmp"; - QDir qdir(DirPath); - //返回文件å��列表 - QStringList localSourceImgsName = qdir.entryList(imgFilters, QDir::Files | QDir::Readable, QDir::Name); - for (int j = 0; j < localSourceImgsName.size(); j++) - { - QString imgPath = DirPath + "/" + localSourceImgsName[j]; - QFile myf(imgPath); - if (myf.exists()) - myf.remove(); - //Sleep(1); - } - } -} - -Hd_AI_algo_jixing1::~Hd_AI_algo_jixing1() -{ - ifdetectThread = false; - Sleep(10); - if (detect_mutex) - { - delete detect_mutex; - detect_mutex = nullptr; - } - if (saveStruct_mutex) - { - delete saveStruct_mutex; - saveStruct_mutex = nullptr; - } - /*DestroySegObj(pSeg); - DestroyClsObj(pCls);*/ -} -//从类中读数æ�®åˆ°å®žä¾‹å¯¹è±¡ -bool Hd_AI_algo_jixing1::readData(std::vector& vec_mat, QByteArray& data) -{ - detect_mutex->lock(); - //qDebug() << __FUNCTION__ << " line:" <<__LINE__ << " data len:" << data.length(); - if (resMat.size() > 0) - { - vec_mat.push_back(resMat[0]); - resMat.clear(); - } - else - { - if (HikMat.size() > 0) - vec_mat.push_back(HikMat[0]); - //qDebug() << __FUNCTION__ << " line:" << __LINE__ << " resMat.data err:"; - } - //if (allNum++ % 2 == 0) - // data = "2*3*2";// resByte.dequeue(); - //else - data = QByteArray::number(algoResult) + "&" + QByteArray::number(algoResult - 1) + "+" + QByteArray::number(algoResult);//1OK,2NG - resByte.clear(); - ////之å�Žæ ¹æ�®ç»“果类修改 - //if(resIfNg == true) - // data = "NG"; - //else data = "OK"; - detect_mutex->unlock(); - /*if(cameraKey_index.contains('_')) - qDebug() << "[INFO] " << __FUNCTION__ << " line:" << __LINE__ << " checkImg getDetectData--CameraName:" - << cameraKey_index.split("_")[0] << " imgIndex:" << cameraKey_index.split("_")[1]; - else - qDebug() << "[INFO] " << __FUNCTION__ << " line:" << __LINE__ << " checkImg getDetectData--CameraName imgIndex:" << cameraKey_index;*/ - return true; -} -//从类中读数æ�®åˆ°å®žä¾‹å¯¹è±¡ -bool Hd_AI_algo_jixing1::encodeResultValue(QVector append_value, QByteArray& resultByte) -{ - try - { - std::string sendMsg; - for (int i = 0; i < append_value.size(); i++) - { - std::string value = append_value.at(1); - //type - int type = 3; - std::string m_type; - m_type.insert(0, 4, '1'); - memcpy((void*)m_type.c_str(), (void*)&type, 4); - sendMsg.append(m_type); - - //len - int len = value.length(); - std::string m_len; - m_len.insert(0, 4, '1'); - memcpy((void*)m_len.c_str(), (void*)&len, 4); - sendMsg.append(m_len); - - //data x - sendMsg.append(value); - } - resultByte = QByteArray::fromStdString(sendMsg); - } - catch (QString ev) - { - qCritical() << "[Error] " << " ev:" << ev; - return false; - } - return true; -} - -int myallNum[4] = { 0 }; -QMap lastImgMap; -//接收数æ�® -bool Hd_AI_algo_jixing1::writeData(std::vector& vec_mat, QByteArray& data) -{ - //qDebug() << __FUNCTION__ << "line:"<< __LINE__ << " data len" << data.length() ; - if (vec_mat.empty()) - { - qCritical() << "[Error] " << " vec_mat is null !"; - return false; - } - detect_mutex->lock(); - HikMat.clear(); - for (int i = 0; i < vec_mat.size(); i++) - HikMat.enqueue(vec_mat[i]); - - QByteArray source_savePath; - QByteArray sData = data; - QByteArrayList splitDataList = sData.split(','); - if (splitDataList.size() >= 4) - { - if (splitDataList[2].contains('_')) - cameraKey_index = splitDataList[2]; - QByteArray saveDir = splitDataList[0] + "/" + splitDataList[1] + "/"; - isDirExist(byteArrayToUnicode(saveDir)); //ä¸�存在,创建 - QString sdataTime = QDateTime::currentDateTime().toString("yyyy-MM-dd-hh-mm-ss-zzz"); - source_savePath = splitDataList[0] + "/" + splitDataList[1] + "/" + sdataTime.toLocal8Bit() + "-" + splitDataList[2] + "-" + splitDataList[3];// +".bmp"; - } - //int index = -1; - /*if (sData.contains("offline-camera0")) - { - index = 0; - savePath = "E:\\testImg\\source0\\"+QString::number(myallNum[0]++) + ".bmp"; - } - else if (sData.contains("offline-camera1")) - { - index = 1; - savePath = "E:\\testImg\\source1\\" + QString::number(myallNum[1]++) + ".bmp"; - } - else if (sData.contains("offline-camera2")) - { - index = 2; - savePath = "E:\\testImg\\source2\\" + QString::number(myallNum[2]++) + ".bmp"; - } - else if (sData.contains("offline-camera3")) - { - index = 3; - savePath = "E:\\testImg\\source3\\" + QString::number(myallNum[3]++) + ".bmp"; - }*/ - - - - - createDirectoryIfNotExists(oriImgSaveDir + getCurrentDate() + "//" + getCurrentHour() + "//"); - addImgToSaveStruct(HikMat[0], "0", oriImgSaveDir + getCurrentDate() + "//" + getCurrentHour() + "//" - "ORI" + cameraKey_index + QString::fromStdString(getCurrentTime()) + ".bmp");//ä¿�存原图 - - //if (myallNum[index] == 1) - //{ - // cv::Mat img; - // lastImgMap.insert(index, img); - //} - //else - //{ - // //判断和上一张图,是å�¦é‡�å¤� - // int dataLength = HikMat[0].total() * HikMat[0].elemSize(); - // bool res = false; - // if (myallNum[index] > 0) - // { - // cv::Mat img = lastImgMap.value(index); - // if (img.total() * img.elemSize() == dataLength) - // { - // res = memcmp(img.data, HikMat[0].data, dataLength) == 0; - // if (res == true) - // std::cout << "res ==true ====!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl; - // } - // } - //} - //lastImgMap.insert(index, HikMat[0]); - - //or检测:ä¿�存路径,æ‹�ç…§é�¢æ��述,相机key_第几张图,SN_时间戳 - //and检测:ä¿�存路径,æ‹�ç…§é�¢æ��述,相机key_第几张图,相机key_第几张图,SN_时间戳,SN_时间戳 - //汇总:ä¿�存路径,æ‹�ç…§é�¢æ��述,触å�‘ä¿¡å�·_åº�å�·åˆ—表0,SN_时间戳 - QString qstring_data = data; - QStringList datalist = qstring_data.split(','); - - - /*saveKey.enqueue("datalist[0]"); - Dir2D.enqueue("datalist[1]"); - QStringList SN_dataTime; - SN_dataTime = datalist[3].split('_'); - DateTime1 = "SN_dataTime[1]"; - SN.enqueue("SN_dataTime[0]");*/ - //qCritical() << __FUNCTION__ << " line: " << __LINE__ << " data:" << qstring_data; - detect_mutex->unlock(); - - //qDebug() << __FUNCTION__ << "line:" << __LINE__ << "[INFO] " << " data: " << data << " run end"; - //cv::Mat resultDstImg = vec_mat[0].clone();// = pSeg->Evaluate(sourceImg); //返回å�•通é�“二值图 图片错误输出Image Error!但ä¸�报错。。 - //resultDstImg = pSeg->Evaluate(resultDstImg); - //resultDstImg.release(); - - return true; -} - -//ä¼ å…¥initParas函数,格å¼�为:相机key+å�‚æ•°å��1#å�‚数值1#å�‚数值2+å�‚æ•°å��2#å�‚数值1... -//åˆ�始化 -bool Hd_AI_algo_jixing1::initParas(QByteArray& byte) -{ - initValueList = byte.split('+'); - QStringList valueiList; - - if (byte.contains("onlySetParameter")) - { - qDebug() << __FUNCTION__ << " line:" << __LINE__ << "onlySetParameter,valueList[0]:" << initValueList[0]; - if (initValueList.size() > 1) - for (int i = 1; i < initValueList.size(); i++) - { - QString valuei = byteArrayToUnicode(initValueList[i]); - qDebug() << __FUNCTION__ << " line:" << __LINE__ << "onlySetParameter,lastName:" << initValueList[0] << " ,valuei:" << valuei; - } - return true; - } - - - if (initValueList.size() > 1) - for (int i = 1; i < initValueList.size(); i++) - { - QString valuei = byteArrayToUnicode(initValueList[i]); - valueiList.append(valuei); - } - - - /*pSeg = CreateSegObjS(pSeg_modulePath, 128, gpuId); - pCls = CreateClsObjV3(pCls_modulePath, gpuId, 1);*/ - - - //StationNo = vec_ret.at(0).toInt(); - - //InitThreads(StationNo, img2D); - //InitModels(StationNo, img2D); - - //è¿�行检测线程 - ifdetectThread = true; - - //线程检测:结果类完æˆ�时,使用 - //ifThreadRunDetect = true; - //QFuture future1 = QtConcurrent::run(this, &Hd_AI_algo_jixing1::detectThread); - //è¿�行存图线程 - QFuture future2 = QtConcurrent::run(this, &Hd_AI_algo_jixing1::saveImgThread); - //detectThread(); - - //原图总文件夹 - isDirExist(oriImgSaveDir); - //原图class总文件夹 - isDirExist(classImgSaveDir); - //结果图总文件夹 - isDirExist(resImgSaveDir); - - - //qDebug() << "[INFO] " << " StationNo:" << StationNo << " img2D:" << img2D ; - return true; -} -// è§£ç � -bool Hd_AI_algo_jixing1::decodeAiValue(QByteArray byte, QVector& vec_ret) -{ - if (byte.isEmpty()) - { - qCritical() << "[Error] " << " byte is null!"; - return false; - } - - /*******************************************/ - byte.remove(0, 8); - QByteArray mm_data = byte.mid(0, 4); - memcpy((void*)¶mNum, (void*)mm_data.data(), 4); - qDebug() << "[INFO] " << " paramNum:" << paramNum; - byte.remove(0, 4); - /*******************************************/ - - while (!byte.isEmpty()) - { - int type = 0; - QByteArray m_type = byte.mid(0, 4); - memcpy((void*)&type, (void*)m_type.data(), 4); - byte.remove(0, 4); - - int len = 0; - QByteArray m_len = byte.mid(0, 4); - memcpy((void*)&len, (void*)m_len.data(), 4); - byte.remove(0, 4); - - QByteArray mm_data = byte.mid(0, len); - vec_ret.append(mm_data); - byte.remove(0, len); - } - return true; -} - -//---------检测æµ�程,根æ�®å®žé™…项目修改--------- -bool Hd_AI_algo_jixing1::AIdetect(cv::Mat img2D, QString mysaveKey, QString myDir2D, QString mySN, QString myDataTime) -{ - try - { - //存图数æ�®åŠ ä¿�存队列,加é”�,é�¿å…�æ•°æ�®è®¿é—®å†²çª� - saveStruct_mutex->lock(); - saveImgStruct mySave; - Mat sourceImg; - sourceImg = img2D.clone(); - //img2D.copyTo(sourceImg); - //img2D.release(); - QString mysaveKey1 = mysaveKey; //"offlineStation1_off_1" - saveStruct_mutex->unlock(); - - QJsonDocument document; - QJsonObject obj; - obj.insert("result_key", "mysaveKey"); - obj.insert("SN", "mySN"); - obj.insert("DataTime", "myDataTime"); - - - //QFile csvName("test.csv"); - //QStringList lines; - //lines << "class,name\n" << "3,4,5,6,7\n" << "a,b,c,d\n"; - //if (csvName.open(QIODevice::WriteOnly)) //若文件ä¸�存在,会自动创建 - //{ - // for (int i = 0; i < lines.size(); i++) - // csvName.write(lines[i].toStdString().c_str()); - // csvName.close(); - //} - - QQueue defectInfoList; - - //æž�性检测 - HObject ho_Image; - HTuple hv_out_Value; - HTuple hv_Make; - //cv::imwrite("C://1.bmp", sourceImg); - MatToHObject(sourceImg, &ho_Image); - _628_1_Polarity_detection(ho_Image, &hv_out_Value, &hv_Make); - //相机2 OK为铜 NG为é“� - if (hv_Make.D() != -1) - { - if (hv_out_Value.D() == 1)//é“� - { - putTextHusky(sourceImg, utf8_to_gbk("é“�æž�").c_str(), cv::Point(0, 0), cv::Scalar(0, 255, 0), 300); - //cv::putText(sourceImg, "Aluminium", cv::Point(0, 240), 2, 10, cv::Scalar(0, 255, 0), 10); - cv::putText(sourceImg, "NG", cv::Point(0, 550), 2, 10, cv::Scalar(0, 0, 255), 10); - algoResult = 1; - //Result = 1 ? 2; - //Result = 1; - } - else if (hv_out_Value.D() == 2)//铜 - { - putTextHusky(sourceImg, utf8_to_gbk("铜æž�").c_str(), cv::Point(0, 0), cv::Scalar(0, 255, 0), 300); - //cv::putText(sourceImg, "Copper", cv::Point(0, 240), 2, 10, cv::Scalar(0, 255, 0), 10); - cv::putText(sourceImg, "OK", cv::Point(0, 550), 2, 10, cv::Scalar(0, 255, 0), 10); - algoResult = 1; - } - else - { - putTextHusky(sourceImg, utf8_to_gbk("算法异常1").c_str(), cv::Point(0, 0), cv::Scalar(0, 255, 0), 300); - // cv::putText(sourceImg, "Algo error1", cv::Point(0, 240), 2, 10, cv::Scalar(0, 0, 255), 10); - //Result = 2; - } - } - else - { - putTextHusky(sourceImg, utf8_to_gbk("算法异常1").c_str(), cv::Point(0, 0), cv::Scalar(0, 255, 0), 300); - // cv::putText(sourceImg, "Algo error2", cv::Point(0, 240), 2, 10, cv::Scalar(0, 0, 255), 10); - } - - ho_Image.Clear(); - hv_out_Value.Clear(); - hv_Make.Clear(); - - detect_mutex->lock(); - //resMat = sourceImg.clone(); - //sourceImg.copyTo(resMat); - resMat.push_back(sourceImg); - //结果图画框和缺陷,在resMat上绘制 - if (resMat.size() > 0) - drawDefects(resMat[0], defectInfoList); - - //QByteArray,根æ�®å®žé™…项目进行解æž� - //å�‚æ•°,例:返回结果图;相机关键字(SN或userID)+ä¿�存路径+缺陷信æ�¯åˆ—表(缺陷å��称,缺陷ä½�ç½®int(x,y,w,h),画框颜色Scalar(a,b,c),缺陷é�¢ç§¯double) - - QJsonArray detaillists; - //QByteArrayList resQbyte; - for (int i = 0; i < defectInfoList.size(); i++) - { - defectInfo mdefect = defectInfoList[i]; - //resQbyte.push_back(mdefect.defectName.toLocal8Bit()); //中文也å�¯ä»¥QString::number(1.1).toUtf8() - //resQbyte.push_back(QString::number(mdefect.defectRect.x).toUtf8()); - //resQbyte.push_back(QString::number(mdefect.defectRect.y).toUtf8()); - //resQbyte.push_back(QString::number(mdefect.defectRect.width).toUtf8()); - //resQbyte.push_back(QString::number(mdefect.defectRect.height).toUtf8()); - //resQbyte.push_back(QString::number(mdefect.defectScalar[0]).toUtf8()); - //resQbyte.push_back(QString::number(mdefect.defectScalar[1]).toUtf8()); - //resQbyte.push_back(QString::number(mdefect.defectScalar[2]).toUtf8()); - //resQbyte.push_back(QString::number(mdefect.defectArea).toUtf8()); - QJsonObject detailObj; - detailObj.insert("defectName", "mdefect.defectName"); - detailObj.insert("defectRect.x", QString::number(mdefect.defectRect.x)); - detailObj.insert("defectRect.y", QString::number(mdefect.defectRect.y)); - detailObj.insert("defectRect.width", QString::number(mdefect.defectRect.width)); - detailObj.insert("defectRect.height", QString::number(mdefect.defectRect.height)); - detailObj.insert("defectScalar0", QString::number(mdefect.defectScalar[0])); - detailObj.insert("defectScalar1", QString::number(mdefect.defectScalar[1])); - detailObj.insert("defectScalar2", QString::number(mdefect.defectScalar[2])); - detailObj.insert("defectArea", QString::number(mdefect.defectArea)); - detailObj.insert("defectLength", QString::number(sqrt(mdefect.defectRect.width * mdefect.defectRect.width + mdefect.defectRect.height * mdefect.defectRect.height))); - - detaillists.append(detailObj); - } - - - //使用完删除 - defectInfoList.clear(); - - //往主界é�¢å�‘ - //emit sendResultData(resMat, resQbyte); - //resQbyte.clear(); - - isDirExist(resImgSaveDir + mysaveKey1 + "/"); - QString qimgsavePath = resImgSaveDir + mysaveKey1 + "/" + mySN + myDataTime + ".png"; - //存图数æ�®å…¥é˜Ÿ,按需 - QString sdataTime = QDateTime::currentDateTime().toString("yyyy-MM-dd-hh-mm-ss-zzz"); - if (resMat.size() > 0) - { - createDirectoryIfNotExists(oriImgSaveDir + getCurrentDate() + "//" + getCurrentHour() + "//"); - addImgToSaveStruct(HikMat[0], "0", resImgSaveDir + getCurrentDate() + "//" + getCurrentHour() + "//" - + "RES" + cameraKey_index + QString::fromStdString(getCurrentTime()) + ".png");//ä¿�存原图 - } - detect_mutex->unlock(); - - obj.insert("detaillists", detaillists); - obj.insert("qimgsavePath", qimgsavePath); - document.setObject(obj); - //resByte.clear(); - QByteArray qa = document.toJson(); - //resByte .enqueue(qa); - - - //resMat.release(); - sourceImg.release(); - - mySave.out_Mat.resize(0); - mysaveKey1.clear(); - qApp->processEvents(); - - - ////原图和结果都往主界é�¢å�‘? - //std::vector resMat; - //resMat.push_back(img2D); - //resMat.push_back(sourceRectangles); - //QByteArray resByte = mysaveKey.toLocal8Bit(); - //resByte.append(myDir2D.toLocal8Bit()); - //resByte.append(mySN.toLocal8Bit()); - //resByte.append(myDataTime.toLocal8Bit()); - - ////往主界é�¢å�‘é€�图片和数æ�® - ////emit writeData(resMat, resByte); - //resMat.resize(0); - //resByte.resize(0); - } - catch (...) - { - qDebug() << "[Error] " << QString::fromUtf8("检测失败!"); - return false; - } - return true; - -} - -//存图加入队列 -void Hd_AI_algo_jixing1::addImgToSaveStruct(cv::Mat img2D, QString mysaveKey, QString savePath) -{ - //存图数æ�®åŠ ä¿�存队列,加é”�,é�¿å…�æ•°æ�®è®¿é—®å†²çª� - saveStruct_mutex->lock(); - saveImgStruct mySave; - mySave.out_Mat = img2D.clone(); - //img2D.copyTo(mySave.out_Mat); - mySave.saveKey = mysaveKey.toLocal8Bit().toStdString(); - mySave.savePath = savePath.toLocal8Bit().toStdString(); - saveStruct.enqueue(mySave); - saveStruct_mutex->unlock(); -} -void Hd_AI_algo_jixing1::saveImgThread() -{ - while (1) - { - if (!ifdetectThread)return; - _sleep(5); - qApp->processEvents(); - if (saveStruct.size() < 1)continue; - for (int i = 0; i < saveStruct.size(); i++) - { - clock_t start, stop; - start = clock(); - saveStruct_mutex->lock(); - saveImgStruct mysaveStruct = saveStruct.dequeue(); - saveStruct_mutex->unlock(); - stop = clock(); - if (stop - start > 1000) - std::cout << "lock stop-start >1000::************************" << stop - start << std::endl; - start = clock(); - if (mysaveStruct.out_Mat.data) - imwrite(mysaveStruct.savePath, mysaveStruct.out_Mat); - //std::cout << "savePath::" << mysaveStruct.savePath << std::endl; - stop = clock(); - if (stop - start > 1000) - std::cout << "imwrite stop-start >1000::--------------------------" << stop - start << std::endl; - _sleep(1); - } - } -} -//检测线程,应当å�ªè¿�行一次 -void Hd_AI_algo_jixing1::detectThread() -{ - do - { - if (!ifdetectThread)return; - - //此两行代ç �,é�¿å…�程åº�å�¡æ­»ï¼›_sleep的时间根æ�®å®žé™…项目调整 - _sleep(2); - qApp->processEvents(); - //å�–æ•°æ�®åŠ é”�,é�¿å…�æ•°æ�®è®¿é—®å†²çª� - detect_mutex->lock(); - //if (HikMat.size() < 1 || saveKey.size() < 1 || Dir2D.size() < 1 || SN.size() < 1 )//|| DateTime1.size() < 1) - //{ - // detect_mutex->unlock(); - // continue; - //} - - cv::Mat sourceImg1 = HikMat[0];// .dequeue(); - QString mysaveKey = "saveKey";// .dequeue(); - QString myDir2D = "Dir2D";// .dequeue(); - QString mySN = "SN";// .dequeue(); - QString myDataTime = "DateTime1"; - detect_mutex->unlock(); - - //判断存图文件夹是å�¦å­˜åœ¨,ä¸�存在则创建 - { - //原图总文件夹 - isDirExist(oriImgSaveDir + mysaveKey); - //原图class总文件夹 - isDirExist(classImgSaveDir + mysaveKey); - //结果图总文件夹 - isDirExist(resImgSaveDir + mysaveKey); - - } - - //测试相机的, - //while (sourceImg1.cols > 2000)cv::resize(sourceImg1, sourceImg1, cv::Size(), 0.5, 0.5); - - //存图数æ�®å…¥é˜Ÿ - //addImgToSaveStruct(sourceImg1, mysaveKey, oriImgSaveDir + mysaveKey + "/" + mySN + myDataTime + ".bmp"); - - //-------检测æµ�程,根æ�®å®žé™…项目修改--------- - AIdetect(sourceImg1, mysaveKey, oriImgSaveDir, mySN, myDataTime); - //sourceImg1.release(); - - mysaveKey.clear(); - myDir2D.clear(); - mySN.clear(); - myDataTime.clear(); - qApp->processEvents(); - - } while (ifThreadRunDetect); - -} - -static int runNum = 0; -bool Hd_AI_algo_jixing1::run() -{ - clock_t start, stop; - start = clock(); - - //Sleep(1000); - detectThread(); - stop = clock(); - qDebug() << __FUNCTION__ << "line:" << __LINE__ << " run start ::runNum::" << runNum++ << " cutTime::" << stop - start; - - - //qDebug() << __FUNCTION__ << "line:" << __LINE__ << "[INFO] " << "Mat_name: " << Mat_name << " run end"; - return true; -} - -bool Hd_AI_algo_jixing1::checkStatus() -{ - status = moduleStatus; - return status; -} - diff --git a/BaseModules/Hd_AI_algo_jixing_cam3/Hd_AI_algo_jixing1.h b/BaseModules/Hd_AI_algo_jixing_cam3/Hd_AI_algo_jixing1.h deleted file mode 100644 index 889dc14..0000000 --- a/BaseModules/Hd_AI_algo_jixing_cam3/Hd_AI_algo_jixing1.h +++ /dev/null @@ -1,119 +0,0 @@ -#ifndef Hd_AI_algo_jixing1_H -#define Hd_AI_algo_jixing1_H - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include "imgproc/imgproc_c.h" - -#include "base.h" - -#pragma execution_character_set("utf-8") - - - -//ä¿�存图片的结构体 -struct saveImgStruct; -//{ -// cv::Mat out_Mat; -// std::string saveKey; //关键字,用于LOG日志 -// std::string savePath; //ä¿�存路径 -//}; - -//åˆ�始化æµ�程(一次):Hd_AI_algo_jixing1,initParas -//è¿�行æµ�程:writeData主线程把数æ�®ä¼ è¿‡æ�¥ï¼Œrun,readData此线程把数æ�®ä¼ ä¸»çº¿ç¨‹ -class Hd_AI_algo_jixing1 :public Base -{ - Q_OBJECT -public: - Hd_AI_algo_jixing1(); - virtual ~Hd_AI_algo_jixing1(); - //从类中读数æ�®åˆ°å®žä¾‹å¯¹è±¡ - bool readData(std::vector&,QByteArray&); - //实例对象把数æ�®å†™å…¥åˆ°ç±» - bool writeData(std::vector&, QByteArray&); - bool initParas(QByteArray&); - //è¿�行(Logic_taskthread.cpp) - bool run(); - //线程状æ€� - bool checkStatus();// { return true; }; - - bool encodeResultValue(QVector append_value,QByteArray &resultByte); - bool decodeAiValue(QByteArray byte,QVector &vec_ret); - //---------检测æµ�程,根æ�®å®žé™…项目修改--------- - bool AIdetect(cv::Mat img2D, QString saveKey, QString Dir2D, QString SN, QString DataTime); - - - -private: - - int allNum = 0; - int StationNo=0; - int img2D = 2; - - bool moduleStatus = true; - - //输入图片队列 - QQueue HikMat; - //输入关键字队列 - QString saveKey="saveKey"; - //结果路径文件夹队列 - QString Dir2D="Dir2D"; - //产å“�SN队列 - QString SN="SN"; - //产å“�时间戳队列 - QString DateTime1="DateTime1"; - - int paramNum; - - //是å�¦ä½¿ç”¨çº¿ç¨‹æ£€æµ‹æ–¹å¼� - bool ifThreadRunDetect = false; - //检测结果图 - std::vector resMat; - //检测结果 - bool resIfNg = false; - - QQueue resByte; - - //检测线程 - void detectThread(); - //存图线程 - void saveImgThread(); - - //ä¿�存图片队列 - QQueue saveStruct; - - //判断文件夹是å�¦å­˜åœ¨ï¼Œä¸�存在则创建 - void isDirExist(QString fullDirName); - - //存图加入队列 - void addImgToSaveStruct(cv::Mat img2D, QString saveKey, QString savePath); -}; - -extern "C" -{ - Q_DECL_EXPORT Hd_AI_algo_jixing1 * create(); - Q_DECL_EXPORT void destory(Hd_AI_algo_jixing1 * ptr); -} -//ä¿�存图片的结构体 -struct saveImgStruct -{ - cv::Mat out_Mat; - std::string saveKey; //关键字,用于LOG日志 - std::string savePath; //ä¿�存路径 -}; -#endif // Hd_AI_927_2D_module_H diff --git a/BaseModules/Hd_AI_algo_jixing_cam4/base.h b/BaseModules/Hd_AI_algo_jixing_cam4/base.h deleted file mode 100644 index 00bd6b2..0000000 --- a/BaseModules/Hd_AI_algo_jixing_cam4/base.h +++ /dev/null @@ -1,69 +0,0 @@ -#ifndef __BASECLASS_H__ -#define __BASECLASS_H__ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -class Base :public QObject -{ - Q_OBJECT -public: - bool init_flag; //是å�¦åˆ�始化,false,true - bool status = true; //相机状æ€�(判断相机是å�¦æ–­å¼€è¿žæŽ¥ï¼‰ - std::string paras; //传输数æ�® - std::vector m_mat; //传输图片 - std::string moduleName; //模å�—å��ç§° -public: - Base(){} - virtual ~Base(){} - virtual bool readData(std::vector&,QByteArray&){return true;} - virtual bool writeData(std::vector&,QByteArray&){return true;} - virtual bool initParas(QByteArray&){return true;} - virtual bool run() {return true;} - virtual bool checkStatus() { return true; } - -//signals: - //QByteArrayList,根æ�®å®žé™…项目进行解æž�;因ä¸�确定æ¯�个å�‚数的长度,固用队列的方å¼�。æ¯�个QByteArray表示一个值,使用时先转æ�¢ä¸ºQString - //å�‚æ•°,例:返回结果图;相机关键字(SN或userID)+ä¿�存路径+缺陷信æ�¯åˆ—表(缺陷å��称,缺陷ä½�ç½®int(x,y,w,h),画框颜色Scalar(a,b,c),缺陷é�¢ç§¯double) - //void sendResultData(cv::Mat resMat, QJsonObject resQbj); -}; - -/* -//QJsonObject 转QByteArray -{ - QJsonDocument document; - QJsonObject obj; - obj.insert(password, "pwd"); - obj.insert(userName, "usr"); - document.setObject(obj); - QByteArray abyte = document.toJson(QJsonDocument::Compact); -} - -//QByteArray转QJsonObject -{ - QByteArray ba = reply->readAll(); - QJsonDocument doc = QJsonDocument::fromJson(ba); - QJsonObject obj = doc.object(); -} -*/ -/* -//从类中读数æ�®åˆ°å®žä¾‹å¯¹è±¡ -virtual bool readData(std::vector&,QByteArray&){return true;} - - - - - - - - -*/ - -#endif diff --git a/BaseModules/Hd_AI_algo_jixing_cam1/CMakeLists.txt b/BaseModules/Hd_CameraModule_HIK_soft_TakeTwo/CMakeLists.txt similarity index 96% rename from BaseModules/Hd_AI_algo_jixing_cam1/CMakeLists.txt rename to BaseModules/Hd_CameraModule_HIK_soft_TakeTwo/CMakeLists.txt index 3f7d257..3f4ea58 100644 --- a/BaseModules/Hd_AI_algo_jixing_cam1/CMakeLists.txt +++ b/BaseModules/Hd_CameraModule_HIK_soft_TakeTwo/CMakeLists.txt @@ -3,7 +3,7 @@ get_filename_component(CURRENT_FOLDER ${CMAKE_CURRENT_SOURCE_DIR} NAME) string(TIMESTAMP RUN_TIME) message( " model start : " ${CURRENT_FOLDER}:${RUN_TIME}) -set(DLL_NAMES "opencv" "halcon" "Myalgo""myTools" ) +set(DLL_NAMES "mvs" "opencv") foreach(child ${DLL_NAMES}) LIST(APPEND ENV_INCLUDE ${${child}_include}) LIST(APPEND ENV_LIB ${${child}_lib}) diff --git a/BaseModules/Hd_CameraModule_HIK_soft_TakeTwo/Hd_CameraModule_HIK_soft.cpp b/BaseModules/Hd_CameraModule_HIK_soft_TakeTwo/Hd_CameraModule_HIK_soft.cpp new file mode 100644 index 0000000..423d8d9 --- /dev/null +++ b/BaseModules/Hd_CameraModule_HIK_soft_TakeTwo/Hd_CameraModule_HIK_soft.cpp @@ -0,0 +1,722 @@ +#include "Hd_CameraModule_HIK_soft.h" +using namespace std; +int firstExposureTime = 3000; +int secondExposureTime = 3000; +std::mutex triggerLock; +#include +#include +#include +#include +QByteArray mv_Status = "connected";//0106 新增相机断è�”报警 +//cv::Mat srcImage; +int index = -1; //相机åº�å�· +void* handle; //相机指针 +string Username = ""; +bool m_flag = false; +MV_CC_DEVICE_INFO_LIST m_stDevList;//相机设备 +bool moduleStatus = true; +QQueue queuepic; +cv::Mat matList[1000] = { cv::Mat() }; +//data == "rest_newProductIn"æ—¶è¦�结æ�Ÿrun;机å�°æŠ¥è­¦ï¼Œå�–图超时,å¤�ä½�å�Žé‡�æ–°æ‹�的情况。 +bool ifBreak = false; +//ifRunningå‡�å°‘ifBreak的判断;"rest_newProductIn"时,Logic_camera_thread框架会结æ�Ÿæœªå¤„ç�†å®Œçš„相相机å�–图 +bool ifRunning = false; +bool ifChangeExpourseAndGain = true; +MV_CAM_TRIGGER_SOURCE initTriggerSource = MV_TRIGGER_SOURCE_SOFTWARE; +MV_CAM_TRIGGER_SOURCE currentTriggerSource = MV_TRIGGER_SOURCE_SOFTWARE; + + +QString byteArrayToUnicode(const QByteArray array) { + + // state用于ä¿�存转æ�¢çжæ€�,它的æˆ�员invalidChars,å�¯ç”¨æ�¥åˆ¤æ–­æ˜¯å�¦è½¬æ�¢æˆ�功 + // 如果转æ�¢æˆ�功,则值为0,如果值大于0,则说明转æ�¢å¤±è´¥ + QTextCodec::ConverterState state; + // å…ˆå°�试使用utf-8的方å¼�把QByteArray转æ�¢æˆ�QString + QString text = QTextCodec::codecForName("UTF-8")->toUnicode(array.constData(), array.size(), &state); + // 如果转æ�¢æ—¶æ— æ•ˆå­—符数é‡�大于0,说明编ç �æ ¼å¼�ä¸�对 + if (state.invalidChars > 0) + { + // å†�å°�试使用GBK的方å¼�进行转æ�¢ï¼Œä¸€èˆ¬å°±èƒ½è½¬æ�¢æ­£ç¡®(当然也å�¯èƒ½æ˜¯å…¶å®ƒæ ¼å¼�,但比较少è§�了) + text = QTextCodec::codecForName("GBK")->toUnicode(array); + } + return text; +} + +#pragma execution_character_set("utf-8") + +QMutex* n_mutex;// = new QMutex(); +//是å�¦ä¸ºæ ‡å‡†é€šä¿¡æµ�程: +//标准通信æµ�程,run函数设置æ›�å…‰/增益;é�žæ ‡å‡†é€šä¿¡æµ�程(简å�•通信æµ�程),回调函数设置æ›�å…‰/增益 +bool ifStandard = false; +//相机å�–图超时时间 +int getImageTimeOut = 1000; +//总å�–图数 +int imgIndex = 0; +//æ›�光值列表 +QQueue expourseTimeList; +//增益列表 +QQueue gainList; + +//0106 断线é‡�连 +void __stdcall ReconnectDevice(unsigned int nMsgType, void* pUser); +void __stdcall ImageCallBackEx(unsigned char* pData0, MV_FRAME_OUT_INFO_EX* pFrameInfo0, void* pUser0); + + +bool IsColor(MvGvspPixelType enType) +{ + switch (enType) + { + case PixelType_Gvsp_RGB8_Packed: + case PixelType_Gvsp_YUV422_Packed: + case PixelType_Gvsp_YUV422_YUYV_Packed: + case PixelType_Gvsp_BayerGR8: + case PixelType_Gvsp_BayerRG8: + case PixelType_Gvsp_BayerGB8: + case PixelType_Gvsp_BayerBG8: + case PixelType_Gvsp_BayerGB10: + case PixelType_Gvsp_BayerGB10_Packed: + case PixelType_Gvsp_BayerBG10: + case PixelType_Gvsp_BayerBG10_Packed: + case PixelType_Gvsp_BayerRG10: + case PixelType_Gvsp_BayerRG10_Packed: + case PixelType_Gvsp_BayerGR10: + case PixelType_Gvsp_BayerGR10_Packed: + case PixelType_Gvsp_BayerGB12: + case PixelType_Gvsp_BayerGB12_Packed: + case PixelType_Gvsp_BayerBG12: + case PixelType_Gvsp_BayerBG12_Packed: + case PixelType_Gvsp_BayerRG12: + case PixelType_Gvsp_BayerRG12_Packed: + case PixelType_Gvsp_BayerGR12: + case PixelType_Gvsp_BayerGR12_Packed: + return true; + default: + return false; + } +} + +//æ�œç´¢æ‰€æœ‰è®¾å¤‡ +int SearchDevice() +{ + memset(&m_stDevList, 0, sizeof(MV_CC_DEVICE_INFO_LIST)); + // ch:枚举å­�网内所有设备 | en:Enumerate all devices within subnet + int nRet = MV_CC_EnumDevices(MV_GIGE_DEVICE || MV_USB_DEVICE, &m_stDevList); + for (int i = 0; i < m_stDevList.nDeviceNum; i++) + { + //SN + unsigned char* name = m_stDevList.pDeviceInfo[i]->SpecialInfo.stGigEInfo.chSerialNumber; + //userID + //unsigned char* name=m_stDevList.pDeviceInfo[i]->SpecialInfo.stGigEInfo.chUserDefinedName; + string userName = static_cast((LPCSTR)name); + if (Username == userName) + { + index = i; + break; + } + } + if (MV_OK != nRet) + { + return 0; + } + return -1; +} + +bool connctDevice() +{ + index = -1; + SearchDevice(); + if (index == -1) + { + //未匹é…�到相机 + qDebug() << "[Waring] " << "Hd_CameraModule_HIK_soft not match --CameraName:" << QString::fromStdString(Username); + return false; + } + unsigned char* name = m_stDevList.pDeviceInfo[index]->SpecialInfo.stGigEInfo.chUserDefinedName; + string userName = static_cast((LPCSTR)name); + qDebug() << "[INFO] " << " start" << "--UserName:" << QString::fromStdString(userName); + if (handle != NULL) + { + MV_CC_StopGrabbing(handle); + MV_CC_CloseDevice(handle); + MV_CC_DestroyHandle(handle); + } + + //打开相机 + MV_CC_CreateHandle(&handle, m_stDevList.pDeviceInfo[index]); + int nRet = MV_CC_OpenDevice(handle); + ////触å�‘模å¼� + MV_CC_SetEnumValue(handle, "TriggerSource", MV_TRIGGER_SOURCE_SOFTWARE); + MV_CC_SetEnumValue(handle, "TriggerMode", MV_TRIGGER_MODE_ON); + // //加载用户集,相机设置应当UserSet1 + nRet = MV_CC_SetEnumValueByString(handle, "UserSetSelector", "UserSet1"); + if (MV_OK != nRet) + { + qDebug() << "Set UserSetSelector fail! nRet " << nRet; + } + // ch:注册抓图回调 | en:Register image callback + MV_CC_SetIntValueEx(handle, "GevHeartbeatTimeout", 3000);//心跳日志 + + nRet = MV_CC_RegisterImageCallBackEx(handle, ImageCallBackEx, handle);//注册回调 + if (MV_OK != nRet) + return false; + nRet = MV_CC_RegisterExceptionCallBack(handle, ReconnectDevice, NULL);//断线é‡�连 + if (MV_OK != nRet) + return false; + MV_CC_StartGrabbing(handle); + return true; +} + +//0106 断线é‡�连 +void __stdcall ReconnectDevice(unsigned int nMsgType, void* pUser) +{ + mv_Status = "disconnect"; + qDebug() << "[Error] " << " MV camera disconnects!"; + moduleStatus = false; + if (nMsgType == MV_EXCEPTION_DEV_DISCONNECT) + { + //断开连接 + MV_CC_CloseDevice(handle); + int nRet = MV_CC_DestroyHandle(handle); + handle = nullptr; + BOOL bConnected = FALSE; + while (1) + { + Sleep(100); + if (connctDevice() == true) + { + qWarning() << "[Hd_CameraModule_HIK_soft] " << " Hd_CameraModule_HIK_soft create success again! "; + moduleStatus = true; + break; + } + + } + } +} +void _stdcall ExceptionCB(unsigned int nMesgType, void* pUser) { + mv_Status = "disconnect"; + qDebug() << "[Error] " << " MV camera disconnects!"; + moduleStatus = false; +} + +int RGB2BGR(unsigned char* pRgbData, unsigned int nWidth, unsigned int nHeight) +{ + + if (NULL == pRgbData) + { + return MV_E_PARAMETER; + } + + for (unsigned int j = 0; j < nHeight; j++) + { + for (unsigned int i = 0; i < nWidth; i++) + { + unsigned char red = pRgbData[j * (nWidth * 3) + i * 3]; + pRgbData[j * (nWidth * 3) + i * 3] = pRgbData[j * (nWidth * 3) + i * 3 + 2]; + pRgbData[j * (nWidth * 3) + i * 3 + 2] = red; + } + } + + return MV_OK; + +} + +Hd_CameraModule_HIK_soft* create() +{ + qDebug() << "[INFO] " << "Hd_CameraModule_HIK_soft create success!" ; + return new Hd_CameraModule_HIK_soft; +} + +void destory(Hd_CameraModule_HIK_soft * ptr) +{ + if(ptr) + { + delete ptr; + ptr = nullptr; + } + qDebug() << "[INFO] " << "Hd_CameraModule_HIK_soft destory success!"; +} +//回调函数; +//ç»�测试,相机åƒ�ç´ æ ¼å¼�Mono8ã€�RGB8是å�¯ä»¥æ­£å¸¸è½¬æ�¢çš„,YUV422还需è¦�优化;RGB8æ ¼å¼�比YUV422帧率低;BGRæ ¼å¼�会导致异色问题 +void __stdcall ImageCallBackEx(unsigned char* pData0, MV_FRAME_OUT_INFO_EX* pFrameInfo0, void* pUser0) +{ + SetExposureTime(secondExposureTime); + triggerLock.unlock(); + n_mutex->lock(); + double time_Start = (double)clock(); + int frameNum = 0; + cv::Mat srcImage = cv::Mat(); + if (pFrameInfo0) + { + //获å�–的是å�•通é�“ç�°åº¦å›¾ + if (pFrameInfo0->enPixelType == PixelType_Gvsp_Mono8)//获å�–当å‰�采集到的图åƒ�æ ¼å¼� + { + srcImage = cv::Mat(pFrameInfo0->nHeight, pFrameInfo0->nWidth, CV_8UC1, pData0); + } + //获å�–的是RGB8图 + else if (pFrameInfo0->enPixelType == PixelType_Gvsp_BGR8_Packed) + { + srcImage = cv::Mat(pFrameInfo0->nHeight, pFrameInfo0->nWidth, CV_8UC3, pData0); + } + + ////获å�–的是RGB8图 + //else if (pFrameInfo0->enPixelType == PixelType_Gvsp_RGB8_Packed) + //{ + // cv::Mat dst = cv::Mat(pFrameInfo0->nHeight, pFrameInfo0->nWidth, CV_8UC3, pData0); + // //cv::cvtColor(matimage, matimage, cv::COLOR_RGB2BGR); + // srcImage = cv::Mat::zeros(pFrameInfo0->nHeight, pFrameInfo0->nWidth, CV_8UC3); + // std::vector channels; + // cv::split(dst, channels);//分割matimage的通é�“ + // std::vector dstchannels; + // for (int i = 2; i >= 0; i--) + // { + // dstchannels.push_back(channels[i]); + // } + // merge(dstchannels, srcImage); + //} + + else if (IsColor(pFrameInfo0->enPixelType)) //其它格å¼�彩色图 + { + MvGvspPixelType enDstPixelType = PixelType_Gvsp_Undefined; + enDstPixelType = PixelType_Gvsp_BGR8_Packed; + unsigned char* pConvertData = NULL; + pConvertData = (unsigned char*)malloc(pFrameInfo0->nWidth * pFrameInfo0->nHeight * 3); + if (NULL == pConvertData) + { + printf("malloc pConvertData fail!\n"); + } + else + { + unsigned int nConvertDataSize = 0; + nConvertDataSize = pFrameInfo0->nWidth * pFrameInfo0->nHeight * 3; + + // ch:åƒ�ç´ æ ¼å¼�转æ�¢ | en:Convert pixel format + MV_CC_PIXEL_CONVERT_PARAM stConvertParam = { 0 }; + + frameNum = pFrameInfo0->nFrameNum; //ch:帧å�· | en:frame number + stConvertParam.nWidth = pFrameInfo0->nWidth; //ch:图åƒ�宽 | en:image width + stConvertParam.nHeight = pFrameInfo0->nHeight; //ch:图åƒ�高 | en:image height + stConvertParam.pSrcData = pData0; //ch:输入数æ�®ç¼“å­˜ | en:input data buffer + stConvertParam.nSrcDataLen = pFrameInfo0->nFrameLen; //ch:输入数æ�®å¤§å°� | en:input data size + stConvertParam.enSrcPixelType = pFrameInfo0->enPixelType; //ch:输入åƒ�ç´ æ ¼å¼� | en:input pixel format + stConvertParam.enDstPixelType = enDstPixelType; //ch:输出åƒ�ç´ æ ¼å¼� | en:output pixel format + stConvertParam.pDstBuffer = pConvertData; //ch:输出数æ�®ç¼“å­˜ | en:output data buffer + stConvertParam.nDstBufferSize = nConvertDataSize; //ch:输出缓存大å°� | en:output buffer size + int nRet = MV_CC_ConvertPixelType(handle, &stConvertParam); + + Mat mysrcImage = cv::Mat(pFrameInfo0->nHeight, pFrameInfo0->nWidth, CV_8UC3, stConvertParam.pDstBuffer); + mysrcImage.copyTo(srcImage); + + free(pConvertData); + pConvertData = NULL; + stConvertParam = { 0 }; + } + } + } + if(srcImage.empty()) + { + srcImage = cv::Mat(5, 5, CV_8UC1).setTo(0); + } + + m_flag = true; + queuepic.push_back(srcImage.clone()); + n_mutex->unlock(); + pData0 = { 0 }; + double time_End = (double)clock(); + qDebug() << "[INFO] " << __FUNCTION__ << " line:" << __LINE__ << " checkImg getImg,Time:" << (time_End - time_Start) << "ms" + << "--CameraName:" << QString::fromStdString(Username) << " imgIndex:" << imgIndex << "nFrameNum : " << frameNum; + /*QString savePath = "../runtime/Bin_DEVICE/testImg/camera_" + QString::number(imgIndex + 1)+".png"; + cv::Mat resizeS; + cv::resize(srcImage, resizeS, cv::Size(), 0.1, 0.1); + cv::imwrite(savePath.toStdString(), resizeS);*/ +} + +void SetExposureTime(float exposureValue) +{ + qDebug() << "[INFO] " << "exposureValue:" << exposureValue; + MV_CC_SetEnumValue(handle, "ExposureAuto", MV_EXPOSURE_AUTO_MODE_OFF); + MV_CC_SetFloatValue(handle, "ExposureTime", exposureValue); +} + +void SetGain(float GainValue) +{ + qDebug() << "[INFO] " << "GainValue:" << GainValue; + MV_CC_SetEnumValue(handle, "GainAuto", 0); + MV_CC_SetFloatValue(handle, "Gain", GainValue); +} +Hd_CameraModule_HIK_soft::Hd_CameraModule_HIK_soft() +{ + n_mutex = new QMutex(); + m_thread = new MyThread; +} +//关闭设备 +void CloseDevice() +{ + MV_CC_StopGrabbing(handle); + MV_CC_CloseDevice(handle); + MV_CC_DestroyHandle(handle); + handle = nullptr; //此处注释掉的è¯�,软件断开å†�连接,回调函数ä¸�出图 +} + +Hd_CameraModule_HIK_soft::~Hd_CameraModule_HIK_soft() +{ + m_flag = true; + Sleep(10); + CloseDevice(); + if (n_mutex) + { + delete n_mutex; + n_mutex = nullptr; + } + if(m_thread) + { + m_thread->exit(); + m_thread->wait(1); + delete m_thread; + m_thread = nullptr; + } + + qDebug() << "[INFO] " << " delete success!"; +} +//从类中读数æ�®åˆ°å®žä¾‹å¯¹è±¡ +bool Hd_CameraModule_HIK_soft::readData(std::vector &mat,QByteArray &data) +{ + if (queuepic.isEmpty()) + { + qCritical() << __FUNCTION__ << " line:" <<__LINE__ << " srcImage is null"; + return false; + } + n_mutex->lock(); + cv::Mat img = cv::Mat(); + queuepic.dequeue().copyTo(img); + mat.push_back(img.clone()); + n_mutex->unlock(); + QString qimgIndex = "imgIndex_" + QString::number(imgIndex-1)+"_中文测试"; + data = qimgIndex.toLocal8Bit(); + qDebug() << "[INFO] " << __FUNCTION__ << " line:" << __LINE__ << " checkImg readData--CameraName:" << QString::fromStdString(Username) << "--imgIndex : " << imgIndex-1; + return true; +} +//实例对象把数æ�®å†™å…¥åˆ°ç±» +bool Hd_CameraModule_HIK_soft::writeData(std::vector &mat,QByteArray &data) +{ + //2024.02.18更新,相机对应的读SNä¿¡å�·æ—¶ï¼Œè¡¨ç¤ºæ–°äº§å“�进入,设置åˆ�始值 + if (data == "rest_newProductIn") + { + //æ ¹æ�®å®žé™…项目,设置åˆ�始值:æ›�å…‰ã€�增益,ROI区域等 + { + if (expourseTimeList.size() > 0) + SetExposureTime(expourseTimeList[0]); + if (gainList.size() > 0) + SetGain(gainList[0]); + } + + if (queuepic.size() > 0) + { + n_mutex->lock(); + queuepic.clear(); + n_mutex->unlock(); + std::cout << "rest_newProductIn , queuePic.size() > 0 ,signal maybe too fast " << Username << std::endl; + qWarning() << __FUNCTION__ << " line: " << __LINE__ << "rest_newProductIn , queuePic.size() > 0 ,signal maybe too fast " << QString::fromStdString(Username); + } + if (ifRunning == true) + { + ifBreak = true; + Sleep(10); + } + imgIndex = 0; + return true; + } + else + { + m_flag = false; + //expourseTimeList.clear(); + //gainList.clear(); + } + if (data == "ifChangeExpourseAndGain_false") + ifChangeExpourseAndGain = false; + else + ifChangeExpourseAndGain = true; + if (data.contains("SetExposureTime_")) + { + QByteArrayList dataList = data.split('#'); + for (int i = 0; i < dataList.size(); i++) + { + if (dataList[i].contains("SetExposureTime_")) + { + int value = byteArrayToUnicode(dataList[i]).split("SetExposureTime_")[1].toInt(); + SetExposureTime(value); + } + if (dataList[i].contains("SetGain_")) + { + double value = byteArrayToUnicode(dataList[i]).split("SetGain_")[1].toInt(); + SetGain(value); + } + if (dataList[i].contains("TriggerMode_")) + { + QString value = byteArrayToUnicode(dataList[i]).split("TriggerMode_")[1]; + if (value == "软触å�‘") + ////触å�‘模å¼� + { + MV_CC_SetEnumValue(handle, "TriggerSource", MV_TRIGGER_SOURCE_SOFTWARE); + currentTriggerSource = MV_TRIGGER_SOURCE_SOFTWARE; + } + else + { + MV_CC_SetEnumValue(handle, "TriggerSource", MV_TRIGGER_SOURCE_LINE0); + currentTriggerSource = MV_TRIGGER_SOURCE_LINE0; + } + } + } + } + //调试模å¼�下,data==ifChangeExpourseAndGain_falseï¼›é�žè°ƒè¯•模å¼�è¿�行时,dataä¸�包å�«SetExposureTime_ + else if (data != "ifChangeExpourseAndGain_false" && initTriggerSource != currentTriggerSource) + { + MV_CC_SetEnumValue(handle, "TriggerSource", initTriggerSource); + currentTriggerSource = initTriggerSource; + } + + + /*data.append("SetExposureTime_" + ui.spinBox->text() + "#"); + data.append("SetGain_" + ui.doubleSpinBox->text() + "#"); + data.append("TriggerMode_" + ui.comboBox_triggerMode->currentText());*/ + + + qDebug() << "Hd_CameraModule_HIK_soft::writeData::" << data; + + m_flag = false; + //Username = data.toStdString(); + return true; +} + + +//ä¼ å…¥initParas函数,格å¼�为:相机key+å�‚æ•°å��1#å�‚数值1#å�‚数值2+å�‚æ•°å��2#å�‚数值1... +bool Hd_CameraModule_HIK_soft::initParas(QByteArray& initData) +{ + QByteArrayList valueList = initData.split('+'); + Username = valueList[0]; + imgIndex = 0; + + expourseTimeList.clear(); + gainList.clear(); + + + bool ifOk = true; + if (handle == NULL) + ifOk = connctDevice(); + if (ifOk == false) + return false; + if (valueList.size() > 1) + for (int i = 1; i < valueList.size(); i++) + { + QString valuei = byteArrayToUnicode(valueList[i]); + //valuei.prepend(valueList[i]); + if (valuei.contains("expourseTime")) + { + QStringList expourseTimeL = valuei.split('#'); + if (expourseTimeL.size() > 1) + for (int j = 1; j < expourseTimeL.size(); j++) + expourseTimeList.enqueue(expourseTimeL[j].toFloat()); + } + if (valuei.contains("gain")) + { + QStringList gainL = valuei.split('#'); + if (gainL.size() > 1) + for (int j = 1; j < gainL.size(); j++) + gainList.enqueue(gainL[j].toFloat()); + } + + if (valuei.contains("是å�¦ä¸ºæ ‡å‡†é€šä¿¡æµ�程")) + { + if (valuei.contains("true")) + ifStandard = true; + } + if (valuei.contains("å�–图超时")) + { + QStringList gainL = valuei.split('#'); + if (gainL.size() > 1) + getImageTimeOut = gainL[1].toInt(); + if (getImageTimeOut < 50) + getImageTimeOut = 1000; + } + if (valuei.contains("OffsetX")) + { + QStringList valueL = valuei.split('#'); + if (valueL.size() > 1) + if(valueL[1].toInt()>=0) + MV_CC_SetIntValue(handle, "OffsetX", valueL[1].toInt()); + } + if (valuei.contains("OffsetY")) + { + QStringList valueL = valuei.split('#'); + if (valueL.size() > 1) + if (valueL[1].toInt() >= 0) + MV_CC_SetIntValue(handle, "OffsetY", valueL[1].toInt()); + } + if (valuei.contains("Width")) + { + QStringList valueL = valuei.split('#'); + if (valueL.size() > 1) + if (valueL[1].toInt() >= 0) + MV_CC_SetIntValue(handle, "Width", valueL[1].toInt()); + } + if (valuei.contains("Height")) + { + QStringList valueL = valuei.split('#'); + if (valueL.size() > 1) + if (valueL[1].toInt() >= 0) + MV_CC_SetIntValue(handle, "Height", valueL[1].toInt()); + } + + if (valuei.contains("触å�‘æ–¹å¼�")) + { + QStringList valueL = valuei.split('#'); + if (valueL.size() > 1) + if (valueL[1].toInt() >= 0) + if (valueL[1] == "软触å�‘") + { + MV_CC_SetEnumValue(handle, "TriggerSource", MV_TRIGGER_SOURCE_SOFTWARE); + currentTriggerSource = MV_TRIGGER_SOURCE_SOFTWARE; + initTriggerSource = MV_TRIGGER_SOURCE_SOFTWARE; + } + else + { + MV_CC_SetEnumValue(handle, "TriggerSource", MV_TRIGGER_SOURCE_LINE0); + currentTriggerSource = MV_TRIGGER_SOURCE_LINE0; + initTriggerSource = MV_TRIGGER_SOURCE_LINE0; + } + } + } + + if (ifOk == true) + { + if (expourseTimeList.size() > 0) + SetExposureTime(expourseTimeList[0]); + if (gainList.size() > 0) + SetGain(gainList[0]); + } + imgIndex = 0; + if (ifOk == true) + { + MVCC_FLOATVALUE mf = { 0 }; + MV_CC_GetFloatValue(handle, "ExposureTime", &mf); + std::cout << "ExposureTime::" << mf.fCurValue << std::endl; + mf = { 0 }; + MV_CC_GetFloatValue(handle, "Gain", &mf); + std::cout << "Gain::" << mf.fCurValue << std::endl; + MVCC_INTVALUE mI = { 0 }; + MV_CC_GetIntValue(handle, "OffsetX", &mI); + std::cout << "OffsetX::" << mI.nCurValue << std::endl; + mI = { 0 }; + MV_CC_GetIntValue(handle, "OffsetY", &mI); + std::cout << "OffsetY::" << mI.nCurValue << std::endl; + mI = { 0 }; + MV_CC_GetIntValue(handle, "Width", &mI); + std::cout << "Width::" << mI.nCurValue << std::endl; + mI = { 0 }; + MV_CC_GetIntValue(handle, "Height", &mI); + std::cout << "Height::" << mI.nCurValue << std::endl; + MVCC_ENUMVALUE me = { 0 }; + MV_CC_GetEnumValue(handle,"BalanceWhiteAuto",&me); //自动白平衡 + std::cout << "BalanceWhiteAuto::" << me.nCurValue << std::endl; + + } + + return ifOk; +} +bool Hd_CameraModule_HIK_soft::run() +{ + if (imgIndex == expourseTimeList.size()) + imgIndex = 0; + //Sleep(100); + qDebug() << "[INFO] " << " run start" <lock(); + m_flag = false; + //Sleep(2); + //n_mutex->unlock(); + //m_thread->run(); //start()线程è¿�行,频率高时有低概率无å“�应; + + if (currentTriggerSource == MV_TRIGGER_SOURCE_SOFTWARE) + { + MV_CC_SetCommandValue(handle, "TriggerSoftware"); + qDebug() << "[INFO] " << "TriggerSoftware"; + } + else + qDebug() << "[INFO] " << "TriggerHardware"; + //MV_CC_SetCommandValue(handle, "TriggerSoftware"); + //Sleep(15); + int mytime = 0; + qDebug() << "[INFO] " << " waite Img" << QString::fromStdString(Username); + while (true) + { + if (moduleStatus == false || mytime++ > getImageTimeOut || ifBreak == true )//|| m_flag==true) + { + result = false; + break; + } + n_mutex->lock(); + if (queuepic.size() > 0) + { + n_mutex->unlock(); + result = true; + break; + } + n_mutex->unlock(); + Sleep(1); + } + Sleep(1); + + //qDebug() << "[INFO] " << " expourseTimeList " << QString::fromStdString(Username); + //软触å�‘,ä¸�考虑误触å�‘ã€�æ¼�触å�‘ + if (ifChangeExpourseAndGain == true) + { + imgIndex++; + if (expourseTimeList.size() > 1 && expourseTimeList[imgIndex % expourseTimeList.size()] != expourseTimeList[(imgIndex - 1) % expourseTimeList.size()]) + SetExposureTime(expourseTimeList[imgIndex % expourseTimeList.size()]); + //Sleep(1); + if (gainList.size() > 1 && gainList[imgIndex % gainList.size()] != gainList[(imgIndex - 1) % gainList.size()]) + SetGain(gainList[imgIndex % gainList.size()]); + //Sleep(1); + } + if (result == false) + { + QString currPath = "../runtime/Bin_DEVICE/testImg/testImg_"; + if (ifChangeExpourseAndGain == true) + currPath +=QString::number(imgIndex-1); + else + currPath += QString::number(imgIndex); + currPath += ".jpg"; + cv::Mat readMat = cv::imread(currPath.toStdString()); + queuepic.push_back(readMat); + qDebug() << "å�–图失败,读å�–图片:" << currPath; + result = true; + } + + } + catch (QString ev) + { + qDebug() << "[Error] " << " ev:" << ev ; + } + qDebug() << "[INFO] " << __LINE__ << " run end" ; + return result; +} + +//相机连接状æ€�:正常连接或断开 +bool Hd_CameraModule_HIK_soft::checkStatus() +{ + //status = moduleStatus; + return moduleStatus; +} + +void MyThread::run() +{ + SetExposureTime(firstExposureTime);//第一次æ›�光数值 + MV_CC_SetCommandValue(handle, "TriggerSoftware"); + triggerLock.lock(); + triggerLock.lock(); + MV_CC_SetCommandValue(handle, "TriggerSoftware"); +} diff --git a/BaseModules/Hd_CameraModule_HIK_soft_TakeTwo/Hd_CameraModule_HIK_soft.h b/BaseModules/Hd_CameraModule_HIK_soft_TakeTwo/Hd_CameraModule_HIK_soft.h new file mode 100644 index 0000000..51b82b9 --- /dev/null +++ b/BaseModules/Hd_CameraModule_HIK_soft_TakeTwo/Hd_CameraModule_HIK_soft.h @@ -0,0 +1,59 @@ +#ifndef Hd_CameraModule_HIK_soft_H +#define Hd_CameraModule_HIK_soft_H + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +#include "base.h" + +using namespace cv; +#pragma execution_character_set("utf-8") + + +class MyThread; +class Hd_CameraModule_HIK_soft :public Base +{ +public: + Hd_CameraModule_HIK_soft(); + virtual ~Hd_CameraModule_HIK_soft(); + //从类中读数æ�®åˆ°å®žä¾‹å¯¹è±¡ + bool readData(std::vector& mat, QByteArray& data); + //实例对象把数æ�®å†™å…¥åˆ°ç±» + bool writeData(std::vector& mat, QByteArray& data); + bool initParas(QByteArray&); + bool run(); + bool checkStatus(); +private: + MyThread *m_thread = nullptr; +}; + +class MyThread : public QThread +{ + Q_OBJECT +public: + explicit MyThread(QObject *parent = nullptr):m_obj(parent){} + void run(); +private: + QObject *m_obj; +signals: + +}; + +extern "C" +{ +Q_DECL_EXPORT Hd_CameraModule_HIK_soft * create(); +Q_DECL_EXPORT void destory(Hd_CameraModule_HIK_soft * ptr); +} + +#endif // Hd_CameraModule_HIK_soft_H diff --git a/BaseModules/Hd_CameraModule_HIK_soft_TakeTwo/base.h b/BaseModules/Hd_CameraModule_HIK_soft_TakeTwo/base.h new file mode 100644 index 0000000..510c3df --- /dev/null +++ b/BaseModules/Hd_CameraModule_HIK_soft_TakeTwo/base.h @@ -0,0 +1,33 @@ +#ifndef __BASECLASS_H__ +#define __BASECLASS_H__ + +#include +#include +#include +#include +#include +#include + +class Base :public QObject +{ + Q_OBJECT +public: + bool init_flag; //是å�¦åˆ�始化,false,true + bool status = true; //相机状æ€�(判断相机是å�¦æ–­å¼€è¿žæŽ¥ï¼‰ + std::string paras; //传输数æ�® + std::vector m_mat; //传输图片 + std::string moduleName; //模å�—å��ç§° +public: + Base(){} + virtual ~Base(){} + virtual bool readData(std::vector&,QByteArray&){return true;} + virtual bool writeData(std::vector&,QByteArray&){return true;} + virtual bool initParas(QByteArray&){return true;} + virtual bool run() {return true;} + virtual bool checkStatus() { return true; } +signals: + void trigged(bool); +}; + + +#endif diff --git a/CMakeLists.txt b/CMakeLists.txt index 695d985..2b14a71 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -127,7 +127,7 @@ if(ON) else() SET( ${child}_target_link "opencv_world410" ) endif() - elseif(${child} MATCHES "Myalgo") + elseif(${child} MATCHES "halconAlgo") SET( ${child}_target_link "Inspection" ) elseif(${child} MATCHES "basler") SET( ${child}_target_link diff --git a/env/Myalgo/dll/Inspection.dll b/env/Myalgo/dll/Inspection.dll deleted file mode 100644 index 5c6481f..0000000 Binary files a/env/Myalgo/dll/Inspection.dll and /dev/null differ diff --git a/env/Myalgo/include/Myalgo.h b/env/Myalgo/include/Myalgo.h deleted file mode 100644 index 32028fe..0000000 --- a/env/Myalgo/include/Myalgo.h +++ /dev/null @@ -1,110 +0,0 @@ -#pragma once -#include -#include -#include - -//#include -//#include - -using namespace HalconCpp; - -#if 1 ºó¶Ëµ÷Óú¯Êý - -/* - ho_Image:ÊäÈëԭͼ - hv_out_Value£ºÊä³ö¼ì²â½á¹û 1ΪÂÁ£¬2Ϊͭ - hv_Make£ºËã·¨Ö´ÐÐ״̬-1ΪËã·¨NG£¬1ΪËã·¨ok - ¼«ÐÔ¼ì²âº¯Êý - ÈýЭ»ų́ -*/ -extern "C" __declspec(dllexport) void _stdcall _628_1_Polarity_detection(HObject ho_Image, HTuple* hv_out_Value, HTuple* hv_Make); - - - - -/* -* ho_Image£ºÊäÈëͼƬ£¨Ô­Í¼£© -* hv_model£º¸³ÖµÎª1ʱÊÇ»ù×¼±ê¶¨Ä£Ê½£¬0ΪÕý³£¼ì²âģʽ -* hv_BenchmarkFile£º»ù×¼±ê¶¨ÎļþµÄ·¾¶ -* hv_NinePointDocument£º¾ÅµãÎļþµÄ·¾¶ -*hv_CameraNumber£ºÉ϶¤Ïà»ú±àºÅ -* hv_out_Cirle£ºÊä³ö·Å¶¤¿×µÄÔ²ÐÄx£¬Ô²ÐÄy£¬°ë¾¶¡£Êý×éÐÎʽ -* hv_Make£ºÊä³ö-1ΪËã·¨´íÎó£¬Êä³ö1ΪËã·¨Õý³£Ö´ÐУ¬Êä³öΪ2Ϊ»ù×¼±ê¶¨³É¹¦ -* hv_offset_x£ºxÖá·½ÏòÉÏÏà¶ÔÓÚ»ù׼λÖÃµÄÆ«²î -* hv_offset_y£ºyÖá·½ÏòÉÏÏà¶ÔÓÚ»ù׼λÖÃµÄÆ«²î -* É϶¤Òýµ¼º¯Êý -*/ - -extern "C" __declspec(dllexport) void _stdcall _628_SealingNails(HObject ho_Image, HTuple hv_model, HTuple hv_BenchmarkFile, - HTuple hv_NinePointDocument, HTuple hv_CameraNumber, HTuple* hv_out_Cirle, HTuple* hv_Make, - HTuple* hv_offset_x, HTuple* hv_offset_y); - -/* -* ho_Image£ºÊäÈëͼƬ£¨Ô­Í¼£© -* hv_model£º¸³ÖµÎª1ʱÊÇ»ù×¼±ê¶¨Ä£Ê½£¬0ΪÕý³£¼ì²âģʽ -* hv_BenchmarkFile£º»ù×¼±ê¶¨ÎļþµÄ·¾¶ -* hv_NinePointDocument£º¾ÅµãÎļþµÄ·¾¶ -*hv_CameraNumber£ºÔ¤º¸Ïà»ú±àºÅ -* hv_out_Cirle£ºÊä³ö·Å¶¤¿×µÄÔ²ÐÄx£¬Ô²ÐÄy£¬°ë¾¶¡£Êý×éÐÎʽ -* hv_Make£ºÊä³ö-1ΪËã·¨´íÎó£¬Êä³ö1ΪËã·¨Õý³£Ö´ÐУ¬Êä³öΪ2Ϊ»ù×¼±ê¶¨³É¹¦ -* hv_offset_x£ºxÖá·½ÏòÉÏÏà¶ÔÓÚ»ù׼λÖÃµÄÆ«²î -* hv_offset_y£ºyÖá·½ÏòÉÏÏà¶ÔÓÚ»ù׼λÖÃµÄÆ«²î -* hv_Text:Êä³ö±¨¾¯ÐÅÏ¢°üÀ¨£¨ok£¬ÎÞ¶¤£¬Ç̶¤£¬·´¶¤£© -* Ô¤º¸º¯Êý -*/ - -extern "C" __declspec(dllexport) void _stdcall _628_yuhan(HObject ho_Image, HTuple hv_Model, HTuple hv_BenchmarkFile, HTuple hv_NinePointDocument, - HTuple hv_CameraNumber, HTuple* hv_out_Cirle, HTuple* hv_Make, HTuple* hv_offset_x, - HTuple* hv_offset_y, HTuple* hv_Text); - - -/* -* ho_Image£ºÊäÈëͼƬ£¨Ô­Í¼£© -* hv_model£º¸³ÖµÎª1ʱÊÇ»ù×¼±ê¶¨Ä£Ê½£¬0ΪÕý³£¼ì²âģʽ -* hv_BenchmarkFile£º»ù×¼±ê¶¨ÎļþµÄ·¾¶ -* hv_NinePointDocument£º¾ÅµãÎļþµÄ·¾¶ -*hv_CameraNumber£ºÔ¤º¸Ïà»ú±àºÅ -* hv_out_Cirle£ºÊä³ö·Å¶¤¿×µÄÔ²ÐÄx£¬Ô²ÐÄy£¬°ë¾¶¡£Êý×éÐÎʽ -* hv_Make£ºÊä³ö-1ΪËã·¨´íÎó£¬Êä³ö1ΪËã·¨Õý³£Ö´ÐУ¬Êä³öΪ2Ϊ»ù×¼±ê¶¨³É¹¦ -* hv_offset_x£ºxÖá·½ÏòÉÏÏà¶ÔÓÚ»ù׼λÖÃµÄÆ«²î -* hv_offset_y£ºyÖá·½ÏòÉÏÏà¶ÔÓÚ»ù׼λÖÃµÄÆ«²î -* ÖÕº¸º¯Êý -*/ -extern "C" __declspec(dllexport) void _stdcall _628_FinalWelding(HObject ho_Image, HTuple hv_model, HTuple hv_BenchmarkFile, - HTuple hv_NinePointDocument, HTuple hv_CameraNumber, HTuple* hv_out_Cirle, HTuple* hv_Make, - HTuple* hv_offset_x, HTuple* hv_offset_y); -#endif - -#if 1 halconµ÷Óú¯Êý -void gen_arrow_contour_xld(HObject* ho_Arrow, HTuple hv_Row1, HTuple hv_Column1, - HTuple hv_Row2, HTuple hv_Column2, HTuple hv_HeadLength, HTuple hv_HeadWidth); -void Get_Rectangle2_Corner_new(HObject ho_Rectangle, HTuple* hv_out_Row, HTuple* hv_out_Col); - -void pts_to_best_line(HObject* ho_Line, HTuple hv_Rows, HTuple hv_Cols, HTuple hv_ActiveNum, - HTuple* hv_Row1, HTuple* hv_Column1, HTuple* hv_Row2, HTuple* hv_Column2); -void rake(HObject ho_Image, HObject* ho_Regions, HTuple hv_Elements, HTuple hv_DetectHeight, - HTuple hv_DetectWidth, HTuple hv_Sigma, HTuple hv_Threshold, HTuple hv_Transition, - HTuple hv_Select, HTuple hv_Row1, HTuple hv_Column1, HTuple hv_Row2, HTuple hv_Column2, - HTuple* hv_ResultRow, HTuple* hv_ResultColumn); - -void pts_to_best_circle(HObject* ho_Circle, HTuple hv_Rows, HTuple hv_Cols, HTuple hv_ArcType, - HTuple hv_ActiveNum, HTuple* hv_RowCenter, HTuple* hv_ColCenter, HTuple* hv_Radius, - HTuple* hv_StartPhi, HTuple* hv_EndPhi, HTuple* hv_PointOrder, HTuple* hv_ArcAngle); - -void region_to_spoke(HObject ho_Region, HTuple hv_Offset, HTuple* hv_SpokeRows, - HTuple* hv_SpokeCols); - -void spoke(HObject ho_Image, HObject* ho_Regions, HTuple hv_Elements, HTuple hv_DetectHeight, - HTuple hv_DetectWidth, HTuple hv_Sigma, HTuple hv_Threshold, HTuple hv_Transition, - HTuple hv_Select, HTuple hv_ROIRows, HTuple hv_ROICols, HTuple hv_Direct, HTuple* hv_ResultRow, - HTuple* hv_ResultColumn, HTuple* hv_ArcType); - -void _628_PreWelded(HObject ho_Image, HTuple hv_model, HTuple hv_BenchmarkFile, - HTuple hv_NinePointDocument, HTuple hv_CameraNumber, HTuple* hv_out_Cirle, HTuple* hv_Make, - HTuple* hv_offset_x, HTuple* hv_offset_y); -#endif - - - - - diff --git a/env/Myalgo/lib/Inspection.lib b/env/Myalgo/lib/Inspection.lib deleted file mode 100644 index d9d4867..0000000 Binary files a/env/Myalgo/lib/Inspection.lib and /dev/null differ diff --git a/env/halconAlgo/dll/Inspection.dll b/env/halconAlgo/dll/Inspection.dll new file mode 100644 index 0000000..f906aa3 Binary files /dev/null and b/env/halconAlgo/dll/Inspection.dll differ diff --git a/env/halconAlgo/include/algo.h b/env/halconAlgo/include/algo.h new file mode 100644 index 0000000..892636f --- /dev/null +++ b/env/halconAlgo/include/algo.h @@ -0,0 +1,272 @@ +#pragma once +#include +#include +#include + +//#include +//#include + +using namespace HalconCpp; + +#if 1 ºó¶Ëµ÷Óú¯Êý + +/* + ho_Image:ÊäÈëԭͼ + hv_out_Value£ºÊä³ö¼ì²â½á¹û 1ΪÂÁ£¬2Ϊͭ + hv_Make£ºËã·¨Ö´ÐÐ״̬-1ΪËã·¨NG£¬1ΪËã·¨ok + ¼«ÐÔ¼ì²âº¯Êý + Ô¤º¸ÈýЭ»ų́ +*/ +extern "C" __declspec(dllexport) void _stdcall _628_1_Polarity_detection(HObject ho_Image, HTuple* hv_out_Value, HTuple* hv_Make); + +/* +* ho_Image£ºÊäÈëͼƬ£¨Ô­Í¼£© +* hv_NinePointDocument£º¾ÅµãÎļþµÄ·¾¶ +* hv_SetNumber:ÉèÖýº¶¤µÄ×îС¸öÊý +* hv_Circle_Point£ºÊä³ö·Å¶¤¿×µÄÔ²ÐÄx£¬Ô²ÐÄy£¬°ë¾¶¡£Êý×éÐÎʽ +* hv_Make£ºÊä³ö-1ΪËã·¨´íÎó£¬Êä³ö1ΪËã·¨Õý³£Ö´ÐÐ +*hv_Out_Roboot1£ºÎü×ì1-> Îü×ì±àºÅ,x¾ø¶Ô×ø±ê£¬y¾ø¶Ô×ø±ê +* hv_Out_Roboot2£ºÎü×ì2->Îü×ì±àºÅ£¬x¾ø¶Ô×ø±ê£¬y¾ø¶Ô×ø±ê +* hv_Out_Roboot3£ºÎü×ì3->Îü×ì±àºÅ£¬x¾ø¶Ô×ø±ê£¬y¾ø¶Ô×ø±ê +* »úÆ÷ÈËÒýµ¼º¯Êý +* ÈýЭ»ų́ +*/ +extern "C" __declspec(dllexport) void _stdcall _628_BootTheMachine(HObject ho_Image, HTuple hv_NinePointDocument, HTuple hv_SetNumber, + HTuple* hv_Circle_Point, HTuple* hv_Make, HTuple* hv_Out_Roboot1, HTuple* hv_Out_Roboot2,HTuple* hv_Out_Roboot3); + +/* +*ho_Image£ºÊäÈëͼƬ£¨Ô­Í¼£© +* hv_Pix£ºÏñËØ¾«¶È +* hv_out_line:Êä³öÖ±Ïß×ø±ê +* hv_distance£ºÊä³ö²âÁ¿Öµ ->¸ß£¬¿í¡£Êý×éÐÎʽ +* hv_Make£ºÊä³ö-1ΪËã·¨´íÎó£¬Êä³ö1ΪËã·¨Õý³£Ö´ÐÐ +* Í­¼«¶ú²Ã¼ô²âÁ¿º¯Êý +* ÈýЭԤº¸»ų́ +*/ + +extern "C" __declspec(dllexport) void _stdcall cs_628_jier_T(HObject ho_Image, HTuple hv_Pix, HTuple* hv_out_line, HTuple* hv_out_Soldering_line, + HTuple* hv_distance, HTuple* hv_Make); + + + +/* +* ho_Image£ºÊäÈëͼƬ£¨Ô­Í¼£© +* hv_model£º¸³ÖµÎª1ʱÊÇ»ù×¼±ê¶¨Ä£Ê½£¬0ΪÕý³£¼ì²âģʽ +* hv_BenchmarkFile£º»ù×¼±ê¶¨ÎļþµÄ·¾¶ +* hv_NinePointDocument£º¾ÅµãÎļþµÄ·¾¶ +*hv_CameraNumber£ºÉ϶¤Ïà»ú±àºÅ +* hv_out_Cirle£ºÊä³ö·Å¶¤¿×µÄÔ²ÐÄx£¬Ô²ÐÄy£¬°ë¾¶¡£Êý×éÐÎʽ +* hv_Make£ºÊä³ö-1ΪËã·¨´íÎó£¬Êä³ö1ΪËã·¨Õý³£Ö´ÐУ¬Êä³öΪ2Ϊ»ù×¼±ê¶¨³É¹¦ +* hv_offset_x£ºxÖá·½ÏòÉÏÏà¶ÔÓÚ»ù׼λÖÃµÄÆ«²î +* hv_offset_y£ºyÖá·½ÏòÉÏÏà¶ÔÓÚ»ù׼λÖÃµÄÆ«²î +* ´ò¶¤¶¤Òýµ¼º¯Êý +* ÈýЭµÄ»ų́ +*/ + +extern "C" __declspec(dllexport) void _stdcall _628_NailingPosition(HObject ho_Image, HTuple hv_model, HTuple hv_BenchmarkFile, + HTuple hv_NinePointDocument, HTuple hv_CameraNumber, HTuple* hv_out_Cirle, HTuple* hv_Make, + HTuple* hv_offset_x, HTuple* hv_offset_y); + + +/* + ho_Image:ÊäÈëԭͼ + hv_out_Value£ºÊä³ö¼ì²â½á¹û[1,1] .1ΪÂÁ£¬[2,2] 2Ϊͭ + hv_Make£ºËã·¨Ö´ÐÐ״̬-1ΪËã·¨NG£¬1ΪËã·¨ok + ¼«ÐÔ¼ì²âº¯Êý + ÖÕº¸ÈýЭ»ų́ +*/ +extern "C" __declspec(dllexport) void _stdcall _628_2_Polarity_detection(HObject ho_Image, HTuple* hv_out_Value, HTuple* hv_Make); + +/* +* ho_Image_L£ºÊäÈëͼƬÂÁ +* ho_Image_T£ºÊäÈëͼƬͭ +* hv_Pix_T:Í­¼«ÏñËØ¾«¶È +* hv_Pix_L:ÂÁ¼«ÏñËØ¾«¶È +* hv_Out_Vale_L£ºÊä³öÂÁ¼«²âÁ¿Öµ°üÀ¨Á½¸öÖµ +* hv_Out_Line_L£ºÊä³öÂÁ¼«»®Ïß×ø±ê +* hv_Out_Vale_T£ºÊä³öÂÁ¼«²âÁ¿Öµ°üÀ¨Á½¸öÖµ +* hv_Out_Line_T£ºÊä³öÍ­¼«¼«»®Ïß×ø±ê +* hv_Out_extremum_Value£ºÊä³öÁ½¼«Ö®¼äµÄ¾àÀë +* hv_Make£ºÊä³ö-1ΪËã·¨´íÎó£¬Êä³ö1ΪËã·¨Õý³£Ö´ÐÐ +* Ô¤º¸º¸Ç°²âÁ¿º¯Êý +* ÈýЭµÄ»ų́ +*/ +extern "C" __declspec(dllexport) void _stdcall _628_2_BeforeWelding_Distnce(HObject ho_Image_L, HObject ho_Image_T, HTuple hv_Pix_T, + HTuple hv_Pix_L, HTuple* hv_Out_Vale_L, HTuple* hv_Out_Line_L, HTuple* hv_Out_Vale_T, + HTuple* hv_Out_Line_T, HTuple* hv_Out_extremum_Value, HTuple* hv_Makes); + +/* +* ho_Image £ºÊäÈëͼƬÂÁ¼« +* ho_ImageSeg £ºÊäÈëͼƬsegͼ£¨¶þֵͼ£© +* hv_Pix : ÂÁ¼«ÏñËØ¾«¶È +* hv_Out_TopLeft_Line : ×óÉÏÊä³öÏߵĶ˵ã×ø±ê +* hv_Out_TopLeft_Value £º×óÉÏÊä³öµÄ²âÁ¿Öµ£¨2¸öÖµ£© +* hv_Out_TopRight_Line £ºÓÒÉÏÊä³öÏߵĶ˵ã×ø±ê +* hv_Out_TopRight_Value £ºÓÒÉÏÊä³öµÄ²âÁ¿Öµ£¨2¸öÖµ£© +* hv_Out_BottomLeft_Line £º×óÏÂÊä³öÏߵĶ˵ã×ø±ê +* hv_Out_BottomLeft_Value £º×óÏÂÊä³öµÄ²âÁ¿Öµ£¨2¸öÖµ£© +** hv_Out_BottomRight_Line £ºÓÒÏÂÊä³öÏߵĶ˵ã×ø±ê +* hv_Out_BottomRight_Value £ºÓÒÏÂÊä³öµÄ²âÁ¿Öµ£¨2¸öÖµ£© +* hv_Make£ºÊä³ö-1ΪËã·¨´íÎó£¬Êä³ö1ΪËã·¨Õý³£Ö´ÐÐ +* Ô¤º¸º¸ºó²âÁ¿ÂÁ¼«º¯Êý +* ÈýЭµÄ»ų́ +*/ + +extern "C" __declspec(dllexport) void _stdcall _628_AfterWelding_Distance_L(HObject ho_Image, HObject ho_ImageSeg, HTuple hv_Pix, + HTuple* hv_Out_TopLeft_Line, HTuple* hv_Out_TopLeft_Value, HTuple* hv_Out_TopRight_Line, + HTuple* hv_Out_TopRight_Value, HTuple* hv_Out_BottomLeft_Line, HTuple* hv_Out_BottomLeft_Value, + HTuple* hv_Out_BottomRight_Line, HTuple* hv_Out_BottomRight_Value, HTuple* hv_Make); + +/* +* ho_Image £ºÊäÈëͼƬÂÁ¼« +* ho_ImageSeg £ºÊäÈëͼƬsegͼ£¨¶þֵͼ£© +* hv_Pix : ÂÁ¼«ÏñËØ¾«¶È +* hv_Out_TopLeft_Line : ×óÉÏÊä³öÏߵĶ˵ã×ø±ê +* hv_Out_TopLeft_Value £º×óÉÏÊä³öµÄ²âÁ¿Öµ£¨2¸öÖµ£© +* hv_Out_TopRight_Line £ºÓÒÉÏÊä³öÏߵĶ˵ã×ø±ê +* hv_Out_TopRight_Value £ºÓÒÉÏÊä³öµÄ²âÁ¿Öµ£¨2¸öÖµ£© +* hv_Out_BottomLeft_Line £º×óÏÂÊä³öÏߵĶ˵ã×ø±ê +* hv_Out_BottomLeft_Value £º×óÏÂÊä³öµÄ²âÁ¿Öµ£¨2¸öÖµ£© +** hv_Out_BottomRight_Line £ºÓÒÏÂÊä³öÏߵĶ˵ã×ø±ê +* hv_Out_BottomRight_Value £ºÓÒÏÂÊä³öµÄ²âÁ¿Öµ£¨2¸öÖµ£© +* hv_Make£ºÊä³ö-1ΪËã·¨´íÎó£¬Êä³ö1ΪËã·¨Õý³£Ö´ÐÐ +* Ô¤º¸º¸ºó²âÁ¿Í­¼«º¯Êý +* ÈýЭµÄ»ų́ +*/ + +extern "C" __declspec(dllexport) void _stdcall _628_AfterWelding_Distance_T(HObject ho_Image, HObject ho_ImageSeg, HTuple hv_Pix, + HTuple* hv_Out_TopLeft_Line, HTuple* hv_Out_TopLeft_Value, HTuple* hv_Out_TopRight_Line, + HTuple* hv_Out_TopRight_Value, HTuple* hv_Out_BottomLeft_Line, HTuple* hv_Out_BottomLeft_Value, + HTuple* hv_Out_BottomRight_Line, HTuple* hv_Out_BottomRight_Value, HTuple* hv_Make); + + + + + + + + + + + + + + + + + + +/* +* ho_Image£ºÊäÈëͼƬ£¨Ô­Í¼£© +* hv_model£º¸³ÖµÎª1ʱÊÇ»ù×¼±ê¶¨Ä£Ê½£¬0ΪÕý³£¼ì²âģʽ +* hv_BenchmarkFile£º»ù×¼±ê¶¨ÎļþµÄ·¾¶ +* hv_NinePointDocument£º¾ÅµãÎļþµÄ·¾¶ +*hv_CameraNumber£ºÉ϶¤Ïà»ú±àºÅ +* hv_out_Cirle£ºÊä³ö·Å¶¤¿×µÄÔ²ÐÄx£¬Ô²ÐÄy£¬°ë¾¶¡£Êý×éÐÎʽ +* hv_Make£ºÊä³ö-1ΪËã·¨´íÎó£¬Êä³ö1ΪËã·¨Õý³£Ö´ÐУ¬Êä³öΪ2Ϊ»ù×¼±ê¶¨³É¹¦ +* hv_offset_x£ºxÖá·½ÏòÉÏÏà¶ÔÓÚ»ù׼λÖÃµÄÆ«²î +* hv_offset_y£ºyÖá·½ÏòÉÏÏà¶ÔÓÚ»ù׼λÖÃµÄÆ«²î +* É϶¤Òýµ¼º¯Êý +* Ó®ºÏµÄ»ų́ +*/ + +extern "C" __declspec(dllexport) void _stdcall _628_SealingNails(HObject ho_Image, HTuple hv_model, HTuple hv_BenchmarkFile, + HTuple hv_NinePointDocument, HTuple hv_CameraNumber, HTuple* hv_out_Cirle, HTuple* hv_Make, + HTuple* hv_offset_x, HTuple* hv_offset_y); + +/* +* ho_Image£ºÊäÈëͼƬ£¨Ô­Í¼£© +* hv_model£º¸³ÖµÎª1ʱÊÇ»ù×¼±ê¶¨Ä£Ê½£¬0ΪÕý³£¼ì²âģʽ +* hv_BenchmarkFile£º»ù×¼±ê¶¨ÎļþµÄ·¾¶ +* hv_NinePointDocument£º¾ÅµãÎļþµÄ·¾¶ +*hv_CameraNumber£ºÔ¤º¸Ïà»ú±àºÅ +* hv_out_Cirle£ºÊä³ö·Å¶¤¿×µÄÔ²ÐÄx£¬Ô²ÐÄy£¬°ë¾¶¡£Êý×éÐÎʽ +* hv_Make£ºÊä³ö-1ΪËã·¨´íÎó£¬Êä³ö1ΪËã·¨Õý³£Ö´ÐУ¬Êä³öΪ2Ϊ»ù×¼±ê¶¨³É¹¦ +* hv_offset_x£ºxÖá·½ÏòÉÏÏà¶ÔÓÚ»ù׼λÖÃµÄÆ«²î +* hv_offset_y£ºyÖá·½ÏòÉÏÏà¶ÔÓÚ»ù׼λÖÃµÄÆ«²î +* hv_Text:Êä³ö±¨¾¯ÐÅÏ¢°üÀ¨£¨ok£¬ÎÞ¶¤£¬Ç̶¤£¬·´¶¤£© +* Ó®ºÏ»ų́ +* Ô¤º¸º¯Êý +*/ +extern "C" __declspec(dllexport) void _stdcall _628_yuhan(HObject ho_Image, HTuple hv_Model, HTuple hv_BenchmarkFile, HTuple hv_NinePointDocument, + HTuple hv_CameraNumber, HTuple* hv_out_Cirle, HTuple* hv_Make, HTuple* hv_offset_x, + HTuple* hv_offset_y, HTuple* hv_Text); + +/* +* ho_Image£ºÊäÈëͼƬ£¨Ô­Í¼£© +* hv_model£º¸³ÖµÎª1ʱÊÇ»ù×¼±ê¶¨Ä£Ê½£¬0ΪÕý³£¼ì²âģʽ +* hv_BenchmarkFile£º»ù×¼±ê¶¨ÎļþµÄ·¾¶ +* hv_NinePointDocument£º¾ÅµãÎļþµÄ·¾¶ +*hv_CameraNumber£ºÔ¤º¸Ïà»ú±àºÅ +* hv_out_Cirle£ºÊä³ö·Å¶¤¿×µÄÔ²ÐÄx£¬Ô²ÐÄy£¬°ë¾¶¡£Êý×éÐÎʽ +* hv_Make£ºÊä³ö-1ΪËã·¨´íÎó£¬Êä³ö1ΪËã·¨Õý³£Ö´ÐУ¬Êä³öΪ2Ϊ»ù×¼±ê¶¨³É¹¦ +* hv_offset_x£ºxÖá·½ÏòÉÏÏà¶ÔÓÚ»ù׼λÖÃµÄÆ«²î +* hv_offset_y£ºyÖá·½ÏòÉÏÏà¶ÔÓÚ»ù׼λÖÃµÄÆ«²î +* ÖÕº¸º¯Êý +* Ó®ºÏµÄ»ų́ +*/ +extern "C" __declspec(dllexport) void _stdcall _628_FinalWelding(HObject ho_Image, HTuple hv_model, HTuple hv_BenchmarkFile, + HTuple hv_NinePointDocument, HTuple hv_CameraNumber, HTuple* hv_out_Cirle, HTuple* hv_Make, + HTuple* hv_offset_x, HTuple* hv_offset_y); + +/* +* ho_Image1£ºÊäÈëͼƬ£¨Ô­Í¼£© +* ho_Image2£ºÊäÈëͼƬ£¨Ô­Í¼£© +* ho_Image3£ºÊäÈëͼƬ£¨Ô­Í¼£© +* ho_Image4£ºÊäÈëͼƬ£¨Ô­Í¼£© +*ho_Out_Image1£ºÊä³öͼƬ1 +* ho_Out_image2£ºÊä³öͼƬ2 +* hv_Make£ºÊä³ö-1ΪËã·¨´íÎó£¬Êä³ö1ΪËã·¨Õý³£Ö´ÐУ¬Êä³öΪ2Ϊ»ù×¼±ê¶¨³É¹¦ +* hv_sacats£º¹âÔ´Óë¹âÖá¼Ð½Ç +* hv_Tilts£º¹âÔ´°²×°Î»Öà +*/ + +extern "C" __declspec(dllexport) void _stdcall _628_25D(HObject ho_Image1, HObject ho_Image2, HObject ho_Image3, HObject ho_Image4, + HObject* ho_Out_Image1, HObject* ho_Out_image2, HTuple hv_sacats, HTuple hv_Tilts, + HTuple* hv_Make); + + +#endif + +#if 1 halconµ÷Óú¯Êý + +void gen_arrow_contour_xld(HObject* ho_Arrow, HTuple hv_Row1, HTuple hv_Column1, + HTuple hv_Row2, HTuple hv_Column2, HTuple hv_HeadLength, HTuple hv_HeadWidth); +void Get_Rectangle2_Corner_new(HObject ho_Rectangle, HTuple* hv_out_Row, HTuple* hv_out_Col); + +void pts_to_best_line(HObject* ho_Line, HTuple hv_Rows, HTuple hv_Cols, HTuple hv_ActiveNum, + HTuple* hv_Row1, HTuple* hv_Column1, HTuple* hv_Row2, HTuple* hv_Column2); +void rake(HObject ho_Image, HObject* ho_Regions, HTuple hv_Elements, HTuple hv_DetectHeight, + HTuple hv_DetectWidth, HTuple hv_Sigma, HTuple hv_Threshold, HTuple hv_Transition, + HTuple hv_Select, HTuple hv_Row1, HTuple hv_Column1, HTuple hv_Row2, HTuple hv_Column2, + HTuple* hv_ResultRow, HTuple* hv_ResultColumn); + +void pts_to_best_circle(HObject* ho_Circle, HTuple hv_Rows, HTuple hv_Cols, HTuple hv_ArcType, + HTuple hv_ActiveNum, HTuple* hv_RowCenter, HTuple* hv_ColCenter, HTuple* hv_Radius, + HTuple* hv_StartPhi, HTuple* hv_EndPhi, HTuple* hv_PointOrder, HTuple* hv_ArcAngle); + +void region_to_spoke(HObject ho_Region, HTuple hv_Offset, HTuple* hv_SpokeRows, + HTuple* hv_SpokeCols); + +void spoke(HObject ho_Image, HObject* ho_Regions, HTuple hv_Elements, HTuple hv_DetectHeight, + HTuple hv_DetectWidth, HTuple hv_Sigma, HTuple hv_Threshold, HTuple hv_Transition, + HTuple hv_Select, HTuple hv_ROIRows, HTuple hv_ROICols, HTuple hv_Direct, HTuple* hv_ResultRow, + HTuple* hv_ResultColumn, HTuple* hv_ArcType); + +void _628_PreWelded(HObject ho_Image, HTuple hv_model, HTuple hv_BenchmarkFile, + HTuple hv_NinePointDocument, HTuple hv_CameraNumber, HTuple* hv_out_Cirle, HTuple* hv_Make, + HTuple* hv_offset_x, HTuple* hv_offset_y); + +void BeforeWelding_L(HObject ho_Image_L, HTuple hv_Pix_T, HTuple* hv_Make, HTuple* hv_Out_Line, + HTuple* hv_Out_Vale, HTuple* hv_Out_PointRow, HTuple* hv_Out_PointCol); + +void BeforeWelding_T(HObject ho_Image_T, HTuple hv_Pix_T, HTuple* hv_Make, HTuple* hv_Out_Line, + HTuple* hv_Out_Vale, HTuple* hv_Out_PointRow, HTuple* hv_Out_PointCol); + + +#endif + + + + + diff --git a/env/halconAlgo/lib/Inspection.lib b/env/halconAlgo/lib/Inspection.lib new file mode 100644 index 0000000..a0ce9b4 Binary files /dev/null and b/env/halconAlgo/lib/Inspection.lib differ diff --git a/env/myTools/include/myTools.h b/env/myTools/include/myTools.h index f960081..46bb0cc 100644 --- a/env/myTools/include/myTools.h +++ b/env/myTools/include/myTools.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include #include #define FENGZHUANG_API __declspec(dllexport) @@ -10,13 +10,14 @@ #include #include #include +#include using namespace cv; FENGZHUANG_API void putTextHusky(Mat& dst, const char* str, Point org, Scalar color, int fontSize, const char* fn = "Arial", bool italic = false, bool underline = false); -FENGZHUANG_API int32_t createDirectory(const wstring& directoryPath); -FENGZHUANG_API int32_t createDirectory(const string& directoryPath); +FENGZHUANG_API int32_t createDirectory(const std::wstring& directoryPath); +FENGZHUANG_API int32_t createDirectory(const std::string& directoryPath); FENGZHUANG_API char* UnicodeToAnsi(const wchar_t* szStr); FENGZHUANG_API wchar_t* AnsiToUnicode(const char* szStr); FENGZHUANG_API std::string WString2String(const std::wstring& ws);