ClassFlowMakeImage.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. FixedExposure = false;
  31. namerawimage = "/sdcard/img_tmp/raw.jpg";
  32. }
  33. ClassFlowMakeImage::ClassFlowMakeImage(std::vector<ClassFlow*>* lfc) : ClassFlowImage(lfc, TAG)
  34. {
  35. SetInitialParameter();
  36. }
  37. bool ClassFlowMakeImage::ReadParameter(FILE* pfile, string& aktparamgraph)
  38. {
  39. std::vector<string> zerlegt;
  40. aktparamgraph = trim(aktparamgraph);
  41. int _brightness = 0;
  42. int _contrast = 0;
  43. int _saturation = 0;
  44. if (aktparamgraph.size() == 0)
  45. if (!this->GetNextParagraph(pfile, aktparamgraph))
  46. return false;
  47. if (aktparamgraph.compare("[MakeImage]") != 0) // Paragraph passt nich zu MakeImage
  48. return false;
  49. while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph))
  50. {
  51. zerlegt = this->ZerlegeZeile(aktparamgraph);
  52. if ((zerlegt[0] == "LogImageLocation") && (zerlegt.size() > 1))
  53. {
  54. LogImageLocation = "/sdcard" + zerlegt[1];
  55. isLogImage = true;
  56. }
  57. if ((zerlegt[0] == "ImageQuality") && (zerlegt.size() > 1))
  58. ImageQuality = std::stod(zerlegt[1]);
  59. if ((zerlegt[0] == "ImageSize") && (zerlegt.size() > 1))
  60. {
  61. ImageSize = Camera.TextToFramesize(zerlegt[1].c_str());
  62. isImageSize = true;
  63. }
  64. if ((toUpper(zerlegt[0]) == "SAVEALLFILES") && (zerlegt.size() > 1))
  65. {
  66. if (toUpper(zerlegt[1]) == "TRUE")
  67. SaveAllFiles = true;
  68. }
  69. if ((toUpper(zerlegt[0]) == "BRIGHTNESS") && (zerlegt.size() > 1))
  70. {
  71. _brightness = stoi(zerlegt[1]);
  72. }
  73. if ((toUpper(zerlegt[0]) == "CONTRAST") && (zerlegt.size() > 1))
  74. {
  75. _contrast = stoi(zerlegt[1]);
  76. }
  77. if ((toUpper(zerlegt[0]) == "SATURATION") && (zerlegt.size() > 1))
  78. {
  79. _saturation = stoi(zerlegt[1]);
  80. }
  81. if ((toUpper(zerlegt[0]) == "FIXEDEXPOSURE") && (zerlegt.size() > 1))
  82. {
  83. if (toUpper(zerlegt[1]) == "TRUE")
  84. FixedExposure = true;
  85. }
  86. }
  87. Camera.SetBrightnessContrastSaturation(_brightness, _contrast, _saturation);
  88. Camera.SetQualitySize(ImageQuality, ImageSize);
  89. image_width = Camera.image_width;
  90. image_height = Camera.image_height;
  91. rawImage = new CImageBasis();
  92. rawImage->CreateEmptyImage(image_width, image_height, 3);
  93. waitbeforepicture_store = waitbeforepicture;
  94. if (FixedExposure)
  95. {
  96. printf("Fixed Exposure enabled!\n");
  97. int flashdauer = (int) (waitbeforepicture * 1000);
  98. Camera.EnableAutoExposure(flashdauer);
  99. waitbeforepicture = 0.2;
  100. // flashdauer = (int) (waitbeforepicture * 1000);
  101. // takePictureWithFlash(flashdauer);
  102. // rawImage->SaveToFile("/sdcard/init2.jpg");
  103. }
  104. return true;
  105. }
  106. string ClassFlowMakeImage::getHTMLSingleStep(string host)
  107. {
  108. string result;
  109. result = "Raw Image: <br>\n<img src=\"" + host + "/img_tmp/raw.jpg\">\n";
  110. return result;
  111. }
  112. bool ClassFlowMakeImage::doFlow(string zwtime)
  113. {
  114. string logPath = CreateLogFolder(zwtime);
  115. int flashdauer = (int) (waitbeforepicture * 1000);
  116. #ifdef DEBUG_DETAIL_ON
  117. LogFile.WriteHeapInfo("ClassFlowMakeImage::doFlow - Before takePictureWithFlash");
  118. #endif
  119. takePictureWithFlash(flashdauer);
  120. #ifdef DEBUG_DETAIL_ON
  121. LogFile.WriteHeapInfo("ClassFlowMakeImage::doFlow - After takePictureWithFlash");
  122. #endif
  123. LogImage(logPath, "raw", NULL, NULL, zwtime, rawImage);
  124. RemoveOldLogs();
  125. #ifdef DEBUG_DETAIL_ON
  126. LogFile.WriteHeapInfo("ClassFlowMakeImage::doFlow - After RemoveOldLogs");
  127. #endif
  128. return true;
  129. }
  130. esp_err_t ClassFlowMakeImage::SendRawJPG(httpd_req_t *req)
  131. {
  132. int flashdauer = (int) (waitbeforepicture * 1000);
  133. return Camera.CaptureToHTTP(req, flashdauer);
  134. }
  135. ImageData* ClassFlowMakeImage::SendRawImage()
  136. {
  137. CImageBasis *zw = new CImageBasis(rawImage);
  138. ImageData *id;
  139. int flashdauer = (int) (waitbeforepicture * 1000);
  140. Camera.CaptureToBasisImage(zw, flashdauer);
  141. id = zw->writeToMemoryAsJPG();
  142. delete zw;
  143. return id;
  144. }
  145. time_t ClassFlowMakeImage::getTimeImageTaken()
  146. {
  147. return TimeImageTaken;
  148. }
  149. ClassFlowMakeImage::~ClassFlowMakeImage(void)
  150. {
  151. delete rawImage;
  152. }