ClassFlowMakeImage.cpp 3.7 KB

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