ClassFlowMakeImage.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. #include "ClassFlowMakeImage.h"
  2. #include "Helper.h"
  3. #include "ClassLogFile.h"
  4. #include "CImageBasis.h"
  5. #include "ClassControllCamera.h"
  6. #include <time.h>
  7. // #define DEBUG_DETAIL_ON
  8. static const char* TAG = "flow_make_image";
  9. esp_err_t ClassFlowMakeImage::camera_capture(){
  10. string nm = namerawimage;
  11. Camera.CaptureToFile(nm);
  12. return ESP_OK;
  13. }
  14. void ClassFlowMakeImage::takePictureWithFlash(int flashdauer)
  15. {
  16. Camera.CaptureToBasisImage(rawImage, flashdauer);
  17. if (SaveAllFiles) rawImage->SaveToFile(namerawimage);
  18. }
  19. void ClassFlowMakeImage::SetInitialParameter(void)
  20. {
  21. waitbeforepicture = 5;
  22. isImageSize = false;
  23. ImageQuality = -1;
  24. TimeImageTaken = 0;
  25. ImageQuality = 5;
  26. rawImage = NULL;
  27. ImageSize = FRAMESIZE_VGA;
  28. SaveAllFiles = false;
  29. disabled = false;
  30. namerawimage = "/sdcard/img_tmp/raw.jpg";
  31. }
  32. ClassFlowMakeImage::ClassFlowMakeImage(std::vector<ClassFlow*>* lfc) : ClassFlowImage(lfc, TAG)
  33. {
  34. SetInitialParameter();
  35. }
  36. bool ClassFlowMakeImage::ReadParameter(FILE* pfile, string& aktparamgraph)
  37. {
  38. std::vector<string> zerlegt;
  39. aktparamgraph = trim(aktparamgraph);
  40. int _brightness = 0;
  41. int _contrast = 0;
  42. int _saturation = 0;
  43. if (aktparamgraph.size() == 0)
  44. if (!this->GetNextParagraph(pfile, aktparamgraph))
  45. return false;
  46. if (aktparamgraph.compare("[MakeImage]") != 0) // Paragraph passt nich zu MakeImage
  47. return false;
  48. while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph))
  49. {
  50. zerlegt = this->ZerlegeZeile(aktparamgraph);
  51. if ((zerlegt[0] == "LogImageLocation") && (zerlegt.size() > 1))
  52. {
  53. LogImageLocation = "/sdcard" + zerlegt[1];
  54. isLogImage = true;
  55. }
  56. if ((zerlegt[0] == "ImageQuality") && (zerlegt.size() > 1))
  57. ImageQuality = std::stod(zerlegt[1]);
  58. if ((zerlegt[0] == "ImageSize") && (zerlegt.size() > 1))
  59. {
  60. ImageSize = Camera.TextToFramesize(zerlegt[1].c_str());
  61. isImageSize = true;
  62. }
  63. if ((toUpper(zerlegt[0]) == "SAVEALLFILES") && (zerlegt.size() > 1))
  64. {
  65. if (toUpper(zerlegt[1]) == "TRUE")
  66. SaveAllFiles = true;
  67. }
  68. if ((toUpper(zerlegt[0]) == "BRIGHTNESS") && (zerlegt.size() > 1))
  69. {
  70. _brightness = stoi(zerlegt[1]);
  71. }
  72. if ((toUpper(zerlegt[0]) == "CONTRAST") && (zerlegt.size() > 1))
  73. {
  74. _contrast = stoi(zerlegt[1]);
  75. }
  76. if ((toUpper(zerlegt[0]) == "SATURATION") && (zerlegt.size() > 1))
  77. {
  78. _saturation = stoi(zerlegt[1]);
  79. }
  80. }
  81. Camera.SetBrightnessContrastSaturation(_brightness, _contrast, _saturation);
  82. Camera.SetQualitySize(ImageQuality, ImageSize);
  83. image_width = Camera.image_width;
  84. image_height = Camera.image_height;
  85. rawImage = new CImageBasis();
  86. rawImage->CreateEmptyImage(image_width, image_height, 3);
  87. return true;
  88. }
  89. string ClassFlowMakeImage::getHTMLSingleStep(string host)
  90. {
  91. string result;
  92. result = "Raw Image: <br>\n<img src=\"" + host + "/img_tmp/raw.jpg\">\n";
  93. return result;
  94. }
  95. bool ClassFlowMakeImage::doFlow(string zwtime)
  96. {
  97. string logPath = CreateLogFolder(zwtime);
  98. int flashdauer = (int) waitbeforepicture * 1000;
  99. #ifdef DEBUG_DETAIL_ON
  100. LogFile.WriteHeapInfo("ClassFlowMakeImage::doFlow - Before takePictureWithFlash");
  101. #endif
  102. takePictureWithFlash(flashdauer);
  103. #ifdef DEBUG_DETAIL_ON
  104. LogFile.WriteHeapInfo("ClassFlowMakeImage::doFlow - After takePictureWithFlash");
  105. #endif
  106. LogImage(logPath, "raw", NULL, NULL, zwtime, rawImage);
  107. RemoveOldLogs();
  108. #ifdef DEBUG_DETAIL_ON
  109. LogFile.WriteHeapInfo("ClassFlowMakeImage::doFlow - After RemoveOldLogs");
  110. #endif
  111. return true;
  112. }
  113. esp_err_t ClassFlowMakeImage::SendRawJPG(httpd_req_t *req)
  114. {
  115. int flashdauer = (int) waitbeforepicture * 1000;
  116. return Camera.CaptureToHTTP(req, flashdauer);
  117. }
  118. ImageData* ClassFlowMakeImage::SendRawImage()
  119. {
  120. CImageBasis *zw = new CImageBasis(rawImage);
  121. ImageData *id;
  122. int flashdauer = (int) waitbeforepicture * 1000;
  123. Camera.CaptureToBasisImage(zw, flashdauer);
  124. id = zw->writeToMemoryAsJPG();
  125. delete zw;
  126. return id;
  127. }
  128. time_t ClassFlowMakeImage::getTimeImageTaken()
  129. {
  130. return TimeImageTaken;
  131. }
  132. ClassFlowMakeImage::~ClassFlowMakeImage(void)
  133. {
  134. delete rawImage;
  135. }