Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implementation of shutterspeed, awb red gain, awb blue gain in still mode #9

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 50 additions & 1 deletion src/private_still/private_still_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,11 @@ namespace raspicam {
//videoStabilisation = 0;
//exposureCompensation = 0;
exposure = RASPICAM_EXPOSURE_AUTO;
shutterSpeed = 0;
metering = RASPICAM_METERING_AVERAGE;
awb = RASPICAM_AWB_AUTO;
awbg_red = 1.0f;
awbg_blue = 1.0f;
imageEffect = RASPICAM_IMAGE_EFFECT_NONE;
//colourEffects.enable = 0;
//colourEffects.u = 128;
Expand All @@ -150,7 +153,9 @@ namespace raspicam {
commitSaturation();
commitISO();
commitExposure();
commitShutterSpeed();
commitMetering();
commitAWB_RB();
commitAWB();
commitImageEffect();
commitRotation();
Expand Down Expand Up @@ -540,11 +545,25 @@ namespace raspicam {
changedSettings = true;
}

void Private_Impl_Still::setShutterSpeed ( unsigned int shutter ) {
// TODO : Verify the highest value, currently based on video implementation for now
if ( shutter > 330000 )
shutter = 330000;
this->shutterSpeed= shutter;
changedSettings = true;
}

void Private_Impl_Still::setAWB ( RASPICAM_AWB awb ) {
this->awb = awb;
changedSettings = true;
}

void Private_Impl_Still::setAWB_RB ( float red_g, float blue_g ) {
this->awbg_blue = blue_g;
this->awbg_red = red_g;
changedSettings = true;
}

void Private_Impl_Still::setImageEffect ( RASPICAM_IMAGE_EFFECT imageEffect ) {
this->imageEffect = imageEffect;
changedSettings = true;
Expand Down Expand Up @@ -609,10 +628,22 @@ namespace raspicam {
return exposure;
}

unsigned int Private_Impl_Still::getShutterSpeed() {
return shutterSpeed;
}

RASPICAM_AWB Private_Impl_Still::getAWB() {
return awb;
}

float Private_Impl_Still::getAWBG_red() {
return awbg_red;
}

float Private_Impl_Still::getAWBG_blue() {
return awbg_blue;
}

RASPICAM_IMAGE_EFFECT Private_Impl_Still::getImageEffect() {
return imageEffect;
}
Expand All @@ -631,7 +662,7 @@ namespace raspicam {

void Private_Impl_Still::commitBrightness() {
mmal_port_parameter_set_rational ( camera->control, MMAL_PARAMETER_BRIGHTNESS, ( MMAL_RATIONAL_T ) {
brightness, 100
(int32_t)brightness, 100
} );
}

Expand Down Expand Up @@ -679,12 +710,26 @@ namespace raspicam {
cout << API_NAME << ": Failed to set exposure parameter.\n";
}

void Private_Impl_Still::commitShutterSpeed() {
if ( mmal_port_parameter_set_uint32 ( camera->control, MMAL_PARAMETER_SHUTTER_SPEED, this->shutterSpeed ) != MMAL_SUCCESS )
cout << __func__ << ": Failed to set shutter parameter.\n";
}

void Private_Impl_Still::commitAWB() {
MMAL_PARAMETER_AWBMODE_T param = {{MMAL_PARAMETER_AWB_MODE,sizeof ( param ) }, convertAWB ( awb ) };
if ( mmal_port_parameter_set ( camera->control, &param.hdr ) != MMAL_SUCCESS )
cout << API_NAME << ": Failed to set AWB parameter.\n";
}

void Private_Impl_Still::commitAWB_RB() {
MMAL_PARAMETER_AWB_GAINS_T param = {{MMAL_PARAMETER_CUSTOM_AWB_GAINS,sizeof(param)}, {0,0}, {0,0}};
param.r_gain.num = (unsigned int)(100 * awbg_red);
param.b_gain.num = (unsigned int)(100 * awbg_blue);
param.r_gain.den = param.b_gain.den = 100;
if ( mmal_port_parameter_set(camera->control, &param.hdr) != MMAL_SUCCESS )
cout << __func__ << ": Failed to set AWBG gains parameter.\n";
}

void Private_Impl_Still::commitImageEffect() {
MMAL_PARAMETER_IMAGEFX_T imgFX = {{MMAL_PARAMETER_IMAGE_EFFECT,sizeof ( imgFX ) }, convertImageEffect ( imageEffect ) };
if ( mmal_port_parameter_set ( camera->control, &imgFX.hdr ) != MMAL_SUCCESS )
Expand Down Expand Up @@ -845,7 +890,11 @@ namespace raspicam {
return MMAL_PARAM_IMAGEFX_COLOURBALANCE;
case RASPICAM_IMAGE_EFFECT_CARTOON:
return MMAL_PARAM_IMAGEFX_CARTOON;
default:
cout << API_NAME << ": Could not convert given value to image effect, returned MMAL_PARAM_IMAGEFX_NONE.\n";
return MMAL_PARAM_IMAGEFX_NONE;
}

}

//Returns an id of the camera. We assume the camera id is the one of the raspberry
Expand Down
10 changes: 10 additions & 0 deletions src/private_still/private_still_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ namespace raspicam {
unsigned int rotation; // 0 to 359
unsigned int brightness; // 0 to 100
unsigned int quality; // 0 to 100
unsigned int shutterSpeed;
float awbg_red;
float awbg_blue;
int iso;
int sharpness; // -100 to 100
int contrast; // -100 to 100
Expand All @@ -91,6 +94,8 @@ namespace raspicam {
void commitContrast();
void commitSaturation();
void commitExposure();
void commitShutterSpeed();
void commitAWB_RB();
void commitAWB();
void commitImageEffect();
void commitMetering();
Expand Down Expand Up @@ -140,7 +145,9 @@ namespace raspicam {
void setSaturation ( int saturation );
void setEncoding ( RASPICAM_ENCODING encoding );
void setExposure ( RASPICAM_EXPOSURE exposure );
void setShutterSpeed ( unsigned int shutter );
void setAWB ( RASPICAM_AWB awb );
void setAWB_RB ( float red, float blue );
void setImageEffect ( RASPICAM_IMAGE_EFFECT imageEffect );
void setMetering ( RASPICAM_METERING metering );
void setHorizontalFlip ( bool hFlip );
Expand All @@ -157,7 +164,10 @@ namespace raspicam {
int getSaturation();
RASPICAM_ENCODING getEncoding();
RASPICAM_EXPOSURE getExposure();
unsigned int getShutterSpeed();
RASPICAM_AWB getAWB();
float getAWBG_red();
float getAWBG_blue();
RASPICAM_IMAGE_EFFECT getImageEffect();
RASPICAM_METERING getMetering();
bool isHorizontallyFlipped();
Expand Down
32 changes: 30 additions & 2 deletions src/raspicam_still.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,25 @@ namespace raspicam {
void RaspiCam_Still::setExposure ( RASPICAM_EXPOSURE exposure ) {
_impl->setExposure ( exposure );
}
void RaspiCam_Still::setShutterSpeed(unsigned int ss) {
if (ss > 0) {
if (_impl->getExposure() != RASPICAM_EXPOSURE_OFF)
{
_impl->setExposure(RASPICAM_EXPOSURE_OFF);
}
_impl->setShutterSpeed(ss);
}
else {
_impl->setExposure(RASPICAM_EXPOSURE_AUTO);
_impl->setShutterSpeed(0);
}
}
void RaspiCam_Still::setAWB ( RASPICAM_AWB awb ) {
_impl->setAWB ( awb );
}
void RaspiCam_Still::setAWB_RB(float r, float b) {
_impl->setAWB_RB( r, b );
}
void RaspiCam_Still::setImageEffect ( RASPICAM_IMAGE_EFFECT imageEffect ) {
_impl-> setImageEffect ( imageEffect );
}
Expand Down Expand Up @@ -146,12 +162,24 @@ namespace raspicam {
RASPICAM_ENCODING RaspiCam_Still::getEncoding() {
return _impl->getEncoding();
}
RASPICAM_EXPOSURE RaspiCam_Still::getExposure() {
unsigned int RaspiCam_Still::getShutterSpeed() const {
if ( _impl->getShutterSpeed() == 0 )
return _impl->getExposure();
else
return _impl->getShutterSpeed();
}
RASPICAM_EXPOSURE RaspiCam_Still::getExposure() const {
return _impl->getExposure ();
}
RASPICAM_AWB RaspiCam_Still::getAWB() {
RASPICAM_AWB RaspiCam_Still::getAWB() const {
return _impl->getAWB();
}
float RaspiCam_Still::getAWBG_red() const {
return _impl->getAWBG_red();
}
float RaspiCam_Still::getAWBG_blue() const {
return _impl->getAWBG_blue();
}
RASPICAM_IMAGE_EFFECT RaspiCam_Still::getImageEffect() {
return _impl->getImageEffect();
}
Expand Down
10 changes: 8 additions & 2 deletions src/raspicam_still.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ namespace raspicam {
void setSaturation ( int saturation );
void setEncoding ( RASPICAM_ENCODING encoding );
void setExposure ( RASPICAM_EXPOSURE exposure );
void setShutterSpeed ( unsigned int ss );
void setAWB ( RASPICAM_AWB awb );
// set specific values for whitebalance. Requires to set AWB in OFF mode first using setAWB
void setAWB_RB ( float r, float b );//range is 0-1.
void setImageEffect ( RASPICAM_IMAGE_EFFECT imageEffect );
void setMetering ( RASPICAM_METERING metering );
void setHorizontalFlip ( bool hFlip );
Expand All @@ -98,8 +101,11 @@ namespace raspicam {
int getContrast();
int getSaturation();
RASPICAM_ENCODING getEncoding();
RASPICAM_EXPOSURE getExposure();
RASPICAM_AWB getAWB();
unsigned int getShutterSpeed() const;
RASPICAM_EXPOSURE getExposure() const;
RASPICAM_AWB getAWB() const;
float getAWBG_red() const;
float getAWBG_blue() const;
RASPICAM_IMAGE_EFFECT getImageEffect();
RASPICAM_METERING getMetering();
bool isHorizontallyFlipped();
Expand Down
59 changes: 49 additions & 10 deletions src/raspicam_still_cv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,16 @@ namespace raspicam {
case CV_CAP_PROP_GAIN :
return Scaler::scale ( 0,800,0,100, _impl->getISO() );
case CV_CAP_PROP_EXPOSURE :
// if ( _impl->getShutterSpeed() ==0 )
return -1;//not yet
// else return Scaler::scale (0,330000, 0,100, _impl->getShutterSpeed() ) ;
break;
if ( _impl->getShutterSpeed() ==0 )
return _impl->getExposure();
else
return _impl->getShutterSpeed();
case CAP_PROP_AUTO_WB :
return _impl->getAWB();
case CV_CAP_PROP_WHITE_BALANCE_RED_V:
return _impl->getAWBG_red();
case CV_CAP_PROP_WHITE_BALANCE_BLUE_U:
return _impl->getAWBG_blue();
case CV_CAP_PROP_CONVERT_RGB :
return ( true );
// case CV_CAP_PROP_WHITE_BALANCE :return _cam_impl->getAWB();
Expand Down Expand Up @@ -170,16 +176,49 @@ namespace raspicam {
_impl->setISO ( Scaler::scale ( 0,100,0,800, value ) );
break;
case CV_CAP_PROP_EXPOSURE :
// if ( value>0 && value<=100 ) {
// _impl->setShutterSpeed ( Scaler::scale ( 0,100,0,330000, value ) );
// } else {
// _impl->setExposure ( RASPICAM_EXPOSURE_AUTO );
// _impl->setShutterSpeed ( 0 );
// }
if ( value > 0 ) {
if( _impl->getExposure () != RASPICAM_EXPOSURE_OFF ) {
_impl->setExposure ( RASPICAM_EXPOSURE_OFF );
}
_impl->setShutterSpeed ( value );
} else {
_impl->setExposure ( RASPICAM_EXPOSURE_AUTO );
_impl->setShutterSpeed ( 0 );
}
break;
case CV_CAP_PROP_CONVERT_RGB :
// CV_8UC3;
break;

case CAP_PROP_AUTO_WB:
if ( value>0 && value<=9 ) {
_impl->setAWB(raspicam::RASPICAM_AWB(value));
}
else {
_impl->setAWB(raspicam::RASPICAM_AWB_AUTO);
};
break;
case CV_CAP_PROP_WHITE_BALANCE_RED_V:
if ( value>0 && value<=8 ) {
float valblue=_impl->getAWBG_blue();
_impl->setAWB(raspicam::RASPICAM_AWB_OFF);
_impl->setAWB_RB(value, valblue );
}
else {
_impl->setAWB(raspicam::RASPICAM_AWB_AUTO);
};
break;

case CV_CAP_PROP_WHITE_BALANCE_BLUE_U:
if ( value>0 && value<=8 ) {
float valred=_impl->getAWBG_red();
_impl->setAWB(raspicam::RASPICAM_AWB_OFF);
_impl->setAWB_RB(valred, value );
}
else {
_impl->setAWB(raspicam::RASPICAM_AWB_AUTO);
};
break;
// case CV_CAP_PROP_WHITE_BALANCE :return _cam_impl->getAWB();
default :
return false;
Expand Down