Skip to content

Commit

Permalink
Add support for OV5640 camera (#3063)
Browse files Browse the repository at this point in the history
* Add support for OV5640 camera

* clean up sharpness handling

* limit sharpness range to -2 and +2

* refactor

* Fix OV3660 sharpness handling

* refactor sharpness handling

* fix OV3660 zoom mode

* reinstate aspect ratio via imageSize

* Changed OV5640 full frame size to match datasheet

* various fixes

* add denoise config and general clean up

* fix line endings to LF

* Support enabling red blue swap via web interface

* update jpeg quality limits

* remove color swap config; color swap workaround dependent on vflip

* fix missing commit

* fix gain ceiling

* Update cam vflip param page

* fix typo: camdenoise, not camsdenoise

* fix compile errors
  • Loading branch information
jasaw authored Aug 29, 2024
1 parent b4f6b1a commit 7225792
Show file tree
Hide file tree
Showing 15 changed files with 476 additions and 227 deletions.
346 changes: 205 additions & 141 deletions code/components/jomjol_controlcamera/ClassControllCamera.cpp

Large diffs are not rendered by default.

29 changes: 14 additions & 15 deletions code/components/jomjol_controlcamera/ClassControllCamera.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,10 @@
#include "CImageBasis.h"
#include "../../include/defines.h"

typedef enum
{
OV2640_MODE_UXGA,
OV2640_MODE_SVGA,
OV2640_MODE_CIF
} ov2640_sensor_mode_t;

typedef struct
{
uint16_t CamSensor_id;

framesize_t ImageFrameSize = FRAMESIZE_VGA; // 0 - 10
gainceiling_t ImageGainceiling; // Image gain (GAINCEILING_x2, x4, x8, x16, x32, x64 or x128)

Expand Down Expand Up @@ -51,13 +46,14 @@ typedef struct
int ImageVflip; // Invert image (0 or 1)
int ImageDcw; // downsize enable (1 or 0)

int ImageDenoiseLevel; // The OV2640 does not support it, OV3660 and OV5640 (0 to 8)

int ImageWidth;
int ImageHeight;

int ImageLedIntensity;

bool ImageZoomEnabled;
int ImageZoomMode;
int ImageZoomOffsetX;
int ImageZoomOffsetY;
int ImageZoomSize;
Expand All @@ -79,33 +75,36 @@ class CCamera
void ledc_init(void);
bool loadNextDemoImage(camera_fb_t *fb);
long GetFileSize(std::string filename);
void SetCamWindow(sensor_t *s, int resolution, int xOffset, int yOffset, int xTotal, int yTotal, int xOutput, int yOutput);
void SetCamWindow(sensor_t *s, int frameSizeX, int frameSizeY, int xOffset, int yOffset, int xTotal, int yTotal, int xOutput, int yOutput, int imageVflip);
void SetImageWidthHeightFromResolution(framesize_t resol);
void SanitizeZoomParams(int imageSize, int frameSizeX, int frameSizeY, int &imageWidth, int &imageHeight, int &zoomOffsetX, int &zoomOffsetY);

public:
CCamera(void);
esp_err_t InitCam(void);

void LightOnOff(bool status);
void LEDOnOff(bool status);

esp_err_t setSensorDatenFromCCstatus(void);
esp_err_t getSensorDatenToCCstatus(void);

int ov5640_set_gainceiling(sensor_t *s, gainceiling_t level);

esp_err_t CaptureToHTTP(httpd_req_t *req, int delay = 0);
esp_err_t CaptureToStream(httpd_req_t *req, bool FlashlightOn);

void SetQualityZoomSize(int qual, framesize_t resol, bool zoomEnabled, int zoomOffsetX, int zoomOffsetY, int imageSize);
void SetZoomSize(bool zoomEnabled, int zoomOffsetX, int zoomOffsetY, int imageSize);
void SetQualityZoomSize(int qual, framesize_t resol, bool zoomEnabled, int zoomOffsetX, int zoomOffsetY, int imageSize, int imageVflip);
void SetZoomSize(bool zoomEnabled, int zoomOffsetX, int zoomOffsetY, int imageSize, int imageVflip);
void SetCamSharpness(bool _autoSharpnessEnabled, int _sharpnessLevel);
void SetLEDIntensity(float _intrel);

void SetLEDIntensity(float _intrel);
bool testCamera(void);
bool getCameraInitSuccessful(void);
void useDemoMode(void);

framesize_t TextToFramesize(const char *text);

esp_err_t CaptureToFile(std::string nm, int delay = 0);
esp_err_t CaptureToBasisImage(CImageBasis *_Image, int delay = 0);
};
Expand Down
6 changes: 3 additions & 3 deletions code/components/jomjol_controlcamera/server_camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ esp_err_t handler_capture(httpd_req_t *req)
if (CFstatus.changedCameraSettings)
{
Camera.setSensorDatenFromCCstatus(); // CCstatus >>> Kamera
Camera.SetQualityZoomSize(CCstatus.ImageQuality, CCstatus.ImageFrameSize, CCstatus.ImageZoomEnabled, CCstatus.ImageZoomOffsetX, CCstatus.ImageZoomOffsetY, CCstatus.ImageZoomSize);
Camera.SetQualityZoomSize(CCstatus.ImageQuality, CCstatus.ImageFrameSize, CCstatus.ImageZoomEnabled, CCstatus.ImageZoomOffsetX, CCstatus.ImageZoomOffsetY, CCstatus.ImageZoomSize, CCstatus.ImageVflip);
CFstatus.changedCameraSettings = false;
}

Expand Down Expand Up @@ -154,7 +154,7 @@ esp_err_t handler_capture_with_light(httpd_req_t *req)
if (CFstatus.changedCameraSettings)
{
Camera.setSensorDatenFromCCstatus(); // CCstatus >>> Kamera
Camera.SetQualityZoomSize(CCstatus.ImageQuality, CCstatus.ImageFrameSize, CCstatus.ImageZoomEnabled, CCstatus.ImageZoomOffsetX, CCstatus.ImageZoomOffsetY, CCstatus.ImageZoomSize);
Camera.SetQualityZoomSize(CCstatus.ImageQuality, CCstatus.ImageFrameSize, CCstatus.ImageZoomEnabled, CCstatus.ImageZoomOffsetX, CCstatus.ImageZoomOffsetY, CCstatus.ImageZoomSize, CCstatus.ImageVflip);
CFstatus.changedCameraSettings = false;
}

Expand Down Expand Up @@ -236,7 +236,7 @@ esp_err_t handler_capture_save_to_file(httpd_req_t *req)
if (CFstatus.changedCameraSettings)
{
Camera.setSensorDatenFromCCstatus(); // CCstatus >>> Kamera
Camera.SetQualityZoomSize(CCstatus.ImageQuality, CCstatus.ImageFrameSize, CCstatus.ImageZoomEnabled, CCstatus.ImageZoomOffsetX, CCstatus.ImageZoomOffsetY, CCstatus.ImageZoomSize);
Camera.SetQualityZoomSize(CCstatus.ImageQuality, CCstatus.ImageFrameSize, CCstatus.ImageZoomEnabled, CCstatus.ImageZoomOffsetX, CCstatus.ImageZoomOffsetY, CCstatus.ImageZoomSize, CCstatus.ImageVflip);
CFstatus.changedCameraSettings = false;
}

Expand Down
80 changes: 73 additions & 7 deletions code/components/jomjol_flowcontroll/ClassFlowTakeImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,14 @@ bool ClassFlowTakeImage::ReadParameter(FILE *pfile, string &aktparamgraph)
if (isStringNumeric(splitted[1]))
{
int _ImageSharpness = std::stoi(splitted[1]);
CCstatus.ImageSharpness = clipInt(_ImageSharpness, 2, -2);
if (CCstatus.CamSensor_id == OV2640_PID)
{
CCstatus.ImageSharpness = clipInt(_ImageSharpness, 2, -2);
}
else
{
CCstatus.ImageSharpness = clipInt(_ImageSharpness, 3, -3);
}
}
}

Expand Down Expand Up @@ -289,7 +296,14 @@ bool ClassFlowTakeImage::ReadParameter(FILE *pfile, string &aktparamgraph)
if (isStringNumeric(splitted[1]))
{
int _ImageAeLevel = std::stoi(splitted[1]);
CCstatus.ImageAeLevel = clipInt(_ImageAeLevel, 2, -2);
if (CCstatus.CamSensor_id == OV2640_PID)
{
CCstatus.ImageAeLevel = clipInt(_ImageAeLevel, 2, -2);
}
else
{
CCstatus.ImageAeLevel = clipInt(_ImageAeLevel, 5, -5);
}
}
}

Expand Down Expand Up @@ -351,6 +365,22 @@ bool ClassFlowTakeImage::ReadParameter(FILE *pfile, string &aktparamgraph)
CCstatus.ImageDcw = alphanumericToBoolean(splitted[1]);
}

else if ((toUpper(splitted[0]) == "CAMDENOISE") && (splitted.size() > 1))
{
if (isStringNumeric(splitted[1]))
{
int _ImageDenoiseLevel = std::stoi(splitted[1]);
if (CCstatus.CamSensor_id == OV2640_PID)
{
CCstatus.ImageDenoiseLevel = 0;
}
else
{
CCstatus.ImageDenoiseLevel = clipInt(_ImageDenoiseLevel, 8, 0);
}
}
}

else if ((toUpper(splitted[0]) == "CAMZOOM") && (splitted.size() > 1))
{
CCstatus.ImageZoomEnabled = alphanumericToBoolean(splitted[1]);
Expand All @@ -360,23 +390,59 @@ bool ClassFlowTakeImage::ReadParameter(FILE *pfile, string &aktparamgraph)
{
if (isStringNumeric(splitted[1]))
{
CCstatus.ImageZoomOffsetX = std::stoi(splitted[1]);
int _ImageZoomOffsetX = std::stoi(splitted[1]);
if (CCstatus.CamSensor_id == OV2640_PID)
{
CCstatus.ImageZoomOffsetX = clipInt(_ImageZoomOffsetX, 480, -480);
}
else if (CCstatus.CamSensor_id == OV3660_PID)
{
CCstatus.ImageZoomOffsetX = clipInt(_ImageZoomOffsetX, 704, -704);
}
else if (CCstatus.CamSensor_id == OV5640_PID)
{
CCstatus.ImageZoomOffsetX = clipInt(_ImageZoomOffsetX, 960, -960);
}
}
}

else if ((toUpper(splitted[0]) == "CAMZOOMOFFSETY") && (splitted.size() > 1))
{
if (isStringNumeric(splitted[1]))
{
CCstatus.ImageZoomOffsetY = std::stoi(splitted[1]);
int _ImageZoomOffsetY = std::stoi(splitted[1]);
if (CCstatus.CamSensor_id == OV2640_PID)
{
CCstatus.ImageZoomOffsetY = clipInt(_ImageZoomOffsetY, 360, -360);
}
else if (CCstatus.CamSensor_id == OV3660_PID)
{
CCstatus.ImageZoomOffsetY = clipInt(_ImageZoomOffsetY, 528, -528);
}
else if (CCstatus.CamSensor_id == OV5640_PID)
{
CCstatus.ImageZoomOffsetY = clipInt(_ImageZoomOffsetY, 720, -720);
}
}
}

else if ((toUpper(splitted[0]) == "CAMZOOMSIZE") && (splitted.size() > 1))
{
if (isStringNumeric(splitted[1]))
{
CCstatus.ImageZoomSize = std::stoi(splitted[1]);
int _ImageZoomSize = std::stoi(splitted[1]);
if (CCstatus.CamSensor_id == OV2640_PID)
{
CCstatus.ImageZoomSize = clipInt(_ImageZoomSize, 29, 0);
}
else if (CCstatus.CamSensor_id == OV3660_PID)
{
CCstatus.ImageZoomSize = clipInt(_ImageZoomSize, 43, 0);
}
else if (CCstatus.CamSensor_id == OV5640_PID)
{
CCstatus.ImageZoomSize = clipInt(_ImageZoomSize, 59, 0);
}
}
}

Expand All @@ -400,7 +466,7 @@ bool ClassFlowTakeImage::ReadParameter(FILE *pfile, string &aktparamgraph)
}

Camera.setSensorDatenFromCCstatus(); // CCstatus >>> Kamera
Camera.SetQualityZoomSize(CCstatus.ImageQuality, CCstatus.ImageFrameSize, CCstatus.ImageZoomEnabled, CCstatus.ImageZoomOffsetX, CCstatus.ImageZoomOffsetY, CCstatus.ImageZoomSize);
Camera.SetQualityZoomSize(CCstatus.ImageQuality, CCstatus.ImageFrameSize, CCstatus.ImageZoomEnabled, CCstatus.ImageZoomOffsetX, CCstatus.ImageZoomOffsetY, CCstatus.ImageZoomSize, CCstatus.ImageVflip);

rawImage = new CImageBasis("rawImage");
rawImage->CreateEmptyImage(CCstatus.ImageWidth, CCstatus.ImageHeight, 3);
Expand Down Expand Up @@ -443,7 +509,7 @@ bool ClassFlowTakeImage::doFlow(string zwtime)
if (CFstatus.changedCameraSettings)
{
Camera.setSensorDatenFromCCstatus(); // CCstatus >>> Kamera
Camera.SetQualityZoomSize(CCstatus.ImageQuality, CCstatus.ImageFrameSize, CCstatus.ImageZoomEnabled, CCstatus.ImageZoomOffsetX, CCstatus.ImageZoomOffsetY, CCstatus.ImageZoomSize);
Camera.SetQualityZoomSize(CCstatus.ImageQuality, CCstatus.ImageFrameSize, CCstatus.ImageZoomEnabled, CCstatus.ImageZoomOffsetX, CCstatus.ImageZoomOffsetY, CCstatus.ImageZoomSize, CCstatus.ImageVflip);
CFstatus.changedCameraSettings = false;
}

Expand Down
Loading

0 comments on commit 7225792

Please sign in to comment.