ClassFlowAlignment.cpp 3.4 KB

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