You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
2.1 KiB
C++
79 lines
2.1 KiB
C++
#include "ModelTrain.h"
|
|
#include "qcoreapplication.h"
|
|
#include "qstring.h"
|
|
#include "opencv\cv.h"
|
|
#include "opencv\highgui.h"
|
|
//#include "ImageProcess.h"
|
|
#include "qfile.h"
|
|
#include "qiodevice.h"
|
|
#include "qstringlist.h"
|
|
#include "imgcodecs.hpp"
|
|
#include <vector>
|
|
|
|
using namespace std;
|
|
ModelTrain::ModelTrain()
|
|
{
|
|
}
|
|
|
|
|
|
ModelTrain::~ModelTrain()
|
|
{
|
|
}
|
|
|
|
// cv::Mat ModelTrain::findCircleObject(QString strPath, int nThres /*= 20*/, luffy_base::luffyCircle *pCircle /*= NULL*/)
|
|
// {
|
|
// //cv::Mat src = cv::imread(strPath.toLatin1().data(), 0);
|
|
// cv::Mat src = cv::imread(std::string((const char*)strPath.toLocal8Bit()), 0);
|
|
// cv::Mat back = ModelTrain::getBackGoundImage();
|
|
// return ImageProcess::findCircleObject(src, back, nThres, pCircle);
|
|
// }
|
|
|
|
cv::Mat ModelTrain::getBackGoundImage()
|
|
{
|
|
static cv::Mat matback;
|
|
if (matback.empty()){
|
|
QString filepath = qApp->applicationDirPath() + "\\user\\background.png";
|
|
//matback = cv::imread(filepath.toLatin1().data(), 0);
|
|
matback = cv::imread(std::string((const char*)filepath.toLocal8Bit()), 0);
|
|
}
|
|
return matback;
|
|
}
|
|
|
|
bool ModelTrain::caliDiameter2Thickness(float &a, float &b)
|
|
{
|
|
QString str = QCoreApplication::applicationDirPath() + "\\user\\diameter2thickness.csv";
|
|
QFile qFile(str);
|
|
bool bb = qFile.open(QIODevice::ReadOnly);
|
|
QString st = qFile.readAll();
|
|
qFile.close();
|
|
QStringList lst = st.split(";");
|
|
vector<cv::Point2f> points;
|
|
for (int i = 0; i < lst.size(); i++) {
|
|
QStringList l = lst.at(i).split(",");
|
|
if (l.size() == 2) {
|
|
points.push_back(cv::Point2f(l.first().toDouble(), l.last().toDouble() / 4.0));
|
|
}
|
|
}
|
|
if (!bb || points.size() < 3) {
|
|
return false;
|
|
}
|
|
int nSize = points.size();
|
|
double t1 = 0, t2 = 0, t3 = 0, t4 = 0;
|
|
for (int i = 0; i < points.size(); ++i)
|
|
{
|
|
t1 += points[i].x * points[i].x;
|
|
t2 += points[i].x;
|
|
t3 += points[i].x * points[i].y;
|
|
t4 += points[i].y;
|
|
}
|
|
b = (t3 * nSize - t2 * t4) / (t1 * nSize - t2 * t2);
|
|
a = (t1 * t4 - t2 * t3) / (t1 * nSize - t2 * t2);
|
|
|
|
for (int i = 0; i < points.size(); i++) {
|
|
float r = points.at(i).x * b + a;
|
|
float r2 = points.at(i).y;
|
|
int aaaa = 1;
|
|
}
|
|
return true;
|
|
}
|