ClassFlowAlignment.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. #include "ClassFlowAlignment.h"
  2. #include "ClassFlowMakeImage.h"
  3. #include "ClassFlow.h"
  4. #include "CRotateImage.h"
  5. #include "ClassLogFile.h"
  6. bool AlignmentExtendedDebugging = true;
  7. void ClassFlowAlignment::SetInitialParameter(void)
  8. {
  9. initalrotate = 0;
  10. anz_ref = 0;
  11. suchex = 40;
  12. suchey = 40;
  13. initialmirror = false;
  14. SaveAllFiles = false;
  15. namerawimage = "/sdcard/img_tmp/raw.jpg";
  16. ListFlowControll = NULL;
  17. AlignAndCutImage = NULL;
  18. ImageBasis = NULL;
  19. ImageTMP = NULL;
  20. previousElement = NULL;
  21. ref_dx[0] = 0; ref_dx[1] = 0;
  22. ref_dy[0] = 0; ref_dy[1] = 0;
  23. }
  24. ClassFlowAlignment::ClassFlowAlignment(std::vector<ClassFlow*>* lfc)
  25. {
  26. SetInitialParameter();
  27. ListFlowControll = lfc;
  28. for (int i = 0; i < ListFlowControll->size(); ++i)
  29. {
  30. if (((*ListFlowControll)[i])->name().compare("ClassFlowMakeImage") == 0)
  31. {
  32. ImageBasis = ((ClassFlowMakeImage*) (*ListFlowControll)[i])->rawImage;
  33. }
  34. }
  35. if (!ImageBasis) // die Funktion Bilder aufnehmen existiert nicht --> muss erst erzeugt werden NUR ZU TESTZWECKEN
  36. {
  37. if (AlignmentExtendedDebugging) printf("CImageBasis musste erzeugt werden\n");
  38. ImageBasis = new CImageBasis(namerawimage);
  39. }
  40. }
  41. bool ClassFlowAlignment::ReadParameter(FILE* pfile, string& aktparamgraph)
  42. {
  43. std::vector<string> zerlegt;
  44. aktparamgraph = trim(aktparamgraph);
  45. if (aktparamgraph.size() == 0)
  46. if (!this->GetNextParagraph(pfile, aktparamgraph))
  47. return false;
  48. if (aktparamgraph.compare("[Alignment]") != 0) // Paragraph passt nich zu MakeImage
  49. return false;
  50. while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph))
  51. {
  52. zerlegt = this->ZerlegeZeile(aktparamgraph);
  53. if ((zerlegt[0] == "InitialMirror") && (zerlegt.size() > 1))
  54. {
  55. if (toUpper(zerlegt[1]) == "TRUE")
  56. initialmirror = true;
  57. }
  58. if (((zerlegt[0] == "InitalRotate") || (zerlegt[0] == "InitialRotate")) && (zerlegt.size() > 1))
  59. {
  60. this->initalrotate = std::stod(zerlegt[1]);
  61. }
  62. if ((zerlegt[0] == "SearchFieldX") && (zerlegt.size() > 1))
  63. {
  64. this->suchex = std::stod(zerlegt[1]);
  65. }
  66. if ((zerlegt[0] == "SearchFieldY") && (zerlegt.size() > 1))
  67. {
  68. this->suchey = std::stod(zerlegt[1]);
  69. }
  70. if ((zerlegt.size() == 3) && (anz_ref < 2))
  71. {
  72. reffilename[anz_ref] = FormatFileName("/sdcard" + zerlegt[0]);
  73. ref_x[anz_ref] = std::stod(zerlegt[1]);
  74. ref_y[anz_ref] = std::stod(zerlegt[2]);
  75. anz_ref++;
  76. }
  77. if ((toUpper(zerlegt[0]) == "SAVEALLFILES") && (zerlegt.size() > 1))
  78. {
  79. if (toUpper(zerlegt[1]) == "TRUE")
  80. SaveAllFiles = true;
  81. }
  82. }
  83. return true;
  84. }
  85. string ClassFlowAlignment::getHTMLSingleStep(string host)
  86. {
  87. string result;
  88. result = "<p>Rotated Image: </p> <p><img src=\"" + host + "/img_tmp/rot.jpg\"></p>\n";
  89. result = result + "<p>Found Alignment: </p> <p><img src=\"" + host + "/img_tmp/rot_roi.jpg\"></p>\n";
  90. result = result + "<p>Aligned Image: </p> <p><img src=\"" + host + "/img_tmp/alg.jpg\"></p>\n";
  91. return result;
  92. }
  93. bool ClassFlowAlignment::doFlow(string time)
  94. {
  95. if (!ImageTMP)
  96. ImageTMP = new CImageBasis(ImageBasis);
  97. if (AlignAndCutImage)
  98. delete AlignAndCutImage;
  99. AlignAndCutImage = new CAlignAndCutImage(ImageBasis, ImageTMP);
  100. CRotateImage rt(AlignAndCutImage, ImageTMP);
  101. if (initialmirror){
  102. printf("do mirror\n");
  103. rt.Mirror();
  104. if (SaveAllFiles) AlignAndCutImage->SaveToFile(FormatFileName("/sdcard/img_tmp/mirror.jpg"));
  105. }
  106. if (initalrotate != 0)
  107. {
  108. rt.Rotate(initalrotate);
  109. if (SaveAllFiles) AlignAndCutImage->SaveToFile(FormatFileName("/sdcard/img_tmp/rot.jpg"));
  110. }
  111. AlignAndCutImage->Align(reffilename[0], ref_x[0], ref_y[0], reffilename[1], ref_x[1], ref_y[1], suchex, suchey, "");
  112. AlignAndCutImage->GetRefSize(ref_dx, ref_dy);
  113. if (SaveAllFiles) AlignAndCutImage->SaveToFile(FormatFileName("/sdcard/img_tmp/alg.jpg"));
  114. if (SaveAllFiles)
  115. {
  116. DrawRef(ImageTMP);
  117. ImageTMP->SaveToFile(FormatFileName("/sdcard/img_tmp/alg_roi.jpg"));
  118. }
  119. if (ImageTMP) // nuss gelöscht werden, um Speicherplatz für das Laden von tflite zu haben
  120. {
  121. delete ImageTMP;
  122. ImageTMP = NULL;
  123. }
  124. return true;
  125. }
  126. void ClassFlowAlignment::DrawRef(CImageBasis *_zw)
  127. {
  128. _zw->drawRect(ref_x[0], ref_y[0], ref_dx[0], ref_dy[0], 255, 0, 0, 2);
  129. _zw->drawRect(ref_x[1], ref_y[1], ref_dx[1], ref_dy[1], 255, 0, 0, 2);
  130. }