ClassFlowAlignment.cpp 3.9 KB

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