ClassFlowMakeImage.cpp 5.3 KB

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