ClassFlowAlignment.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. #include "ClassFlowAlignment.h"
  2. #include "ClassLogFile.h"
  3. ClassFlowAlignment::ClassFlowAlignment()
  4. {
  5. initalrotate = 0;
  6. anz_ref = 0;
  7. suchex = 40;
  8. suchey = 40;
  9. initialmirror = false;
  10. namerawimage = "/sdcard/img_tmp/raw.jpg";
  11. ListFlowControll = NULL;
  12. }
  13. ClassFlowAlignment::ClassFlowAlignment(std::vector<ClassFlow*>* lfc)
  14. {
  15. initalrotate = 0;
  16. anz_ref = 0;
  17. suchex = 40;
  18. suchey = 40;
  19. initialmirror = false;
  20. namerawimage = "/sdcard/img_tmp/raw.jpg";
  21. ListFlowControll = lfc;
  22. }
  23. bool ClassFlowAlignment::ReadParameter(FILE* pfile, string& aktparamgraph)
  24. {
  25. std::vector<string> zerlegt;
  26. aktparamgraph = trim(aktparamgraph);
  27. if (aktparamgraph.size() == 0)
  28. if (!this->GetNextParagraph(pfile, aktparamgraph))
  29. return false;
  30. if (aktparamgraph.compare("[Alignment]") != 0) // Paragraph passt nich zu MakeImage
  31. return false;
  32. while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph))
  33. {
  34. zerlegt = this->ZerlegeZeile(aktparamgraph);
  35. if ((zerlegt[0] == "InitialMirror") && (zerlegt.size() > 1))
  36. {
  37. if (toUpper(zerlegt[1]) == "TRUE")
  38. initialmirror = true;
  39. }
  40. if (((zerlegt[0] == "InitalRotate") || (zerlegt[0] == "InitialRotate")) && (zerlegt.size() > 1))
  41. {
  42. this->initalrotate = std::stod(zerlegt[1]);
  43. }
  44. if ((zerlegt[0] == "SearchFieldX") && (zerlegt.size() > 1))
  45. {
  46. this->suchex = std::stod(zerlegt[1]);
  47. }
  48. if ((zerlegt[0] == "SearchFieldY") && (zerlegt.size() > 1))
  49. {
  50. this->suchey = std::stod(zerlegt[1]);
  51. }
  52. if ((zerlegt.size() == 3) && (anz_ref < 2))
  53. {
  54. this->reffilename[anz_ref] = FormatFileName("/sdcard" + zerlegt[0]);
  55. this->ref_x[anz_ref] = std::stod(zerlegt[1]);
  56. this->ref_y[anz_ref] = std::stod(zerlegt[2]);
  57. anz_ref++;
  58. }
  59. }
  60. return true;
  61. }
  62. string ClassFlowAlignment::getHTMLSingleStep(string host)
  63. {
  64. string result;
  65. result = "<p>Rotated Image: </p> <p><img src=\"" + host + "/img_tmp/rot.jpg\"></p>\n";
  66. result = result + "<p>Found Alignment: </p> <p><img src=\"" + host + "/img_tmp/rot_roi.jpg\"></p>\n";
  67. result = result + "<p>Aligned Image: </p> <p><img src=\"" + host + "/img_tmp/alg.jpg\"></p>\n";
  68. return result;
  69. }
  70. bool ClassFlowAlignment::doFlow(string time)
  71. {
  72. string input = namerawimage;
  73. string output = "/sdcard/img_tmp/rot.jpg";
  74. string output3 = "/sdcard/img_tmp/rot_roi.jpg";
  75. string output2 = "/sdcard/img_tmp/alg.jpg";
  76. string output4 = "/sdcard/img_tmp/alg_roi.jpg";
  77. string output1 = "/sdcard/img_tmp/mirror.jpg";
  78. input = FormatFileName(input);
  79. output = FormatFileName(output);
  80. output2 = FormatFileName(output2);
  81. if (initialmirror){
  82. CRotate *rt;
  83. rt = new CRotate(input);
  84. if (!rt->ImageOkay()){
  85. LogFile.WriteToFile("ClassFlowAlignment::doFlow CRotate Inital Mirror raw.jpg not okay!");
  86. delete rt;
  87. return false;
  88. }
  89. printf("do mirror\n");
  90. rt->Mirror();
  91. rt->SaveToFile(output1);
  92. input = output1;
  93. delete rt;
  94. }
  95. if (initalrotate != 0)
  96. {
  97. CRotate *rt = NULL;
  98. printf("Load rotationfile: %s\n", input.c_str());
  99. rt = new CRotate(input);
  100. if (!rt->ImageOkay()){
  101. LogFile.WriteToFile("ClassFlowAlignment::doFlow CRotate raw.jpg not okay!");
  102. delete rt;
  103. return false;
  104. }
  105. rt->Rotate(this->initalrotate);
  106. rt->SaveToFile(output);
  107. delete rt;
  108. }
  109. else
  110. {
  111. CopyFile(input, output);
  112. }
  113. CAlignAndCutImage *caic;
  114. caic = new CAlignAndCutImage(output);
  115. caic->Align(this->reffilename[0], this->ref_x[0], this->ref_y[0], this->reffilename[1], this->ref_x[1], this->ref_y[1], suchex, suchey, output3);
  116. caic->SaveToFile(output2);
  117. printf("Startwriting Output4:%s\n", output4.c_str());
  118. if (output4.length() > 0)
  119. {
  120. caic->drawRect(ref_x[0], ref_y[0], caic->t0_dx, caic->t0_dy, 255, 0, 0, 2);
  121. caic->drawRect(ref_x[1], ref_y[1], caic->t1_dx, caic->t1_dy, 255, 0, 0, 2);
  122. caic->SaveToFile(output4);
  123. printf("Write output4: %s\n", output4.c_str());
  124. }
  125. delete caic;
  126. // Align mit Templates
  127. return true;
  128. }