ClassFlowCNNGeneral.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  1. #include "ClassFlowCNNGeneral.h"
  2. #include <math.h>
  3. #include <iomanip>
  4. #include <sys/types.h>
  5. #include <sstream> // std::stringstream
  6. #include "CTfLiteClass.h"
  7. #include "ClassLogFile.h"
  8. static const char* TAG = "flow_analog";
  9. bool debugdetailgeneral = false;
  10. ClassFlowCNNGeneral::ClassFlowCNNGeneral(ClassFlowAlignment *_flowalign, t_CNNType _cnntype) : ClassFlowImage(NULL, TAG)
  11. {
  12. string cnnmodelfile = "";
  13. modelxsize = 1;
  14. modelysize = 1;
  15. ListFlowControll = NULL;
  16. previousElement = NULL;
  17. SaveAllFiles = false;
  18. disabled = false;
  19. extendedResolution = false;
  20. isLogImageSelect = false;
  21. CNNType = AutoDetect;
  22. CNNType = _cnntype;
  23. flowpostalignment = _flowalign;
  24. }
  25. int ClassFlowCNNGeneral::AnzahlROIs(int _analog = 0)
  26. {
  27. int zw = GENERAL[_analog]->ROI.size();
  28. if (extendedResolution && (CNNType != Digital)) zw++; // da letzte Ziffer inkl Nachhkomma, es sei denn, das Nachkomma gibt es nicht (Digital)
  29. return zw;
  30. }
  31. string ClassFlowCNNGeneral::getReadout(int _analog = 0)
  32. {
  33. string result = "";
  34. if (GENERAL[_analog]->ROI.size() == 0)
  35. return result;
  36. if (CNNType == Analogue)
  37. {
  38. float zahl = GENERAL[_analog]->ROI[GENERAL[_analog]->ROI.size() - 1]->result;
  39. int ergebnis_nachkomma = ((int) floor(zahl * 10)) % 10;
  40. int prev = -1;
  41. prev = ZeigerEval(GENERAL[_analog]->ROI[GENERAL[_analog]->ROI.size() - 1]->result, prev);
  42. result = std::to_string(prev);
  43. if (extendedResolution && (CNNType != Digital))
  44. result = result + std::to_string(ergebnis_nachkomma);
  45. for (int i = GENERAL[_analog]->ROI.size() - 2; i >= 0; --i)
  46. {
  47. prev = ZeigerEval(GENERAL[_analog]->ROI[i]->result, prev);
  48. result = std::to_string(prev) + result;
  49. }
  50. }
  51. if (CNNType == Digital)
  52. {
  53. for (int i = 0; i < GENERAL[_analog]->ROI.size(); ++i)
  54. {
  55. if (GENERAL[_analog]->ROI[i]->resultklasse == 10)
  56. result = result + "N";
  57. else
  58. result = result + std::to_string(GENERAL[_analog]->ROI[i]->resultklasse);
  59. }
  60. }
  61. if (CNNType == DigitalHyprid)
  62. {
  63. // int ergebnis_nachkomma = -1;
  64. int zif_akt = -1;
  65. float zahl = GENERAL[_analog]->ROI[GENERAL[_analog]->ROI.size() - 1]->result;
  66. if (zahl >= 0) // NaN?
  67. {
  68. if (extendedResolution)
  69. {
  70. int ergebnis_nachkomma = ((int) floor(zahl * 10)) % 10;
  71. int ergebnis_vorkomma = ((int) floor(zahl)) % 10;
  72. result = std::to_string(ergebnis_vorkomma) + std::to_string(ergebnis_nachkomma);
  73. }
  74. else
  75. {
  76. zif_akt = ZeigerEvalHybrid(GENERAL[_analog]->ROI[GENERAL[_analog]->ROI.size() - 1]->result, -1, -1);
  77. result = std::to_string(zif_akt);
  78. }
  79. }
  80. else
  81. {
  82. result = "N";
  83. if (extendedResolution && (CNNType != Digital))
  84. result = "NN";
  85. }
  86. for (int i = GENERAL[_analog]->ROI.size() - 2; i >= 0; --i)
  87. {
  88. if (GENERAL[_analog]->ROI[i]->result >= 0)
  89. {
  90. zif_akt = ZeigerEvalHybrid(GENERAL[_analog]->ROI[i]->result, GENERAL[_analog]->ROI[i+1]->result, zif_akt);
  91. result = std::to_string(zif_akt) + result;
  92. }
  93. else
  94. {
  95. zif_akt = -1;
  96. result = "N" + result;
  97. }
  98. }
  99. }
  100. return result;
  101. }
  102. int ClassFlowCNNGeneral::ZeigerEvalHybrid(float zahl, float zahl_vorgaenger, int eval_vorgaenger)
  103. {
  104. int ergebnis_nachkomma = ((int) floor(zahl * 10)) % 10;
  105. // int ergebnis_vorkomma = ((int) floor(zahl)) % 10;
  106. if (zahl_vorgaenger < 0) // keine Vorzahl vorhanden !!! --> Runde die Zahl
  107. {
  108. if ((ergebnis_nachkomma <= 2) || (ergebnis_nachkomma >= 8)) // Band um die Ziffer --> Runden, da Ziffer im Rahmen Ungenauigkeit erreicht
  109. return (int) round(zahl);
  110. else
  111. return (int) trunc(zahl);
  112. }
  113. if (zahl_vorgaenger > 9.2) // Ziffernwechsel beginnt
  114. {
  115. if (eval_vorgaenger == 0) // Wechsel hat schon stattgefunden
  116. {
  117. return (int) round(zahl); // Annahme, dass die neue Zahl schon in der Nähe des Ziels ist
  118. }
  119. else
  120. {
  121. if (zahl_vorgaenger <= 9.5) // Wechsel startet gerade, aber beginnt erst
  122. {
  123. if ((ergebnis_nachkomma <= 2) || (ergebnis_nachkomma >= 8)) // Band um die Ziffer --> Runden, da Ziffer im Rahmen Ungenauigkeit erreicht
  124. return (int) round(zahl);
  125. else
  126. return (int) trunc(zahl);
  127. }
  128. else
  129. {
  130. return (int) trunc(zahl); // Wechsel schon weiter fortgeschritten, d.h. über 2 als Nachkomma
  131. }
  132. }
  133. }
  134. if ((ergebnis_nachkomma <= 2) || (ergebnis_nachkomma >= 8)) // Band um die Ziffer --> Runden, da Ziffer im Rahmen Ungenauigkeit erreicht
  135. return (int) round(zahl);
  136. return (int) trunc(zahl);
  137. }
  138. int ClassFlowCNNGeneral::ZeigerEval(float zahl, int ziffer_vorgaenger)
  139. {
  140. int ergebnis_nachkomma = ((int) floor(zahl * 10)) % 10;
  141. int ergebnis_vorkomma = ((int) floor(zahl)) % 10;
  142. int ergebnis, ergebnis_rating;
  143. if (ziffer_vorgaenger == -1)
  144. return ergebnis_vorkomma % 10;
  145. ergebnis_rating = ergebnis_nachkomma - ziffer_vorgaenger;
  146. if (ergebnis_nachkomma >= 5)
  147. ergebnis_rating-=5;
  148. else
  149. ergebnis_rating+=5;
  150. ergebnis = (int) round(zahl);
  151. if (ergebnis_rating < 0)
  152. ergebnis-=1;
  153. if (ergebnis == -1)
  154. ergebnis+=10;
  155. ergebnis = ergebnis % 10;
  156. return ergebnis;
  157. }
  158. bool ClassFlowCNNGeneral::ReadParameter(FILE* pfile, string& aktparamgraph)
  159. {
  160. std::vector<string> zerlegt;
  161. aktparamgraph = trim(aktparamgraph);
  162. if (aktparamgraph.size() == 0)
  163. if (!this->GetNextParagraph(pfile, aktparamgraph))
  164. return false;
  165. if ((toUpper(aktparamgraph) != "[ANALOG]") && (toUpper(aktparamgraph) != ";[ANALOG]")
  166. && (toUpper(aktparamgraph) != "[DIGIT]") && (toUpper(aktparamgraph) != ";[DIGIT]")
  167. && (toUpper(aktparamgraph) != "[DIGITS]") && (toUpper(aktparamgraph) != ";[DIGITS]")
  168. ) // Paragraph passt nicht
  169. return false;
  170. /*
  171. if ((aktparamgraph.compare("[Analog]") != 0) && (aktparamgraph.compare(";[Analog]") != 0)
  172. && (aktparamgraph.compare("[Digit]") != 0) && (aktparamgraph.compare(";[Digit]"))) // Paragraph passt nicht
  173. return false;
  174. */
  175. if (aktparamgraph[0] == ';')
  176. {
  177. disabled = true;
  178. while (getNextLine(pfile, &aktparamgraph) && !isNewParagraph(aktparamgraph));
  179. printf("[Analog/Digit] is disabled !!!\n");
  180. return true;
  181. }
  182. while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph))
  183. {
  184. zerlegt = this->ZerlegeZeile(aktparamgraph);
  185. if ((zerlegt[0] == "LogImageLocation") && (zerlegt.size() > 1))
  186. {
  187. this->LogImageLocation = "/sdcard" + zerlegt[1];
  188. this->isLogImage = true;
  189. }
  190. if ((zerlegt[0] == "LogImageSelect") && (zerlegt.size() > 1))
  191. {
  192. LogImageSelect = zerlegt[1];
  193. isLogImageSelect = true;
  194. }
  195. if ((toUpper(zerlegt[0]) == "LOGFILERETENTIONINDAYS") && (zerlegt.size() > 1))
  196. {
  197. this->logfileRetentionInDays = std::stoi(zerlegt[1]);
  198. }
  199. if ((toUpper(zerlegt[0]) == "MODELTYPE") && (zerlegt.size() > 1))
  200. {
  201. if (toUpper(zerlegt[1]) == "DIGITHYPRID")
  202. CNNType = DigitalHyprid;
  203. }
  204. if ((zerlegt[0] == "Model") && (zerlegt.size() > 1))
  205. {
  206. this->cnnmodelfile = zerlegt[1];
  207. }
  208. if ((zerlegt[0] == "ModelInputSize") && (zerlegt.size() > 2))
  209. {
  210. this->modelxsize = std::stoi(zerlegt[1]);
  211. this->modelysize = std::stoi(zerlegt[2]);
  212. }
  213. if (zerlegt.size() >= 5)
  214. {
  215. general* _analog = GetGENERAL(zerlegt[0], true);
  216. roi* neuroi = _analog->ROI[_analog->ROI.size()-1];
  217. neuroi->posx = std::stoi(zerlegt[1]);
  218. neuroi->posy = std::stoi(zerlegt[2]);
  219. neuroi->deltax = std::stoi(zerlegt[3]);
  220. neuroi->deltay = std::stoi(zerlegt[4]);
  221. neuroi->result = -1;
  222. neuroi->image = NULL;
  223. neuroi->image_org = NULL;
  224. }
  225. if ((toUpper(zerlegt[0]) == "SAVEALLFILES") && (zerlegt.size() > 1))
  226. {
  227. if (toUpper(zerlegt[1]) == "TRUE")
  228. SaveAllFiles = true;
  229. }
  230. if ((toUpper(zerlegt[0]) == "EXTENDEDRESOLUTION") && (zerlegt.size() > 1))
  231. {
  232. if (toUpper(zerlegt[1]) == "TRUE")
  233. extendedResolution = true;
  234. }
  235. }
  236. for (int _ana = 0; _ana < GENERAL.size(); ++_ana)
  237. for (int i = 0; i < GENERAL[_ana]->ROI.size(); ++i)
  238. {
  239. GENERAL[_ana]->ROI[i]->image = new CImageBasis(modelxsize, modelysize, 3);
  240. GENERAL[_ana]->ROI[i]->image_org = new CImageBasis(GENERAL[_ana]->ROI[i]->deltax, GENERAL[_ana]->ROI[i]->deltay, 3);
  241. }
  242. return true;
  243. }
  244. general* ClassFlowCNNGeneral::FindGENERAL(string _name_number)
  245. {
  246. for (int i = 0; i < GENERAL.size(); ++i)
  247. if (GENERAL[i]->name == _name_number)
  248. return GENERAL[i];
  249. return NULL;
  250. }
  251. general* ClassFlowCNNGeneral::GetGENERAL(string _name, bool _create = true)
  252. {
  253. string _analog, _roi;
  254. int _pospunkt = _name.find_first_of(".");
  255. if (_pospunkt > -1)
  256. {
  257. _analog = _name.substr(0, _pospunkt);
  258. _roi = _name.substr(_pospunkt+1, _name.length() - _pospunkt - 1);
  259. }
  260. else
  261. {
  262. _analog = "default";
  263. _roi = _name;
  264. }
  265. general *_ret = NULL;
  266. for (int i = 0; i < GENERAL.size(); ++i)
  267. if (GENERAL[i]->name == _analog)
  268. _ret = GENERAL[i];
  269. if (!_create) // nicht gefunden und soll auch nicht erzeugt werden
  270. return _ret;
  271. if (_ret == NULL)
  272. {
  273. _ret = new general;
  274. _ret->name = _analog;
  275. GENERAL.push_back(_ret);
  276. }
  277. roi* neuroi = new roi;
  278. neuroi->name = _roi;
  279. _ret->ROI.push_back(neuroi);
  280. printf("GetGENERAL - GENERAL %s - roi %s\n", _analog.c_str(), _roi.c_str());
  281. return _ret;
  282. }
  283. string ClassFlowCNNGeneral::getHTMLSingleStep(string host)
  284. {
  285. string result, zw;
  286. std::vector<HTMLInfo*> htmlinfo;
  287. result = "<p>Found ROIs: </p> <p><img src=\"" + host + "/img_tmp/alg_roi.jpg\"></p>\n";
  288. result = result + "Analog Pointers: <p> ";
  289. htmlinfo = GetHTMLInfo();
  290. for (int i = 0; i < htmlinfo.size(); ++i)
  291. {
  292. std::stringstream stream;
  293. stream << std::fixed << std::setprecision(1) << htmlinfo[i]->val;
  294. zw = stream.str();
  295. result = result + "<img src=\"" + host + "/img_tmp/" + htmlinfo[i]->filename + "\"> " + zw;
  296. delete htmlinfo[i];
  297. }
  298. htmlinfo.clear();
  299. return result;
  300. }
  301. bool ClassFlowCNNGeneral::doFlow(string time)
  302. {
  303. if (disabled)
  304. return true;
  305. if (!doAlignAndCut(time)){
  306. return false;
  307. };
  308. if (debugdetailgeneral) LogFile.WriteToFile("ClassFlowCNNGeneral::doFlow nach Alignment");
  309. doNeuralNetwork(time);
  310. RemoveOldLogs();
  311. return true;
  312. }
  313. bool ClassFlowCNNGeneral::doAlignAndCut(string time)
  314. {
  315. if (disabled)
  316. return true;
  317. CAlignAndCutImage *caic = flowpostalignment->GetAlignAndCutImage();
  318. for (int _ana = 0; _ana < GENERAL.size(); ++_ana)
  319. for (int i = 0; i < GENERAL[_ana]->ROI.size(); ++i)
  320. {
  321. printf("General %d - Align&Cut\n", i);
  322. caic->CutAndSave(GENERAL[_ana]->ROI[i]->posx, GENERAL[_ana]->ROI[i]->posy, GENERAL[_ana]->ROI[i]->deltax, GENERAL[_ana]->ROI[i]->deltay, GENERAL[_ana]->ROI[i]->image_org);
  323. if (SaveAllFiles)
  324. {
  325. if (GENERAL[_ana]->name == "default")
  326. GENERAL[_ana]->ROI[i]->image_org->SaveToFile(FormatFileName("/sdcard/img_tmp/" + GENERAL[_ana]->ROI[i]->name + ".jpg"));
  327. else
  328. GENERAL[_ana]->ROI[i]->image_org->SaveToFile(FormatFileName("/sdcard/img_tmp/" + GENERAL[_ana]->name + "_" + GENERAL[_ana]->ROI[i]->name + ".jpg"));
  329. }
  330. GENERAL[_ana]->ROI[i]->image_org->Resize(modelxsize, modelysize, GENERAL[_ana]->ROI[i]->image);
  331. if (SaveAllFiles)
  332. {
  333. if (GENERAL[_ana]->name == "default")
  334. GENERAL[_ana]->ROI[i]->image->SaveToFile(FormatFileName("/sdcard/img_tmp/" + GENERAL[_ana]->ROI[i]->name + ".bmp"));
  335. else
  336. GENERAL[_ana]->ROI[i]->image->SaveToFile(FormatFileName("/sdcard/img_tmp/" + GENERAL[_ana]->name + "_" + GENERAL[_ana]->ROI[i]->name + ".bmp"));
  337. }
  338. }
  339. return true;
  340. }
  341. void ClassFlowCNNGeneral::DrawROI(CImageBasis *_zw)
  342. {
  343. if (CNNType == Analogue)
  344. {
  345. int r = 0;
  346. int g = 255;
  347. int b = 0;
  348. for (int _ana = 0; _ana < GENERAL.size(); ++_ana)
  349. for (int i = 0; i < GENERAL[_ana]->ROI.size(); ++i)
  350. {
  351. _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);
  352. _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);
  353. _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);
  354. _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);
  355. }
  356. }
  357. else
  358. {
  359. for (int _dig = 0; _dig < GENERAL.size(); ++_dig)
  360. for (int i = 0; i < GENERAL[_dig]->ROI.size(); ++i)
  361. _zw->drawRect(GENERAL[_dig]->ROI[i]->posx, GENERAL[_dig]->ROI[i]->posy, GENERAL[_dig]->ROI[i]->deltax, GENERAL[_dig]->ROI[i]->deltay, 0, 0, (255 - _dig*100), 2);
  362. }
  363. }
  364. bool ClassFlowCNNGeneral::doNeuralNetwork(string time)
  365. {
  366. if (disabled)
  367. return true;
  368. string logPath = CreateLogFolder(time);
  369. CTfLiteClass *tflite = new CTfLiteClass;
  370. string zwcnn = "/sdcard" + cnnmodelfile;
  371. zwcnn = FormatFileName(zwcnn);
  372. printf(zwcnn.c_str());printf("\n");
  373. if (!tflite->LoadModel(zwcnn)) {
  374. printf("Can't read model file /sdcard%s\n", cnnmodelfile.c_str());
  375. LogFile.WriteToFile("Cannot load model");
  376. delete tflite;
  377. return false;
  378. }
  379. tflite->MakeAllocate();
  380. if (CNNType == AutoDetect)
  381. {
  382. int _anzoutputdimensions = tflite->GetAnzOutPut();
  383. switch (_anzoutputdimensions)
  384. {
  385. case 2:
  386. CNNType = Analogue;
  387. printf("TFlite-Type set to Analogue\n");
  388. break;
  389. case 11:
  390. CNNType = Digital;
  391. printf("TFlite-Type set to Digital\n");
  392. break;
  393. case 22:
  394. CNNType = DigitalHyprid;
  395. printf("TFlite-Type set to DigitalHyprid\n");
  396. break;
  397. default:
  398. printf("ERROR ERROR ERROR - tflite passt nicht zur Firmware - ERROR ERROR ERROR\n");
  399. }
  400. }
  401. for (int _ana = 0; _ana < GENERAL.size(); ++_ana)
  402. {
  403. for (int i = 0; i < GENERAL[_ana]->ROI.size(); ++i)
  404. {
  405. printf("General %d - TfLite\n", i);
  406. switch (CNNType) {
  407. case Analogue:
  408. {
  409. float f1, f2;
  410. f1 = 0; f2 = 0;
  411. tflite->LoadInputImageBasis(GENERAL[_ana]->ROI[i]->image);
  412. tflite->Invoke();
  413. if (debugdetailgeneral) LogFile.WriteToFile("Nach Invoke");
  414. f1 = tflite->GetOutputValue(0);
  415. f2 = tflite->GetOutputValue(1);
  416. float result = fmod(atan2(f1, f2) / (M_PI * 2) + 2, 1);
  417. GENERAL[_ana]->ROI[i]->result = result * 10;
  418. printf("Result General(Analog)%i: %f\n", i, GENERAL[_ana]->ROI[i]->result);
  419. if (isLogImage)
  420. LogImage(logPath, GENERAL[_ana]->ROI[i]->name, &GENERAL[_ana]->ROI[i]->result, NULL, time, GENERAL[_ana]->ROI[i]->image_org);
  421. } break;
  422. case Digital:
  423. {
  424. GENERAL[_ana]->ROI[i]->resultklasse = 0;
  425. GENERAL[_ana]->ROI[i]->resultklasse = tflite->GetClassFromImageBasis(GENERAL[_ana]->ROI[i]->image);
  426. printf("Result General(Digit)%i: %d\n", i, GENERAL[_ana]->ROI[i]->resultklasse);
  427. if (isLogImage)
  428. {
  429. if (isLogImageSelect)
  430. {
  431. if (LogImageSelect.find(GENERAL[_ana]->ROI[i]->name) != std::string::npos)
  432. LogImage(logPath, GENERAL[_ana]->ROI[i]->name, NULL, &GENERAL[_ana]->ROI[i]->resultklasse, time, GENERAL[_ana]->ROI[i]->image_org);
  433. }
  434. else
  435. {
  436. LogImage(logPath, GENERAL[_ana]->ROI[i]->name, NULL, &GENERAL[_ana]->ROI[i]->resultklasse, time, GENERAL[_ana]->ROI[i]->image_org);
  437. }
  438. }
  439. } break;
  440. case DigitalHyprid:
  441. {
  442. int _num, _nachkomma;
  443. tflite->LoadInputImageBasis(GENERAL[_ana]->ROI[i]->image);
  444. tflite->Invoke();
  445. if (debugdetailgeneral) LogFile.WriteToFile("Nach Invoke");
  446. _num = tflite->GetOutClassification(0, 10);
  447. _nachkomma = tflite->GetOutClassification(11, 22);
  448. string _zwres = "Nach Invoke - Nummer: " + to_string(_num) + " Nachkomma: " + to_string(_nachkomma);
  449. if (debugdetailgeneral) LogFile.WriteToFile(_zwres);
  450. if ((_num == 10) || (_nachkomma == 10)) // NaN detektiert
  451. GENERAL[_ana]->ROI[i]->result = -1;
  452. else
  453. GENERAL[_ana]->ROI[i]->result = fmod((double) _num + (((double)_nachkomma)-5)/10 + (double) 10, 10);
  454. printf("Result General(DigitalHyprid)%i: %f\n", i, GENERAL[_ana]->ROI[i]->result);
  455. _zwres = "Result General(DigitalHyprid)" + to_string(i) + ": " + to_string(GENERAL[_ana]->ROI[i]->result);
  456. if (debugdetailgeneral) LogFile.WriteToFile(_zwres);
  457. if (isLogImage)
  458. LogImage(logPath, GENERAL[_ana]->ROI[i]->name, &GENERAL[_ana]->ROI[i]->result, NULL, time, GENERAL[_ana]->ROI[i]->image_org);
  459. } break;
  460. default:
  461. break;
  462. }
  463. }
  464. }
  465. delete tflite;
  466. return true;
  467. }
  468. bool ClassFlowCNNGeneral::isExtendedResolution(int _number)
  469. {
  470. if (extendedResolution && !(CNNType == Digital))
  471. return true;
  472. return false;
  473. }
  474. std::vector<HTMLInfo*> ClassFlowCNNGeneral::GetHTMLInfo()
  475. {
  476. std::vector<HTMLInfo*> result;
  477. for (int _ana = 0; _ana < GENERAL.size(); ++_ana)
  478. for (int i = 0; i < GENERAL[_ana]->ROI.size(); ++i)
  479. {
  480. if (GENERAL[_ana]->name == "default")
  481. GENERAL[_ana]->ROI[i]->image->SaveToFile(FormatFileName("/sdcard/img_tmp/" + GENERAL[_ana]->ROI[i]->name + ".bmp"));
  482. else
  483. GENERAL[_ana]->ROI[i]->image->SaveToFile(FormatFileName("/sdcard/img_tmp/" + GENERAL[_ana]->name + "_" + GENERAL[_ana]->ROI[i]->name + ".bmp"));
  484. HTMLInfo *zw = new HTMLInfo;
  485. if (GENERAL[_ana]->name == "default")
  486. {
  487. zw->filename = GENERAL[_ana]->ROI[i]->name + ".bmp";
  488. zw->filename_org = GENERAL[_ana]->ROI[i]->name + ".jpg";
  489. }
  490. else
  491. {
  492. zw->filename = GENERAL[_ana]->name + "_" + GENERAL[_ana]->ROI[i]->name + ".bmp";
  493. zw->filename_org = GENERAL[_ana]->name + "_" + GENERAL[_ana]->ROI[i]->name + ".jpg";
  494. }
  495. if (CNNType == Analogue)
  496. zw->val = GENERAL[_ana]->ROI[i]->resultklasse;
  497. else
  498. zw->val = GENERAL[_ana]->ROI[i]->result;
  499. zw->image = GENERAL[_ana]->ROI[i]->image;
  500. zw->image_org = GENERAL[_ana]->ROI[i]->image_org;
  501. printf("Push %s\n", zw->filename.c_str());
  502. result.push_back(zw);
  503. }
  504. printf("größe: %d\n", result.size());
  505. return result;
  506. }
  507. int ClassFlowCNNGeneral::getAnzahlGENERAL()
  508. {
  509. return GENERAL.size();
  510. }
  511. string ClassFlowCNNGeneral::getNameGENERAL(int _analog)
  512. {
  513. if (_analog < GENERAL.size())
  514. return GENERAL[_analog]->name;
  515. return "GENERAL DOES NOT EXIST";
  516. }
  517. general* ClassFlowCNNGeneral::GetGENERAL(int _analog)
  518. {
  519. if (_analog < GENERAL.size())
  520. return GENERAL[_analog];
  521. return NULL;
  522. }
  523. void ClassFlowCNNGeneral::UpdateNameNumbers(std::vector<std::string> *_name_numbers)
  524. {
  525. for (int _dig = 0; _dig < GENERAL.size(); _dig++)
  526. {
  527. std::string _name = GENERAL[_dig]->name;
  528. bool found = false;
  529. for (int i = 0; i < (*_name_numbers).size(); ++i)
  530. {
  531. if ((*_name_numbers)[i] == _name)
  532. found = true;
  533. }
  534. if (!found)
  535. (*_name_numbers).push_back(_name);
  536. }
  537. }