|
|
@@ -17,6 +17,7 @@ ClassFlowCNNGeneral::ClassFlowCNNGeneral(ClassFlowAlignment *_flowalign, t_CNNTy
|
|
|
string cnnmodelfile = "";
|
|
|
modelxsize = 1;
|
|
|
modelysize = 1;
|
|
|
+ CNNGoodThreshold = 0.9;
|
|
|
ListFlowControll = NULL;
|
|
|
previousElement = NULL;
|
|
|
SaveAllFiles = false;
|
|
|
@@ -27,7 +28,7 @@ ClassFlowCNNGeneral::ClassFlowCNNGeneral(ClassFlowAlignment *_flowalign, t_CNNTy
|
|
|
flowpostalignment = _flowalign;
|
|
|
}
|
|
|
|
|
|
-string ClassFlowCNNGeneral::getReadout(int _analog = 0, bool _extendedResolution = false)
|
|
|
+string ClassFlowCNNGeneral::getReadout(int _analog = 0, bool _extendedResolution, int prev)
|
|
|
{
|
|
|
string result = "";
|
|
|
if (GENERAL[_analog]->ROI.size() == 0)
|
|
|
@@ -38,8 +39,6 @@ string ClassFlowCNNGeneral::getReadout(int _analog = 0, bool _extendedResolution
|
|
|
float zahl = GENERAL[_analog]->ROI[GENERAL[_analog]->ROI.size() - 1]->result_float;
|
|
|
int ergebnis_nachkomma = ((int) floor(zahl * 10) + 10) % 10;
|
|
|
|
|
|
- int prev = -1;
|
|
|
-
|
|
|
prev = ZeigerEval(GENERAL[_analog]->ROI[GENERAL[_analog]->ROI.size() - 1]->result_float, prev);
|
|
|
result = std::to_string(prev);
|
|
|
|
|
|
@@ -66,7 +65,51 @@ string ClassFlowCNNGeneral::getReadout(int _analog = 0, bool _extendedResolution
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- if (CNNType == DigitalHyprid)
|
|
|
+ if ((CNNType == DoubleHyprid10))
|
|
|
+ {
|
|
|
+ float zahl = GENERAL[_analog]->ROI[GENERAL[_analog]->ROI.size() - 1]->result_float;
|
|
|
+ if (zahl >= 0) // NaN?
|
|
|
+ {
|
|
|
+ if (_extendedResolution)
|
|
|
+ {
|
|
|
+ int ergebnis_nachkomma = ((int) floor(zahl * 10)) % 10;
|
|
|
+ int ergebnis_vorkomma = ((int) floor(zahl)) % 10;
|
|
|
+
|
|
|
+ result = std::to_string(ergebnis_vorkomma) + std::to_string(ergebnis_nachkomma);
|
|
|
+ prev = ergebnis_vorkomma;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ prev = ZeigerEval(GENERAL[_analog]->ROI[GENERAL[_analog]->ROI.size() - 1]->result_float, prev);
|
|
|
+// prev = ZeigerEvalHybrid(GENERAL[_analog]->ROI[GENERAL[_analog]->ROI.size() - 1]->result_float, prev, prev);
|
|
|
+ result = std::to_string(prev);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ result = "N";
|
|
|
+ if (_extendedResolution && (CNNType != Digital))
|
|
|
+ result = "NN";
|
|
|
+ }
|
|
|
+
|
|
|
+ for (int i = GENERAL[_analog]->ROI.size() - 2; i >= 0; --i)
|
|
|
+ {
|
|
|
+ if (GENERAL[_analog]->ROI[i]->result_float >= 0)
|
|
|
+ {
|
|
|
+ prev = ZeigerEvalHybrid(GENERAL[_analog]->ROI[i]->result_float, GENERAL[_analog]->ROI[i+1]->result_float, prev);
|
|
|
+ result = std::to_string(prev) + result;
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ prev = -1;
|
|
|
+ result = "N" + result;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ((CNNType == DigitalHyprid))
|
|
|
{
|
|
|
int zif_akt = -1;
|
|
|
|
|
|
@@ -110,6 +153,7 @@ string ClassFlowCNNGeneral::getReadout(int _analog = 0, bool _extendedResolution
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
@@ -153,6 +197,35 @@ int ClassFlowCNNGeneral::ZeigerEvalHybrid(float zahl, float zahl_vorgaenger, int
|
|
|
return ((int) trunc(zahl) + 10) % 10;
|
|
|
}
|
|
|
|
|
|
+/*
|
|
|
+int ClassFlowCNNGeneral::ZeigerEvalHybrid_NEU(float zahl, float zahl_vorgaenger)
|
|
|
+{
|
|
|
+ int ergebnis_nachkomma = ((int) floor(zahl * 10) + 10) % 10;
|
|
|
+ int ergebnis_vorkomma = ((int) floor(zahl) + 10) % 10;
|
|
|
+ int ergebnis, ergebnis_rating;
|
|
|
+
|
|
|
+
|
|
|
+ if (zahl_vorgaenger < 0)
|
|
|
+ return ergebnis_vorkomma % 10;
|
|
|
+
|
|
|
+ ergebnis_rating = ergebnis_nachkomma - zahl_vorgaenger;
|
|
|
+ if (ergebnis_nachkomma >= 5)
|
|
|
+ ergebnis_rating-=5;
|
|
|
+ else
|
|
|
+ ergebnis_rating+=5;
|
|
|
+ ergebnis = (int) round(zahl);
|
|
|
+ if (ergebnis_rating < 0)
|
|
|
+ ergebnis-=1;
|
|
|
+ if (ergebnis == -1)
|
|
|
+ ergebnis+=10;
|
|
|
+
|
|
|
+ ergebnis = (ergebnis + 10) % 10;
|
|
|
+ return ergebnis;
|
|
|
+
|
|
|
+}
|
|
|
+*/
|
|
|
+
|
|
|
+
|
|
|
int ClassFlowCNNGeneral::ZeigerEval(float zahl, int ziffer_vorgaenger)
|
|
|
{
|
|
|
int ergebnis_nachkomma = ((int) floor(zahl * 10) + 10) % 10;
|
|
|
@@ -206,12 +279,12 @@ bool ClassFlowCNNGeneral::ReadParameter(FILE* pfile, string& aktparamgraph)
|
|
|
while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph))
|
|
|
{
|
|
|
zerlegt = this->ZerlegeZeile(aktparamgraph);
|
|
|
- if ((zerlegt[0] == "LogImageLocation") && (zerlegt.size() > 1))
|
|
|
+ if ((toUpper(zerlegt[0]) == "LOGIMAGELOCATION") && (zerlegt.size() > 1))
|
|
|
{
|
|
|
this->LogImageLocation = "/sdcard" + zerlegt[1];
|
|
|
this->isLogImage = true;
|
|
|
}
|
|
|
- if ((zerlegt[0] == "LogImageSelect") && (zerlegt.size() > 1))
|
|
|
+ if ((toUpper(zerlegt[0]) == "LOGIMAGESELECT") && (zerlegt.size() > 1))
|
|
|
{
|
|
|
LogImageSelect = zerlegt[1];
|
|
|
isLogImageSelect = true;
|
|
|
@@ -227,11 +300,16 @@ bool ClassFlowCNNGeneral::ReadParameter(FILE* pfile, string& aktparamgraph)
|
|
|
CNNType = DigitalHyprid;
|
|
|
}
|
|
|
|
|
|
- if ((zerlegt[0] == "Model") && (zerlegt.size() > 1))
|
|
|
+ if ((toUpper(zerlegt[0]) == "MODEL") && (zerlegt.size() > 1))
|
|
|
{
|
|
|
this->cnnmodelfile = zerlegt[1];
|
|
|
}
|
|
|
- if ((zerlegt[0] == "ModelInputSize") && (zerlegt.size() > 2))
|
|
|
+
|
|
|
+ if ((toUpper(zerlegt[0]) == "CNNGOODTHRESHOLD") && (zerlegt.size() > 1))
|
|
|
+ {
|
|
|
+ CNNGoodThreshold = std::stof(zerlegt[1]);
|
|
|
+ }
|
|
|
+ if ((toUpper(zerlegt[0]) == "MODELINPUTSIZE") && (zerlegt.size() > 2))
|
|
|
{
|
|
|
this->modelxsize = std::stoi(zerlegt[1]);
|
|
|
this->modelysize = std::stoi(zerlegt[2]);
|
|
|
@@ -408,7 +486,6 @@ void ClassFlowCNNGeneral::DrawROI(CImageBasis *_zw)
|
|
|
for (int i = 0; i < GENERAL[_ana]->ROI.size(); ++i)
|
|
|
{
|
|
|
_zw->drawRect(GENERAL[_ana]->ROI[i]->posx, GENERAL[_ana]->ROI[i]->posy, GENERAL[_ana]->ROI[i]->deltax, GENERAL[_ana]->ROI[i]->deltay, r, g, b, 1);
|
|
|
-// _zw->drawCircle((int) (GENERAL[_ana]->ROI[i]->posx + GENERAL[_ana]->ROI[i]->deltax/2), (int) (GENERAL[_ana]->ROI[i]->posy + GENERAL[_ana]->ROI[i]->deltay/2), (int) (GENERAL[_ana]->ROI[i]->deltax/2), r, g, b, 2);
|
|
|
_zw->drawEllipse( (int) (GENERAL[_ana]->ROI[i]->posx + GENERAL[_ana]->ROI[i]->deltax/2), (int) (GENERAL[_ana]->ROI[i]->posy + GENERAL[_ana]->ROI[i]->deltay/2), (int) (GENERAL[_ana]->ROI[i]->deltax/2), (int) (GENERAL[_ana]->ROI[i]->deltay/2), r, g, b, 2);
|
|
|
_zw->drawLine((int) (GENERAL[_ana]->ROI[i]->posx + GENERAL[_ana]->ROI[i]->deltax/2), (int) GENERAL[_ana]->ROI[i]->posy, (int) (GENERAL[_ana]->ROI[i]->posx + GENERAL[_ana]->ROI[i]->deltax/2), (int) (GENERAL[_ana]->ROI[i]->posy + GENERAL[_ana]->ROI[i]->deltay), r, g, b, 2);
|
|
|
_zw->drawLine((int) GENERAL[_ana]->ROI[i]->posx, (int) (GENERAL[_ana]->ROI[i]->posy + GENERAL[_ana]->ROI[i]->deltay/2), (int) GENERAL[_ana]->ROI[i]->posx + GENERAL[_ana]->ROI[i]->deltax, (int) (GENERAL[_ana]->ROI[i]->posy + GENERAL[_ana]->ROI[i]->deltay/2), r, g, b, 2);
|
|
|
@@ -451,6 +528,10 @@ bool ClassFlowCNNGeneral::doNeuralNetwork(string time)
|
|
|
CNNType = Analogue;
|
|
|
printf("TFlite-Type set to Analogue\n");
|
|
|
break;
|
|
|
+ case 10:
|
|
|
+ CNNType = DoubleHyprid10;
|
|
|
+ printf("TFlite-Type set to DoubleHyprid10\n");
|
|
|
+ break;
|
|
|
case 11:
|
|
|
CNNType = Digital;
|
|
|
printf("TFlite-Type set to Digital\n");
|
|
|
@@ -562,6 +643,62 @@ bool ClassFlowCNNGeneral::doNeuralNetwork(string time)
|
|
|
if (isLogImage)
|
|
|
LogImage(logPath, GENERAL[_ana]->ROI[i]->name, &GENERAL[_ana]->ROI[i]->result_float, NULL, time, GENERAL[_ana]->ROI[i]->image_org);
|
|
|
} break;
|
|
|
+
|
|
|
+ case DoubleHyprid10:
|
|
|
+ {
|
|
|
+ int _num, _numplus, _numminus;
|
|
|
+ float _val, _valplus, _valminus;
|
|
|
+ float _fit;
|
|
|
+
|
|
|
+ tflite->LoadInputImageBasis(GENERAL[_ana]->ROI[i]->image);
|
|
|
+ tflite->Invoke();
|
|
|
+ if (debugdetailgeneral) LogFile.WriteToFile("Nach Invoke");
|
|
|
+
|
|
|
+ _num = tflite->GetOutClassification(0, 9);
|
|
|
+ _numplus = (_num + 1) % 10;
|
|
|
+ _numminus = (_num - 1) % 10;
|
|
|
+
|
|
|
+ _val = tflite->GetOutputValue(_num);
|
|
|
+ _valplus = tflite->GetOutputValue(_numplus);
|
|
|
+ _valminus = tflite->GetOutputValue(_numminus);
|
|
|
+
|
|
|
+ float result = _num;
|
|
|
+
|
|
|
+ if (_valplus > _numminus)
|
|
|
+ {
|
|
|
+ result = result + _valplus / (_valplus + _val);
|
|
|
+ _fit = _val + _valplus;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ result = result - _valminus / (_val + _valminus);
|
|
|
+ _fit = _val + _valminus;
|
|
|
+
|
|
|
+ }
|
|
|
+ if (result > 10)
|
|
|
+ result = result - 10;
|
|
|
+ if (result < 0)
|
|
|
+ result = result + 10;
|
|
|
+
|
|
|
+ if (_fit < CNNGoodThreshold)
|
|
|
+ {
|
|
|
+ GENERAL[_ana]->ROI[i]->isReject = true;
|
|
|
+ result = -1;
|
|
|
+ string zw = "Value Rejected due to Threshold (Fit: " + to_string(_fit) + "Threshold: " + to_string(CNNGoodThreshold);
|
|
|
+ printf("Value Rejected due to Threshold (Fit: %f, Threshold: %f\n", _fit, CNNGoodThreshold);
|
|
|
+ LogFile.WriteToFile(zw);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ GENERAL[_ana]->ROI[i]->isReject = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ GENERAL[_ana]->ROI[i]->result_float = result;
|
|
|
+ printf("Result General(Analog)%i: %f\n", i, GENERAL[_ana]->ROI[i]->result_float);
|
|
|
+
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
default:
|
|
|
break;
|
|
|
}
|