mirror of
https://github.com/jomjol/AI-on-the-edge-device.git
synced 2025-12-07 20:16:55 +03:00
Update
This commit is contained in:
@@ -136,18 +136,34 @@ static size_t jpg_encode_stream(void * arg, size_t index, const void* data, size
|
||||
return len;
|
||||
}
|
||||
|
||||
void CCamera::SetBrightnessContrastSaturation(int _brightness, int _contrast, int _saturation)
|
||||
bool CCamera::SetBrightnessContrastSaturation(int _brightness, int _contrast, int _saturation)
|
||||
{
|
||||
bool result = false;
|
||||
sensor_t * s = esp_camera_sensor_get();
|
||||
_brightness = min(2, max(-2, _brightness));
|
||||
// _contrast = min(2, max(-2, _contrast));
|
||||
_contrast = min(2, max(-2, _contrast));
|
||||
// _saturation = min(2, max(-2, _saturation));
|
||||
|
||||
// s->set_saturation(s, _saturation);
|
||||
// s->set_contrast(s, _contrast);
|
||||
s->set_contrast(s, _contrast);
|
||||
s->set_brightness(s, _brightness);
|
||||
}
|
||||
|
||||
if (_brightness != brightness)
|
||||
result = true;
|
||||
if (_contrast != contrast)
|
||||
result = true;
|
||||
if (_saturation != saturation)
|
||||
result = true;
|
||||
|
||||
brightness = _brightness;
|
||||
contrast = _contrast;
|
||||
saturation = _saturation;
|
||||
|
||||
if (result && isFixedExposure)
|
||||
EnableAutoExposure(waitbeforepicture_org);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void CCamera::SetQualitySize(int qual, framesize_t resol)
|
||||
@@ -194,6 +210,31 @@ void CCamera::SetQualitySize(int qual, framesize_t resol)
|
||||
}
|
||||
|
||||
|
||||
void CCamera::EnableAutoExposure(int flashdauer)
|
||||
{
|
||||
LEDOnOff(true);
|
||||
LightOnOff(true);
|
||||
const TickType_t xDelay = flashdauer / portTICK_PERIOD_MS;
|
||||
vTaskDelay( xDelay );
|
||||
|
||||
camera_fb_t * fb = esp_camera_fb_get();
|
||||
if (!fb) {
|
||||
ESP_LOGE(TAGCAMERACLASS, "Camera Capture Failed");
|
||||
}
|
||||
esp_camera_fb_return(fb);
|
||||
|
||||
sensor_t * s = esp_camera_sensor_get();
|
||||
s->set_gain_ctrl(s, 0);
|
||||
s->set_exposure_ctrl(s, 0);
|
||||
|
||||
|
||||
LEDOnOff(false);
|
||||
LightOnOff(false);
|
||||
isFixedExposure = true;
|
||||
waitbeforepicture_org = flashdauer;
|
||||
}
|
||||
|
||||
|
||||
|
||||
esp_err_t CCamera::CaptureToBasisImage(CImageBasis *_Image, int delay)
|
||||
{
|
||||
@@ -236,7 +277,7 @@ esp_err_t CCamera::CaptureToBasisImage(CImageBasis *_Image, int delay)
|
||||
LogFile.WriteHeapInfo("CCamera::CaptureToBasisImage - After fb_get");
|
||||
#endif
|
||||
|
||||
LEDOnOff(false);
|
||||
LEDOnOff(false);
|
||||
|
||||
if (delay > 0)
|
||||
LightOnOff(false);
|
||||
@@ -526,6 +567,10 @@ CCamera::CCamera()
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
printf("CreateClassCamera\n");
|
||||
#endif
|
||||
brightness = -5;
|
||||
contrast = -5;
|
||||
saturation = -5;
|
||||
isFixedExposure = false;
|
||||
}
|
||||
|
||||
esp_err_t CCamera::InitCam()
|
||||
|
||||
@@ -23,6 +23,9 @@ class CCamera {
|
||||
protected:
|
||||
int ActualQuality;
|
||||
framesize_t ActualResolution;
|
||||
int brightness, contrast, saturation;
|
||||
bool isFixedExposure;
|
||||
int waitbeforepicture_org;
|
||||
|
||||
public:
|
||||
int image_height, image_width;
|
||||
@@ -34,9 +37,12 @@ class CCamera {
|
||||
void LEDOnOff(bool status);
|
||||
esp_err_t CaptureToHTTP(httpd_req_t *req, int delay = 0);
|
||||
void SetQualitySize(int qual, framesize_t resol);
|
||||
void SetBrightnessContrastSaturation(int _brightness, int _contrast, int _saturation);
|
||||
bool SetBrightnessContrastSaturation(int _brightness, int _contrast, int _saturation);
|
||||
void GetCameraParameter(httpd_req_t *req, int &qual, framesize_t &resol);
|
||||
|
||||
void EnableAutoExposure(int flashdauer);
|
||||
|
||||
|
||||
framesize_t TextToFramesize(const char * text);
|
||||
|
||||
esp_err_t CaptureToFile(std::string nm, int delay = 0);
|
||||
|
||||
@@ -34,6 +34,7 @@ void ClassFlowMakeImage::SetInitialParameter(void)
|
||||
ImageSize = FRAMESIZE_VGA;
|
||||
SaveAllFiles = false;
|
||||
disabled = false;
|
||||
FixedExposure = false;
|
||||
namerawimage = "/sdcard/img_tmp/raw.jpg";
|
||||
}
|
||||
|
||||
@@ -97,6 +98,11 @@ bool ClassFlowMakeImage::ReadParameter(FILE* pfile, string& aktparamgraph)
|
||||
_saturation = stoi(zerlegt[1]);
|
||||
}
|
||||
|
||||
if ((toUpper(zerlegt[0]) == "FIXEDEXPOSURE") && (zerlegt.size() > 1))
|
||||
{
|
||||
if (toUpper(zerlegt[1]) == "TRUE")
|
||||
FixedExposure = true;
|
||||
}
|
||||
}
|
||||
|
||||
Camera.SetBrightnessContrastSaturation(_brightness, _contrast, _saturation);
|
||||
@@ -107,6 +113,18 @@ bool ClassFlowMakeImage::ReadParameter(FILE* pfile, string& aktparamgraph)
|
||||
rawImage = new CImageBasis();
|
||||
rawImage->CreateEmptyImage(image_width, image_height, 3);
|
||||
|
||||
waitbeforepicture_store = waitbeforepicture;
|
||||
if (FixedExposure)
|
||||
{
|
||||
printf("Fixed Exposure enabled!\n");
|
||||
int flashdauer = (int) (waitbeforepicture * 1000);
|
||||
Camera.EnableAutoExposure(flashdauer);
|
||||
waitbeforepicture = 0.2;
|
||||
// flashdauer = (int) (waitbeforepicture * 1000);
|
||||
// takePictureWithFlash(flashdauer);
|
||||
// rawImage->SaveToFile("/sdcard/init2.jpg");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -121,7 +139,7 @@ bool ClassFlowMakeImage::doFlow(string zwtime)
|
||||
{
|
||||
string logPath = CreateLogFolder(zwtime);
|
||||
|
||||
int flashdauer = (int) waitbeforepicture * 1000;
|
||||
int flashdauer = (int) (waitbeforepicture * 1000);
|
||||
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
LogFile.WriteHeapInfo("ClassFlowMakeImage::doFlow - Before takePictureWithFlash");
|
||||
@@ -146,7 +164,7 @@ bool ClassFlowMakeImage::doFlow(string zwtime)
|
||||
|
||||
esp_err_t ClassFlowMakeImage::SendRawJPG(httpd_req_t *req)
|
||||
{
|
||||
int flashdauer = (int) waitbeforepicture * 1000;
|
||||
int flashdauer = (int) (waitbeforepicture * 1000);
|
||||
return Camera.CaptureToHTTP(req, flashdauer);
|
||||
}
|
||||
|
||||
@@ -155,7 +173,7 @@ ImageData* ClassFlowMakeImage::SendRawImage()
|
||||
{
|
||||
CImageBasis *zw = new CImageBasis(rawImage);
|
||||
ImageData *id;
|
||||
int flashdauer = (int) waitbeforepicture * 1000;
|
||||
int flashdauer = (int) (waitbeforepicture * 1000);
|
||||
Camera.CaptureToBasisImage(zw, flashdauer);
|
||||
id = zw->writeToMemoryAsJPG();
|
||||
delete zw;
|
||||
|
||||
@@ -15,6 +15,7 @@ class ClassFlowMakeImage :
|
||||
{
|
||||
protected:
|
||||
float waitbeforepicture;
|
||||
float waitbeforepicture_store;
|
||||
framesize_t ImageSize;
|
||||
bool isImageSize;
|
||||
int ImageQuality;
|
||||
@@ -22,6 +23,8 @@ protected:
|
||||
string namerawimage;
|
||||
int image_height, image_width;
|
||||
bool SaveAllFiles;
|
||||
bool FixedExposure;
|
||||
|
||||
|
||||
|
||||
void CopyFile(string input, string output);
|
||||
@@ -29,6 +32,7 @@ protected:
|
||||
esp_err_t camera_capture();
|
||||
void takePictureWithFlash(int flashdauer);
|
||||
|
||||
|
||||
void SetInitialParameter(void);
|
||||
|
||||
public:
|
||||
|
||||
@@ -429,7 +429,7 @@ esp_err_t handler_editflow(httpd_req_t *req)
|
||||
|
||||
// printf("Parameter host: "); printf(_host.c_str()); printf("\n");
|
||||
// string zwzw = "Do " + _task + " start\n"; printf(zwzw.c_str());
|
||||
Camera.SetBrightnessContrastSaturation(bri, con, sat);
|
||||
bool changed = Camera.SetBrightnessContrastSaturation(bri, con, sat);
|
||||
std::string zw = tfliteflow.doSingleStep("[MakeImage]", _host);
|
||||
httpd_resp_sendstr_chunk(req, zw.c_str());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user