ClassFlowMakeImage.cpp 5.7 KB

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