BitmapToolkit Scol plugin
raspicam_cv.cpp
Go to the documentation of this file.
1/**********************************************************
2 Software developed by AVA ( Ava Group of the University of Cordoba, ava at uco dot es)
3 Main author Rafael Munoz Salinas (rmsalinas at uco dot es)
4 This software is released under BSD license as expressed below
5-------------------------------------------------------------------
6Copyright (c) 2013, AVA ( Ava Group University of Cordoba, ava at uco dot es)
7All rights reserved.
8
9Redistribution and use in source and binary forms, with or without
10modification, are permitted provided that the following conditions
11are met:
121. Redistributions of source code must retain the above copyright
13 notice, this list of conditions and the following disclaimer.
142. Redistributions in binary form must reproduce the above copyright
15 notice, this list of conditions and the following disclaimer in the
16 documentation and/or other materials provided with the distribution.
173. All advertising materials mentioning features or use of this software
18 must display the following acknowledgement:
19
20 This product includes software developed by the Ava group of the University of Cordoba.
21
224. Neither the name of the University nor the names of its contributors
23 may be used to endorse or promote products derived from this software
24 without specific prior written permission.
25
26THIS SOFTWARE IS PROVIDED BY AVA ''AS IS'' AND ANY
27EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
28WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29DISCLAIMED. IN NO EVENT SHALL AVA BE LIABLE FOR ANY
30DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
33ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36****************************************************************/
37
40#include "raspicam/scaler.h"
41
42#include <iostream>
43#include <opencv2/imgproc.hpp>
44
45namespace raspicam {
47 _impl=new _private::Private_Impl();
48 set(cv::CAP_PROP_FORMAT, CV_8UC3);
49
50 }
52 delete _impl;
53 }
54
57 bool RaspiCam_Cv::open ( void ) {
58 return _impl->open();
59 }
63 bool RaspiCam_Cv::isOpened() const {return _impl->isOpened();}
68 _impl->release();
69 }
70
75 return _impl->grab();
76 }
77
81 void RaspiCam_Cv::retrieve ( cv::Mat& image ) {
82 //here we go!
83 image.create ( _impl->getHeight(),_impl->getWidth(),imgFormat );
84 _impl->retrieve ( image.ptr<uchar> ( 0 ));
85 }
86
87 bool RaspiCam_Cv::read(cv::Mat& image)
88 {
89 if (!grab())
90 return true;
91
92 retrieve(image);
93 if (image.empty())
94 return false;
95
96 return true;
97 }
98
102 double RaspiCam_Cv::get ( int propId ) {
103
104 switch ( propId ) {
105
106 case cv::CAP_PROP_FRAME_WIDTH:
107 return _impl->getWidth();
108 case cv::CAP_PROP_FRAME_HEIGHT:
109 return _impl->getHeight();
110 case cv::CAP_PROP_FPS:
111 return 30;
112 case cv::CAP_PROP_FORMAT:
113 return imgFormat;
114 case cv::CAP_PROP_MODE:
115 return 0;
116 case cv::CAP_PROP_BRIGHTNESS:
117 return _impl->getBrightness();
118 case cv::CAP_PROP_CONTRAST:
119 return Scaler::scale ( -100,100,0,100, _impl->getContrast() );
120 case cv::CAP_PROP_SATURATION:
121 return Scaler::scale ( -100,100,0,100, _impl->getSaturation() );;
122// case CV_CAP_PROP_HUE : return _cam_impl->getSharpness();
123 case cv::CAP_PROP_GAIN:
124 return Scaler::scale ( 0,800,0,100, _impl->getISO() );
125 case cv::CAP_PROP_EXPOSURE:
126 if ( _impl->getShutterSpeed() ==0 )
127 return -1;//auto
128 else return Scaler::scale (0,330000, 0,100, _impl->getShutterSpeed() ) ;
129 break;
130 case cv::CAP_PROP_CONVERT_RGB:
131 return ( imgFormat==CV_8UC3 );
132 case cv::CAP_PROP_WHITE_BALANCE_RED_V:
133 if( _impl->getAWB()== raspicam::RASPICAM_AWB_AUTO)
134 return -1;//auto
135 else
136 return _impl->getAWBG_red() / 100.0f;
137 break;
138
139 case cv::CAP_PROP_WHITE_BALANCE_BLUE_U:
140 if( _impl->getAWB()== raspicam::RASPICAM_AWB_AUTO)
141 return -1;//auto
142 else
143 return _impl->getAWBG_blue() / 100.0f;
144 break;
145 default :
146 return -1;
147 };
148 }
149
153 bool RaspiCam_Cv::set ( int propId, double value ) {
154
155 switch ( propId ) {
156
157 case cv::CAP_PROP_FRAME_WIDTH:
158 _impl->setWidth ( value );
159 break;
160 case cv::CAP_PROP_FRAME_HEIGHT:
161 _impl->setHeight ( value );
162 break;
163 case cv::CAP_PROP_FORMAT: {
164 bool res=true;
165 if ( value==CV_8UC1 ){
167 imgFormat=value;
168 }
169 else if (value==CV_8UC3){
171 imgFormat=value;
172 }
173 else res=false;//error int format
174 return res;
175 }break;
176 case cv::CAP_PROP_MODE://nothing to do yet
177 return false;
178 break;
179 case cv::CAP_PROP_BRIGHTNESS:
180 _impl->setBrightness ( value );
181 break;
182 case cv::CAP_PROP_CONTRAST:
183 _impl->setContrast ( Scaler::scale ( 0,100,-100,100, value ) );
184 break;
185 case cv::CAP_PROP_SATURATION:
186 _impl->setSaturation ( Scaler::scale ( 0,100,-100,100, value ) );
187 break;
188// case CV_CAP_PROP_HUE : return _cam_impl->getSharpness();
189 case cv::CAP_PROP_GAIN:
190 _impl->setISO ( Scaler::scale ( 0,100,0,800, value ) );
191 break;
192 case cv::CAP_PROP_EXPOSURE:
193 if ( value>0 && value<=100 ) {
194 _impl->setShutterSpeed ( Scaler::scale ( 0,100,0,330000, value ) );
195 }
196 else {
198 _impl->setShutterSpeed ( 0 );
199 }
200 break;
201 case cv::CAP_PROP_CONVERT_RGB:
202 imgFormat=CV_8UC3;
203 break;
204 case cv::CAP_PROP_WHITE_BALANCE_RED_V:
205 if ( value>0 && value<=100 ) {
206 float valblue=_impl->getAWBG_blue();
208 _impl->setAWB_RB(value*100, valblue );
209 }
210 else {
212 };
213 break;
214
215 case cv::CAP_PROP_WHITE_BALANCE_BLUE_U:
216 if ( value>0 && value<=100 ) {
217 float valred=_impl->getAWBG_red();
219 _impl->setAWB_RB(valred, value*100 );
220 }
221 else {
223 };
224 break;
225
226// case CV_CAP_PROP_WHITE_BALANCE :return _cam_impl->getAWB();
227 default :
228 return false;
229 };
230 return true;
231
232 }
233 std::string RaspiCam_Cv::getId() const{
234 return _impl->getId();
235 }
236
237}
unsigned int getWidth() const
void setHeight(unsigned int height)
void setFormat(RASPICAM_FORMAT fmt)
void setWidth(unsigned int width)
unsigned int getHeight() const
unsigned int getBrightness() const
void setBrightness(unsigned int brightness)
void setAWB_RB(float red, float blue)
void setExposure(RASPICAM_EXPOSURE exposure)
void setShutterSpeed(unsigned int shutter)
bool open(bool StartCapture=true)
void setAWB(RASPICAM_AWB awb)
void setSaturation(int saturation)
void retrieve(unsigned char *data, RASPICAM_FORMAT type=RASPICAM_FORMAT_IGNORE)
bool read(cv::Mat &image)
double get(int propId)
std::string getId() const
void retrieve(cv::Mat &image)
bool set(int propId, double value)
static float scale(float inMin, float inMax, float outMin, float outMax, float val)
Definition scaler.h:41
@ RASPICAM_AWB_AUTO
@ RASPICAM_EXPOSURE_AUTO
@ RASPICAM_FORMAT_BGR
@ RASPICAM_FORMAT_GRAY