ClassFlowAlignment.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. bool ClassFlowAlignment::doFlow(string time)
  55. {
  56. string input = namerawimage;
  57. string output = "/sdcard/img_tmp/rot.jpg";
  58. string output3 = "/sdcard/img_tmp/rot_roi.jpg";
  59. string output2 = "/sdcard/img_tmp/alg.jpg";
  60. string output4 = "/sdcard/img_tmp/alg_roi.jpg";
  61. input = FormatFileName(input);
  62. output = FormatFileName(output);
  63. output2 = FormatFileName(output2);
  64. CRotate *rt;
  65. if (initalrotate != 0)
  66. {
  67. rt = new CRotate(input);
  68. rt->Rotate(this->initalrotate);
  69. rt->SaveToFile(output);
  70. delete rt;
  71. }
  72. else
  73. {
  74. CopyFile(input, output);
  75. }
  76. CAlignAndCutImage *caic;
  77. caic = new CAlignAndCutImage(output);
  78. 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);
  79. caic->SaveToFile(output2);
  80. printf("Startwriting Output4:%s\n", output4.c_str());
  81. if (output4.length() > 0)
  82. {
  83. caic->drawRect(ref_x[0], ref_y[0], caic->t0_dx, caic->t0_dy, 255, 0, 0, 2);
  84. caic->drawRect(ref_x[1], ref_y[1], caic->t1_dx, caic->t1_dy, 255, 0, 0, 2);
  85. caic->SaveToFile(output4);
  86. printf("Write output4: %s\n", output4.c_str());
  87. }
  88. delete caic;
  89. // Align mit Templates
  90. return true;
  91. }