From 7ca4ffe11174edd43182719740c3dc42bae8ac3d Mon Sep 17 00:00:00 2001 From: Pammy <43200418+pammyleong@users.noreply.github.com> Date: Fri, 15 Dec 2023 11:46:21 +0800 Subject: [PATCH] Add ISP Control API and Examples (#174) - Update CameraSetting in VideoStream.cpp,.h - Add Examples for Image Tuning, Mode, AWB. WDR and AE --- .../hardware/cores/ambpro2/video_drv.c | 29 ++ .../hardware/cores/ambpro2/video_drv.h | 21 ++ .../examples/ISPControl/Exposure/Exposure.ino | 121 +++++++ .../ISPControl/ImageTuning/ImageTuning.ino | 128 +++++++ .../examples/ISPControl/Mode/Mode.ino | 104 ++++++ .../ISPControl/WhiteBalance/WhiteBalance.ino | 115 +++++++ .../WideDynamicRange/WideDynamicRange.ino | 104 ++++++ .../libraries/Multimedia/src/VideoStream.cpp | 318 ++++++++++++++++++ .../libraries/Multimedia/src/VideoStream.h | 58 +++- 9 files changed, 997 insertions(+), 1 deletion(-) create mode 100644 Arduino_package/hardware/libraries/Multimedia/examples/ISPControl/Exposure/Exposure.ino create mode 100644 Arduino_package/hardware/libraries/Multimedia/examples/ISPControl/ImageTuning/ImageTuning.ino create mode 100644 Arduino_package/hardware/libraries/Multimedia/examples/ISPControl/Mode/Mode.ino create mode 100644 Arduino_package/hardware/libraries/Multimedia/examples/ISPControl/WhiteBalance/WhiteBalance.ino create mode 100644 Arduino_package/hardware/libraries/Multimedia/examples/ISPControl/WideDynamicRange/WideDynamicRange.ino diff --git a/Arduino_package/hardware/cores/ambpro2/video_drv.c b/Arduino_package/hardware/cores/ambpro2/video_drv.c index 3bc67831..064e0d7c 100644 --- a/Arduino_package/hardware/cores/ambpro2/video_drv.c +++ b/Arduino_package/hardware/cores/ambpro2/video_drv.c @@ -2,6 +2,7 @@ #include "hal_video.h" #include "video_api.h" #include "module_video.h" +#include "isp_ctrl_api.h" extern int incb[5]; extern int enc_queue_cnt[5]; @@ -10,6 +11,21 @@ uint32_t image_addr = 0; uint32_t image_len = 0; int voe_heap_size = 0; +static isp_control ISPCtrl = { + .Brightness = 0, + .Contrast = 50, + .Saturation = 50, + .Sharpness = 50, + .LDC = 0, + .WDRMode = 0, + .WDRLevel = 50, + .ExposureMode = 1, + .AWB = 1, + .GrayMode = 0, + .PowerLineFreq = 3, + .DayNightMode = 0 +}; + static video_params_t video_params = { .stream_id = 0, .type = 0, @@ -45,6 +61,19 @@ static video_params_t video_v4_params = { } }; +void ISPControlReset(void) { + isp_set_brightness(ISPCtrl.Brightness); + isp_set_contrast(ISPCtrl.Contrast); + isp_set_saturation(ISPCtrl.Saturation); + isp_set_sharpness(ISPCtrl.Sharpness); + isp_set_ldc(ISPCtrl.LDC); + isp_set_wdr_mode(ISPCtrl.WDRMode); + isp_set_exposure_mode(ISPCtrl.ExposureMode); + isp_set_awb_ctrl(ISPCtrl.AWB); + isp_set_gray_mode(ISPCtrl.GrayMode); + isp_set_power_line_freq(ISPCtrl.PowerLineFreq); + isp_set_day_night(ISPCtrl.DayNightMode); +} int cameraConfig(int v1_enable, int v1_w, int v1_h, int v1_bps, int v1_snapshot, int v2_enable, int v2_w, int v2_h, int v2_bps, int v2_snapshot, diff --git a/Arduino_package/hardware/cores/ambpro2/video_drv.h b/Arduino_package/hardware/cores/ambpro2/video_drv.h index a487c32a..7df5156a 100644 --- a/Arduino_package/hardware/cores/ambpro2/video_drv.h +++ b/Arduino_package/hardware/cores/ambpro2/video_drv.h @@ -3,6 +3,27 @@ #include "mmf2_module.h" +typedef struct { + int Brightness; + int Contrast; + int Saturation; + int Sharpness; + int LDC; + int WDRMode; + int WDRLevel; + int ExposureMode; + int ExposureTime; + int AWB; + int RedBalance; + int BlueBalance; + int AEGain; + int GrayMode; + int PowerLineFreq; + int DayNightMode; +} isp_control; + +void ISPControlReset(void); + int cameraConfig(int v1_enable, int v1_w, int v1_h, int v1_bps, int v1_snapshot, int v2_enable, int v2_w, int v2_h, int v2_bps, int v2_snapshot, int v3_enable, int v3_w, int v3_h, int v3_bps, int v3_snapshot, diff --git a/Arduino_package/hardware/libraries/Multimedia/examples/ISPControl/Exposure/Exposure.ino b/Arduino_package/hardware/libraries/Multimedia/examples/ISPControl/Exposure/Exposure.ino new file mode 100644 index 00000000..f6e110cf --- /dev/null +++ b/Arduino_package/hardware/libraries/Multimedia/examples/ISPControl/Exposure/Exposure.ino @@ -0,0 +1,121 @@ +/* + Example guide: + + // "AE=" Set Auto Exposure, 0: Manual, 1: Auto + // "AE" Get value of Auto Exposure + // "EXPTIME=" Set Exposure Time: Max: 33333us + // "EXPTIME" Get Exposure Time + // "GAIN=" Set AE Gain: Range from 256 to 32768 + // "GAIN" Get AE Gain + // "PLF=" Set Power Line Frequency, 0: Disabled, 1: 50Hz, 2: 60Hz, 3: Auto + // "PLF" Get value of Power Line Frequency + // "RESET" Reset to default +*/ + +#include "WiFi.h" +#include "StreamIO.h" +#include "VideoStream.h" +#include "RTSP.h" + +#define CHANNEL 0 + +// Default preset configurations for each video channel: +// Channel 0 : 1920 x 1080 30FPS H264 +// Channel 1 : 1280 x 720 30FPS H264 +// Channel 2 : 1280 x 720 30FPS MJPEG +CameraSetting configCam; +VideoSetting config(CHANNEL); +RTSP rtsp; +StreamIO videoStreamer(1, 1); // 1 Input Video -> 1 Output RTSP + +char ssid[] = "Network_SSID"; // your network SSID (name) +char pass[] = "Password"; // your network password +int status = WL_IDLE_STATUS; + +void setup() { + Serial.begin(115200); + + // attempt to connect to Wifi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to WPA SSID: "); + Serial.println(ssid); + status = WiFi.begin(ssid, pass); + + // wait 2 seconds for connection: + delay(2000); + } + + // Configure camera video channel with video format information + // Adjust the bitrate based on your WiFi network quality + //config.setBitrate(2 * 1024 * 1024); // Recommend to use 2Mbps for RTSP streaming to prevent network congestion + Camera.configVideoChannel(CHANNEL, config); + Camera.videoInit(); + + // Configure RTSP with identical video format information + rtsp.configVideo(config); + rtsp.begin(); + + // Configure StreamIO object to stream data from video channel to RTSP + videoStreamer.registerInput(Camera.getStream(CHANNEL)); + videoStreamer.registerOutput(rtsp); + if (videoStreamer.begin() != 0) { + Serial.println("StreamIO link start failed"); + } + + // Start data stream from video channel + Camera.channelBegin(CHANNEL); + + delay(1000); + printInfo(); +} + +void loop() { + if (Serial.available() > 0) { + String input = Serial.readString(); + input.trim(); + + if (input.startsWith(String("AE="))) { + String value = input.substring(3); + int val = value.toInt(); + configCam.setExposureMode(val); + } else if (input.startsWith(String("AE"))) { + configCam.getExposureMode(); + } else if (input.startsWith(String("EXPTIME="))) { + String value = input.substring(8); + int val = value.toInt(); + configCam.setExposureTime(val); + } else if (input.startsWith(String("EXPTIME"))) { + configCam.getExposureTime(); + } else if (input.startsWith(String("GAIN="))) { + String value = input.substring(5); + int val = value.toInt(); + configCam.setAEGain(val); + } else if (input.startsWith(String("GAIN"))) { + configCam.getAEGain(); + } else if (input.startsWith(String("PLF="))) { + String value = input.substring(4); + int val = value.toInt(); + configCam.setPowerLineFreq(val); + } else if (input.startsWith(String("PLF"))) { + configCam.getPowerLineFreq(); + } else if (input.startsWith(String("RESET"))) { + configCam.reset(); + } + } +} + +void printInfo(void) { + Serial.println("------------------------------"); + Serial.println("- Summary of Streaming -"); + Serial.println("------------------------------"); + Camera.printInfo(); + + IPAddress ip = WiFi.localIP(); + + Serial.println("- RTSP -"); + Serial.print("rtsp://"); + Serial.print(ip); + Serial.print(":"); + rtsp.printInfo(); +} + diff --git a/Arduino_package/hardware/libraries/Multimedia/examples/ISPControl/ImageTuning/ImageTuning.ino b/Arduino_package/hardware/libraries/Multimedia/examples/ISPControl/ImageTuning/ImageTuning.ino new file mode 100644 index 00000000..f6965ffb --- /dev/null +++ b/Arduino_package/hardware/libraries/Multimedia/examples/ISPControl/ImageTuning/ImageTuning.ino @@ -0,0 +1,128 @@ +/* + Example guide: + + // "BRIGHTNESS=" Set Brightness: Range from -64 to 64 + // "BRIGHTNESS" Get Brightness level + // "CONTRAST=" Set Contrast: Range from 0 to 100 + // "CONTRAST" Get Contrast level + // "SATURATION=" Set Contrast: Range from 0 to 100 + // "SATURATION" Get Contrast level + // "SHARPNESS=" Set Sharpness: Range from 0 to 100 + // "SHARPNESS" Get Sharpness level + // "LDC=" Len Distortion Correction: 0: Disabled, 1: Enabled + // "LDC" Get value of Len Distortion Correction + // "RESET" Reset to default +*/ + +#include "WiFi.h" +#include "StreamIO.h" +#include "VideoStream.h" +#include "RTSP.h" + +#define CHANNEL 0 + +// Default preset configurations for each video channel: +// Channel 0 : 1920 x 1080 30FPS H264 +// Channel 1 : 1280 x 720 30FPS H264 +// Channel 2 : 1280 x 720 30FPS MJPEG +CameraSetting configCam; +VideoSetting config(CHANNEL); +RTSP rtsp; +StreamIO videoStreamer(1, 1); // 1 Input Video -> 1 Output RTSP + +char ssid[] = "Network_SSID"; // your network SSID (name) +char pass[] = "Password"; // your network password +int status = WL_IDLE_STATUS; + +void setup() { + Serial.begin(115200); + + // attempt to connect to Wifi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to WPA SSID: "); + Serial.println(ssid); + status = WiFi.begin(ssid, pass); + + // wait 2 seconds for connection: + delay(2000); + } + + // Configure camera video channel with video format information + // Adjust the bitrate based on your WiFi network quality + //config.setBitrate(2 * 1024 * 1024); // Recommend to use 2Mbps for RTSP streaming to prevent network congestion + Camera.configVideoChannel(CHANNEL, config); + Camera.videoInit(); + + // Configure RTSP with identical video format information + rtsp.configVideo(config); + rtsp.begin(); + + // Configure StreamIO object to stream data from video channel to RTSP + videoStreamer.registerInput(Camera.getStream(CHANNEL)); + videoStreamer.registerOutput(rtsp); + if (videoStreamer.begin() != 0) { + Serial.println("StreamIO link start failed"); + } + + // Start data stream from video channel + Camera.channelBegin(CHANNEL); + + delay(1000); + printInfo(); +} + +void loop() { + if (Serial.available() > 0) { + String input = Serial.readString(); + input.trim(); + + if (input.startsWith(String("BRIGHTNESS="))) { + String value = input.substring(11); + int val = value.toInt(); + configCam.setBrightness(val); + } else if (input.startsWith(String("BRIGHTNESS"))) { + configCam.getBrightness(); + } else if (input.startsWith(String("CONTRAST="))) { + String value = input.substring(9); + int val = value.toInt(); + configCam.setContrast(val); + } else if (input.startsWith(String("CONTRAST"))) { + configCam.getContrast(); + } else if (input.startsWith(String("SATURATION="))) { + String value = input.substring(11); + int val = value.toInt(); + configCam.setSaturation(val); + } else if (input.startsWith(String("SATURATION"))) { + configCam.getSaturation(); + } else if (input.startsWith(String("SHARPNESS="))) { + String value = input.substring(10); + int val = value.toInt(); + configCam.setSharpness(val); + } else if (input.startsWith(String("SHARPNESS"))) { + configCam.getSharpness(); + } else if (input.startsWith(String("LDC="))) { + String value = input.substring(4); + int val = value.toInt(); + configCam.setLDC(val); + } else if (input.startsWith(String("LDC"))) { + configCam.getLDC(); + } else if (input.startsWith(String("RESET"))) { + configCam.reset(); + } + } +} + +void printInfo(void) { + Serial.println("------------------------------"); + Serial.println("- Summary of Streaming -"); + Serial.println("------------------------------"); + Camera.printInfo(); + + IPAddress ip = WiFi.localIP(); + + Serial.println("- RTSP -"); + Serial.print("rtsp://"); + Serial.print(ip); + Serial.print(":"); + rtsp.printInfo(); +} diff --git a/Arduino_package/hardware/libraries/Multimedia/examples/ISPControl/Mode/Mode.ino b/Arduino_package/hardware/libraries/Multimedia/examples/ISPControl/Mode/Mode.ino new file mode 100644 index 00000000..826c0d99 --- /dev/null +++ b/Arduino_package/hardware/libraries/Multimedia/examples/ISPControl/Mode/Mode.ino @@ -0,0 +1,104 @@ +/* + Example guide: + + // "DAYNIGHT=" Set Day/Night Mode: 0: Day, 1: Night + // "DAYNIGHT" Get value of DayNight Mode to determine whether is day or night mode + // "GRAY=" Set Gray Mode: 0: Color Mode, 1: Gray Mode + // "GRAY" Get value of Gray Mode to determine whether if it is gray mode + // "RESET" Reset to default +*/ + +#include "WiFi.h" +#include "StreamIO.h" +#include "VideoStream.h" +#include "RTSP.h" + +#define CHANNEL 0 + +// Default preset configurations for each video channel: +// Channel 0 : 1920 x 1080 30FPS H264 +// Channel 1 : 1280 x 720 30FPS H264 +// Channel 2 : 1280 x 720 30FPS MJPEG +CameraSetting configCam; +VideoSetting config(CHANNEL); +RTSP rtsp; +StreamIO videoStreamer(1, 1); // 1 Input Video -> 1 Output RTSP + +char ssid[] = "Network_SSID"; // your network SSID (name) +char pass[] = "Password"; // your network password +int status = WL_IDLE_STATUS; + +void setup() { + Serial.begin(115200); + + // attempt to connect to Wifi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to WPA SSID: "); + Serial.println(ssid); + status = WiFi.begin(ssid, pass); + + // wait 2 seconds for connection: + delay(2000); + } + + // Configure camera video channel with video format information + // Adjust the bitrate based on your WiFi network quality + //config.setBitrate(2 * 1024 * 1024); // Recommend to use 2Mbps for RTSP streaming to prevent network congestion + Camera.configVideoChannel(CHANNEL, config); + Camera.videoInit(); + + // Configure RTSP with identical video format information + rtsp.configVideo(config); + rtsp.begin(); + + // Configure StreamIO object to stream data from video channel to RTSP + videoStreamer.registerInput(Camera.getStream(CHANNEL)); + videoStreamer.registerOutput(rtsp); + if (videoStreamer.begin() != 0) { + Serial.println("StreamIO link start failed"); + } + + // Start data stream from video channel + Camera.channelBegin(CHANNEL); + + delay(1000); + printInfo(); +} + +void loop() { + if (Serial.available() > 0) { + String input = Serial.readString(); + input.trim(); + + if (input.startsWith(String("DAYNIGHT="))) { + String value = input.substring(9); + int val = value.toInt(); + configCam.setDayNightMode(val); + } else if (input.startsWith(String("DAYNIGHT"))) { + configCam.getDayNightMode(); + } else if (input.startsWith(String("GRAY="))){ + String value = input.substring(5); + int val = value.toInt(); + configCam.setGrayMode(val); + } else if (input.startsWith(String("GRAY"))) { + configCam.getGrayMode(); + } else if (input.startsWith(String("RESET"))) { + configCam.reset(); + } + } +} + +void printInfo(void) { + Serial.println("------------------------------"); + Serial.println("- Summary of Streaming -"); + Serial.println("------------------------------"); + Camera.printInfo(); + + IPAddress ip = WiFi.localIP(); + + Serial.println("- RTSP -"); + Serial.print("rtsp://"); + Serial.print(ip); + Serial.print(":"); + rtsp.printInfo(); +} diff --git a/Arduino_package/hardware/libraries/Multimedia/examples/ISPControl/WhiteBalance/WhiteBalance.ino b/Arduino_package/hardware/libraries/Multimedia/examples/ISPControl/WhiteBalance/WhiteBalance.ino new file mode 100644 index 00000000..acae4b51 --- /dev/null +++ b/Arduino_package/hardware/libraries/Multimedia/examples/ISPControl/WhiteBalance/WhiteBalance.ino @@ -0,0 +1,115 @@ +/* + Example guide: + + // "AWB=" Set Auto White Balance, 0:Manual, 1: Auto + // "AWB" Get value of Auto White Balance + // "RED=" Set Red balance gain: Range from 256 to 2047 + // "RED" Get Red balance gain + // "BLUE=" Set Blue balance gain: Range from 256 to 2047 + // "BLUE" Get Blue balance gain + // "WBTEMP=" Get White Balance Temperature + // "RESET" Reset to default +*/ + +#include "WiFi.h" +#include "StreamIO.h" +#include "VideoStream.h" +#include "RTSP.h" + +#define CHANNEL 0 + +// Default preset configurations for each video channel: +// Channel 0 : 1920 x 1080 30FPS H264 +// Channel 1 : 1280 x 720 30FPS H264 +// Channel 2 : 1280 x 720 30FPS MJPEG +CameraSetting configCam; +VideoSetting config(CHANNEL); +RTSP rtsp; +StreamIO videoStreamer(1, 1); // 1 Input Video -> 1 Output RTSP + +char ssid[] = "Network_SSID"; // your network SSID (name) +char pass[] = "Password"; // your network password +int status = WL_IDLE_STATUS; + +void setup() { + Serial.begin(115200); + + // attempt to connect to Wifi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to WPA SSID: "); + Serial.println(ssid); + status = WiFi.begin(ssid, pass); + + // wait 2 seconds for connection: + delay(2000); + } + + // Configure camera video channel with video format information + // Adjust the bitrate based on your WiFi network quality + //config.setBitrate(2 * 1024 * 1024); // Recommend to use 2Mbps for RTSP streaming to prevent network congestion + Camera.configVideoChannel(CHANNEL, config); + Camera.videoInit(); + + // Configure RTSP with identical video format information + rtsp.configVideo(config); + rtsp.begin(); + + // Configure StreamIO object to stream data from video channel to RTSP + videoStreamer.registerInput(Camera.getStream(CHANNEL)); + videoStreamer.registerOutput(rtsp); + if (videoStreamer.begin() != 0) { + Serial.println("StreamIO link start failed"); + } + + // Start data stream from video channel + Camera.channelBegin(CHANNEL); + + delay(1000); + printInfo(); +} + +void loop() { + if (Serial.available() > 0) { + String input = Serial.readString(); + input.trim(); + + if (input.startsWith(String("AWB="))) { + String value = input.substring(4); + int val = value.toInt(); + configCam.setAWB(val); + } else if (input.startsWith(String("AWB"))) { + configCam.getAWB(); + } else if (input.startsWith(String("RED="))) { + String value = input.substring(4); + int val = value.toInt(); + configCam.setRedBalance(val); + } else if (input.startsWith(String("RED"))) { + configCam.getRedBalance(); + } else if (input.startsWith(String("BLUE="))) { + String value = input.substring(5); + int val = value.toInt(); + configCam.setBlueBalance(val); + } else if (input.startsWith(String("BLUE"))) { + configCam.getBlueBalance(); + } else if (input.startsWith(String("WBTEMP"))) { + configCam.getWBTemp(); + } else if (input.startsWith(String("RESET"))) { + configCam.reset(); + } + } +} + +void printInfo(void) { + Serial.println("------------------------------"); + Serial.println("- Summary of Streaming -"); + Serial.println("------------------------------"); + Camera.printInfo(); + + IPAddress ip = WiFi.localIP(); + + Serial.println("- RTSP -"); + Serial.print("rtsp://"); + Serial.print(ip); + Serial.print(":"); + rtsp.printInfo(); +} diff --git a/Arduino_package/hardware/libraries/Multimedia/examples/ISPControl/WideDynamicRange/WideDynamicRange.ino b/Arduino_package/hardware/libraries/Multimedia/examples/ISPControl/WideDynamicRange/WideDynamicRange.ino new file mode 100644 index 00000000..afddafea --- /dev/null +++ b/Arduino_package/hardware/libraries/Multimedia/examples/ISPControl/WideDynamicRange/WideDynamicRange.ino @@ -0,0 +1,104 @@ +/* + Example guide: + + // "WDR=" Set Wide Dynamic Range, 0: Disabled, 1: Manual, 2: Auto + // "WDR" Get value of WDR + // "WDRLVL=" Set WDR level: Range from 0 to 100 + // "WDRLVL" Get WDR level + // "RESET" Reset to default +*/ + +#include "WiFi.h" +#include "StreamIO.h" +#include "VideoStream.h" +#include "RTSP.h" + +#define CHANNEL 0 + +// Default preset configurations for each video channel: +// Channel 0 : 1920 x 1080 30FPS H264 +// Channel 1 : 1280 x 720 30FPS H264 +// Channel 2 : 1280 x 720 30FPS MJPEG +CameraSetting configCam; +VideoSetting config(CHANNEL); +RTSP rtsp; +StreamIO videoStreamer(1, 1); // 1 Input Video -> 1 Output RTSP + +char ssid[] = "Network_SSID"; // your network SSID (name) +char pass[] = "Password"; // your network password +int status = WL_IDLE_STATUS; + +void setup() { + Serial.begin(115200); + + // attempt to connect to Wifi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to WPA SSID: "); + Serial.println(ssid); + status = WiFi.begin(ssid, pass); + + // wait 2 seconds for connection: + delay(2000); + } + + // Configure camera video channel with video format information + // Adjust the bitrate based on your WiFi network quality + //config.setBitrate(2 * 1024 * 1024); // Recommend to use 2Mbps for RTSP streaming to prevent network congestion + Camera.configVideoChannel(CHANNEL, config); + Camera.videoInit(); + + // Configure RTSP with identical video format information + rtsp.configVideo(config); + rtsp.begin(); + + // Configure StreamIO object to stream data from video channel to RTSP + videoStreamer.registerInput(Camera.getStream(CHANNEL)); + videoStreamer.registerOutput(rtsp); + if (videoStreamer.begin() != 0) { + Serial.println("StreamIO link start failed"); + } + + // Start data stream from video channel + Camera.channelBegin(CHANNEL); + + delay(1000); + printInfo(); +} + +void loop() { + if (Serial.available() > 0) { + String input = Serial.readString(); + input.trim(); + + if (input.startsWith(String("WDR="))) { + String value = input.substring(4); + int val = value.toInt(); + configCam.setWDR(val); + } else if (input.startsWith(String("WDR"))) { + configCam.getWDR(); + } else if (input.startsWith(String("LEVEL="))) { // Preferred Wide Dynamic Range level take effect only if WDR is set to Manual + String value = input.substring(6); + int val = value.toInt(); + configCam.setWDRLevel(val); + } else if (input.startsWith(String("LEVEL"))) { + configCam.getWDRLevel(); + } else if (input.startsWith(String("RESET"))) { + configCam.reset(); + } + } +} + +void printInfo(void) { + Serial.println("------------------------------"); + Serial.println("- Summary of Streaming -"); + Serial.println("------------------------------"); + Camera.printInfo(); + + IPAddress ip = WiFi.localIP(); + + Serial.println("- RTSP -"); + Serial.print("rtsp://"); + Serial.print(ip); + Serial.print(":"); + rtsp.printInfo(); +} diff --git a/Arduino_package/hardware/libraries/Multimedia/src/VideoStream.cpp b/Arduino_package/hardware/libraries/Multimedia/src/VideoStream.cpp index 714b193b..947a09a8 100644 --- a/Arduino_package/hardware/libraries/Multimedia/src/VideoStream.cpp +++ b/Arduino_package/hardware/libraries/Multimedia/src/VideoStream.cpp @@ -6,6 +6,7 @@ extern "C" { #endif #include "video_drv.h" +#include "isp_ctrl_api.h" #ifdef __cplusplus } @@ -16,6 +17,323 @@ Video Camera; uint32_t Video::image_addr[4] = {0}; uint32_t Video::image_len[4] = {0}; +// (Image Tuning) +void CameraSetting::setBrightness(int value) { + if (value >= BRIGHTNESS_MIN && value <= BRIGHTNESS_MAX) { + isp_set_brightness(value); + printf("[INFO] Brightness is set to %d. \n", value); + } else { + printf("[ERROR] Invalid Input. \r\n"); + } +} + +void CameraSetting::getBrightness(void) { + isp_get_brightness(&ret); + printf("[INFO] Brightness = %d \n", ret); +} + +void CameraSetting::setContrast(int value) { + if (value >= CONTRAST_MIN && value <= CONTRAST_MAX) { + isp_set_contrast(value); + printf("[INFO] Contrast is set to %d. \n", value); + } else { + printf("[ERROR] Invalid Input. \r\n"); + } +} + +void CameraSetting::getContrast(void) { + isp_get_contrast(&ret); + printf("[INFO] Contrast = %d \n", ret); +} + +void CameraSetting::setSaturation(int value) { + if (value >= SATURATION_MIN && value <= SATURATION_MAX) { + isp_set_saturation(value); + printf("[INFO] Saturation is set to %d. \n", value); + } else { + printf("[ERROR] Invalid Input. \r\n"); + } +} + +void CameraSetting::getSaturation(void) { + isp_get_saturation(&ret); + printf("[INFO] Saturation = %d \n", ret); +} + +void CameraSetting::setSharpness(int value) { + if (value >= SHARPNESS_MIN && value <= SHARPNESS_MAX) { + isp_set_sharpness(value); + printf("[INFO] Sharpness is set to %d. \n", value); + } else { + printf("[ERROR] Invalid Input. \r\n"); + } +} + +void CameraSetting::getSharpness(void) { + isp_get_sharpness(&ret); + printf("[INFO] Sharpness = %d \n", ret); +} + +// Len Distortion Correction +void CameraSetting::setLDC(int enable) { + isp_set_ldc(enable); + if (enable == 0) { + printf("[INFO] Len Distortion Correction is Disabled. \n"); + } else if (enable == 1) { + printf("[INFO] Len Distortion Correction is Enabled. \n"); + } else { + printf("[ERROR] Invalid Input. \r\n"); + } +} + +void CameraSetting::getLDC(void) { + isp_get_ldc(&ret); + if (ret == 0) { + printf("[INFO] Len Distortion Correction is Disabled. \n"); + } else if (ret == 1) { + printf("[INFO] Len Distortion Correction is Enabled. \n"); + } +} + +// Wide Dynamic Range +void CameraSetting::setWDR(int enable) { + isp_set_wdr_mode(enable); + if (enable== 0) { + printf("[INFO] Wide Dynamic Range is Disabled. \n"); + } else if (enable == 1) { + printf("[INFO] Wide Dynamic Range is set to Manual. \n"); + } else if (enable == 2) { + printf("[INFO] Wide Dynamic Range is set to Auto. \n"); + } else { + printf("[ERROR] Invalid Input. \r\n"); + } +} + +void CameraSetting::getWDR(void) { + isp_get_wdr_mode(&ret); + if (ret == 0) { + printf("[INFO] Wide Dynamic Range = Disabled \n"); + } else if (ret == 1) { + printf("[INFO] Wide Dynamic Range = Manual \n"); + } else if (ret == 2) { + printf("[INFO] Wide Dynamic Range = Auto \n"); + } +} + +void CameraSetting::setWDRLevel(int value) { + getWDR(); + if (ret == 1) { + if (value >= 50 && value <= 100) { + isp_set_wdr_level(value); + printf("[INFO] WDR level is set to %d. \n", value); + } else { + printf("[INFO] Invalid value. WDR level value should be between 50 to 100. \n"); + } + } else { + printf("[ERROR] Please set WDR to Manual to set the WDR level manually. \n"); + } +} + +void CameraSetting::getWDRLevel(void) { + isp_get_wdr_level(&ret); + printf("[INFO] WDR level = %d \r\n", ret); +} + +// AE (Auto Exposure) +void CameraSetting::setExposureMode(int enable) { + isp_set_exposure_mode(enable); + if (enable == 0) { + printf("[INFO] Exposure Mode is set to Manual. \r\n"); + } else if (enable == 1) { + printf("[INFO] Exposure Mode is set to Auto. \r\n"); + } else { + printf("[ERROR] Invalid Input. \r\n"); + } +} + +void CameraSetting::getExposureMode(void) { + isp_get_exposure_mode(&ret); + if (ret == 0) { + printf("[INFO] Exposure Mode = Manual \r\n"); + } else if (ret == 1) { + printf("[INFO] Exposure Mode = Auto \r\n"); + } +} + +void CameraSetting::setExposureTime(int time) { // duration in us + getExposureMode(); + if (ret == 0) { + if (time <= EXPOSURETIME_MAX) { + isp_set_exposure_time(time); + printf("[INFO] Exposure time is set to %dus.\r\n", time); + } else { + printf ("[ERROR] Exposure Time should be less than or equals to 33333us. \r\n"); + } + } else { + printf("[ERROR] Please set Exposure Mode to Manual to set the Exposure Time manually. \r\n"); + } +} + +void CameraSetting::getExposureTime(void) { // duration in us + isp_get_exposure_time(&ret); + printf("[INFO] Exposure time = %dus \r\n", ret); +} + +void CameraSetting::setAEGain(int value) { + getExposureMode(); + if (ret == 0) { + if (value >= AEGAIN_MIN && value <= AEGAIN_MAX) { + isp_set_ae_gain(value); + printf("[INFO] AE Gain is set to %d.\r\n", value); + } else { + printf("[ERROR] Invalid Input. \r\n"); + } + } else if (ret == 1) { + printf("[ERROR] Please set Exposure Mode to Manual to set the AE Gain manually. \r\n"); + } +} + +void CameraSetting::getAEGain(void) { + isp_get_ae_gain(&ret); + printf("[INFO] AE Gain = %d \r\n", ret); +} + +void CameraSetting::setPowerLineFreq(int value) { + isp_set_power_line_freq(value); + if (value == 0) { + printf("[INFO] Power Line Frequency is disabled. \r\n"); + } else if (value == 1) { + printf("[INFO] Power Line Frequency is 50Hz. \r\n"); + } else if (value == 2) { + printf("[INFO] Power Line Frequency is 60Hz. \r\n"); + } else if (value == 3) { + printf("[INFO] Power Line Frequency is Auto. \r\n"); + } +} + +void CameraSetting::getPowerLineFreq(void) { + isp_get_power_line_freq(&ret); + if (ret == 0) { + printf("[INFO] Power Line Frequency = disabled. \r\n"); + } else if (ret == 1) { + printf("[INFO] Power Line Frequency = 50Hz. \r\n"); + } else if (ret == 2) { + printf("[INFO] Power Line Frequency = 60Hz. \r\n"); + } else if (ret == 3) { + printf("[INFO] Power Line Frequency = Auto. \r\n"); + } +} + +// AWB (Auto White Balance) +void CameraSetting::setAWB(int enable) { + isp_set_awb_ctrl(enable); + if (enable == 0) { + printf("[INFO] Auto White Balance is set to Manual. \r\n"); + } else if (enable == 1) { + printf("[INFO] Auto White Balance is set to Auto. \r\n"); + } else { + printf("[ERROR] Invalid Input. \r\n"); + } +} + +void CameraSetting::getAWB(void) { + isp_get_awb_ctrl(&ret); + if (ret == 0) { + printf("[INFO] Auto White Balance = Manual. \r\n"); + } else if (ret == 1) { + printf("[INFO] Auto White Balance = Auto. \r\n"); + } +} + +void CameraSetting::getWBTemp(void) { + isp_get_wb_temperature(&ret); + printf("[INFO] White Balance Temperature = %d \r\n", ret); +} + +void CameraSetting::setRedBalance(int value) { + getAWB(); + if (ret == 0) { + if (value >= REDBALANCE_MIN && value <= REDBALANCE_MAX) { + isp_set_red_balance(value); + printf("[INFO] Red balance is set to %d. \r\n", value); + } else { + printf("[ERROR] Invalid Input. \r\n"); + } + } else { + printf("[ERROR] Please set AWB to Manual to adjust the temperature manually. \r\n"); + } +} + +void CameraSetting::getRedBalance(void) { + isp_get_red_balance(&ret); + printf("[INFO] Red balance = %d \r\n", ret); +} + +void CameraSetting::setBlueBalance(int value) { + getAWB(); + if (ret == 0) { + if (value >= BLUEBALANCE_MIN && value <= BLUEBALANCE_MAX) { + isp_set_blue_balance(value); + printf("[INFO] Blue balance is set to %d. \r\n", value); + } else { + printf("[ERROR] Invalid Input. \r\n"); + } + } else if (ret == 1) { + printf("[ERROR] Please set AWB to Manual to adjust the temperature manually. \r\n"); + } +} + +void CameraSetting::getBlueBalance(void) { + isp_get_blue_balance(&ret); + printf("[INFO] Blue balance = %d \r\n", ret); +} + +// Mode +void CameraSetting::setGrayMode(int enable) { + isp_set_gray_mode(enable); + if (enable == 0) { + printf("[INFO] Not Gray Mode \r\n"); + } else if (enable == 1) { + printf("[INFO] Gray Mode \r\n"); + } else { + printf("[ERROR] Invalid Input. \r\n"); + } +} + +void CameraSetting::getGrayMode(void) { + isp_get_gray_mode(&ret); + if (ret == 0) { + printf("[INFO] Not Gray Mode \r\n"); + } else if (ret == 1) { + printf("[INFO] Gray Mode \r\n"); + } +} + +void CameraSetting::setDayNightMode(int enable) { + isp_set_day_night(enable); + if (enable == 0) { + printf("[INFO] Day Mode \r\n"); + } else if (enable == 1) { + printf("[INFO] Night Mode \r\n"); + } else { + printf("[ERROR] Invalid Input. \r\n"); + } +} + +void CameraSetting::getDayNightMode(void) { + isp_get_day_night(&ret); + if (ret == 0) { + printf("[INFO] Day Mode \r\n"); + } else if (ret == 1) { + printf("[INFO] Night Mode \r\n"); + } +} + +void CameraSetting::reset(void) { + ISPControlReset(); + printf("[INFO] ISP Control Reset. \r\n"); +} + VideoSetting::VideoSetting(uint8_t preset) { switch (preset) { case 0: { diff --git a/Arduino_package/hardware/libraries/Multimedia/src/VideoStream.h b/Arduino_package/hardware/libraries/Multimedia/src/VideoStream.h index 4708bfb3..1d10fd45 100644 --- a/Arduino_package/hardware/libraries/Multimedia/src/VideoStream.h +++ b/Arduino_package/hardware/libraries/Multimedia/src/VideoStream.h @@ -96,6 +96,23 @@ enum encode_type { #define v3_STREAMING_ID 2 #define v4_STREAMING_ID 4 +// ISP control max and min values +#define BRIGHTNESS_MIN -64 +#define BRIGHTNESS_MAX 64 +#define CONTRAST_MIN 0 +#define CONTRAST_MAX 100 +#define SATURATION_MIN 0 +#define SATURATION_MAX 100 +#define SHARPNESS_MIN 0 +#define SHARPNESS_MAX 100 +#define EXPOSURETIME_MAX 33333 +#define AEGAIN_MIN 256 +#define AEGAIN_MAX 32768 +#define REDBALANCE_MIN 256 +#define REDBALANCE_MAX 2047 +#define BLUEBALANCE_MIN 256 +#define BLUEBALANCE_MAX 2047 + class MMFModule { friend class StreamIO; friend class Video; @@ -107,7 +124,46 @@ class MMFModule { }; class CameraSetting { - // To be done + friend class Video; + + public: + void reset(void); + void setBrightness(int value); + void getBrightness(void); + void setContrast(int value); + void getContrast(void); + void setSaturation(int value); + void getSaturation(void); + void setSharpness(int value); + void getSharpness(void); + void setLDC(int enable); + void getLDC(void); + void setWDR(int enable); + void getWDR(void); + void setWDRLevel(int value); + void getWDRLevel(void); + void setExposureMode(int enable); + void getExposureMode(void); + void setExposureTime(int time); + void getExposureTime(void); + void setAEGain(int value); + void getAEGain(void); + void setPowerLineFreq(int value); + void getPowerLineFreq(void); + void setAWB(int AWBMode); + void getAWB(void); + void getWBTemp(void); + void setRedBalance(int value); + void getRedBalance(void); + void setBlueBalance(int value); + void getBlueBalance(void); + void setGrayMode(int enable); + void getGrayMode(void); + void setDayNightMode(int enable); + void getDayNightMode(void); + + private: + int ret = 0; }; class VideoSetting {