ClassFlowMakeImage.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. #include "ClassFlowMakeImage.h"
  2. #include "Helper.h"
  3. #include "CFindTemplate.h"
  4. #include "ClassControllCamera.h"
  5. #include <time.h>
  6. esp_err_t ClassFlowMakeImage::camera_capture(){
  7. string nm = namerawimage;
  8. Camera.CaptureToFile(nm);
  9. return ESP_OK;
  10. }
  11. void ClassFlowMakeImage::takePictureWithFlash(int flashdauer)
  12. {
  13. string nm = namerawimage;
  14. if (isImageSize && (ImageQuality > 0))
  15. Camera.SetQualitySize(ImageQuality, ImageSize);
  16. printf("Start CaptureFile\n");
  17. Camera.CaptureToFile(nm, flashdauer);
  18. }
  19. ClassFlowMakeImage::ClassFlowMakeImage()
  20. {
  21. isLogImage = false;
  22. waitbeforepicture = 5;
  23. isImageSize = false;
  24. ImageQuality = -1;
  25. TimeImageTaken = 0;
  26. namerawimage = "/sdcard/img_tmp/raw.jpg";
  27. }
  28. ClassFlowMakeImage::ClassFlowMakeImage(std::vector<ClassFlow*>* lfc)
  29. {
  30. isLogImage = false;
  31. waitbeforepicture = 5;
  32. isImageSize = false;
  33. ImageQuality = -1;
  34. TimeImageTaken = 0;
  35. namerawimage = "/sdcard/img_tmp/raw.jpg";
  36. ListFlowControll = lfc;
  37. }
  38. bool ClassFlowMakeImage::ReadParameter(FILE* pfile, string& aktparamgraph)
  39. {
  40. std::vector<string> zerlegt;
  41. aktparamgraph = trim(aktparamgraph);
  42. if (aktparamgraph.size() == 0)
  43. if (!this->GetNextParagraph(pfile, aktparamgraph))
  44. return false;
  45. if (aktparamgraph.compare("[MakeImage]") != 0) // Paragraph passt nich zu MakeImage
  46. return false;
  47. while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph))
  48. {
  49. zerlegt = this->ZerlegeZeile(aktparamgraph);
  50. if ((zerlegt[0] == "LogImageLocation") && (zerlegt.size() > 1))
  51. {
  52. this->isLogImage = true;
  53. this->LogImageLocation = zerlegt[1];
  54. }
  55. if ((zerlegt[0] == "ImageQuality") && (zerlegt.size() > 1))
  56. this->ImageQuality = std::stod(zerlegt[1]);
  57. if ((zerlegt[0] == "ImageSize") && (zerlegt.size() > 1))
  58. {
  59. ImageSize = Camera.TextToFramesize(zerlegt[1].c_str());
  60. isImageSize = true;
  61. }
  62. }
  63. return true;
  64. }
  65. void ClassFlowMakeImage::CopyFile(string input, string output)
  66. {
  67. input = FormatFileName(input);
  68. output = FormatFileName(output);
  69. input = namerawimage;
  70. printf("Copy Input : %s\n", input.c_str());
  71. printf("Copy Output: %s\n", output.c_str());
  72. char cTemp;
  73. FILE* fpSourceFile = fopen(input.c_str(), "rb");
  74. FILE* fpTargetFile = fopen(output.c_str(), "wb");
  75. if (fpSourceFile == NULL)
  76. {
  77. printf("fpSourceFile == NULL\n");
  78. perror("Error");
  79. }
  80. if (fpTargetFile == NULL)
  81. {
  82. printf("fpTargetFile == NULL\n");
  83. perror("Error");
  84. }
  85. while (fread(&cTemp, 1, 1, fpSourceFile) == 1)
  86. {
  87. fwrite(&cTemp, 1, 1, fpTargetFile);
  88. }
  89. // Close The Files
  90. fclose(fpSourceFile);
  91. fclose(fpTargetFile);
  92. printf("Copy done\n");
  93. }
  94. string ClassFlowMakeImage::getHTMLSingleStep(string host)
  95. {
  96. string result;
  97. result = "Raw Image: <br>\n<img src=\"" + host + "/img_tmp/raw.jpg\">\n";
  98. return result;
  99. }
  100. bool ClassFlowMakeImage::doFlow(string zwtime)
  101. {
  102. ////////////////////////////////////////////////////////////////////
  103. // TakeImage and Store into /image_tmp/raw.jpg TO BE DONE
  104. ////////////////////////////////////////////////////////////////////
  105. int flashdauer = (int) waitbeforepicture * 1000;
  106. takePictureWithFlash(flashdauer);
  107. time(&TimeImageTaken);
  108. localtime(&TimeImageTaken);
  109. if (this->isLogImage)
  110. {
  111. string nm = "/sdcard" + this->LogImageLocation + "/" + zwtime + ".jpg";
  112. string input = "/sdcard/image_tmp/raw.jgp";
  113. printf("loginput from: %s to: %s\n", input.c_str(), nm.c_str());
  114. nm = FormatFileName(nm);
  115. input = FormatFileName(input);
  116. CopyFile(input, nm);
  117. }
  118. return true;
  119. }
  120. time_t ClassFlowMakeImage::getTimeImageTaken()
  121. {
  122. return TimeImageTaken;
  123. }