ClassFlowAlignment.cpp 4.7 KB

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