/********************************************************** Software developed by AVA ( Ava Group of the University of Cordoba, ava at uco dot es) Main author Rafael Munoz Salinas (rmsalinas at uco dot es) This software is released under BSD license as expressed below ------------------------------------------------------------------- Copyright (c) 2013, AVA ( Ava Group University of Cordoba, ava at uco dot es) All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. All advertising materials mentioning features or use of this software must display the following acknowledgement: This product includes software developed by the Ava group of the University of Cordoba. 4. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY AVA ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL AVA BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ****************************************************************/ #include #include #include #include #include #include #include "raspicam.h" using namespace std; bool doTestSpeedOnly=false; bool useUserCallback=false; size_t nFramesCaptured=100; //parse command line //returns the index of a command line param in argv. If not found, return -1 int findParam ( string param,int argc,char **argv ) { int idx=-1; for ( int i=0; i #include class Timer{ private: struct timeval _start, _end; public: Timer(){} void start(){ gettimeofday(&_start, NULL); } void end(){ gettimeofday(&_end, NULL); } double getSecs(){ return double(((_end.tv_sec - _start.tv_sec) * 1000 + (_end.tv_usec - _start.tv_usec)/1000.0) + 0.5)/1000.; } }; void saveImage ( string filepath,unsigned char *data,raspicam::RaspiCam &Camera ) { std::ofstream outFile ( filepath.c_str(),std::ios::binary ); if ( Camera.getFormat()==raspicam::RASPICAM_FORMAT_BGR || Camera.getFormat()==raspicam::RASPICAM_FORMAT_RGB ) { outFile<<"P6\n"; } else if ( Camera.getFormat()==raspicam::RASPICAM_FORMAT_GRAY ) { outFile<<"P5\n"; } else if ( Camera.getFormat()==raspicam::RASPICAM_FORMAT_YUV420 ) { //made up format // Openable as a .yuv format outFile.write ( ( char* ) data,Camera.getImageBufferSize() ); return; } outFile<isCapturing) return; camData->Camera->retrieve ( camData->data ); if ( !doTestSpeedOnly ) { if ( camData->i%5==0 ) cout<<"\r capturing ..."<i<<"/"<i%30==0 && camData->i!=0 && nFramesCaptured>0 ) { //save image if not in inifite loop std::stringstream fn; fn<<"image"; if (camData->i<10) fn<<"0"; fn<i<Camera); saveImage ( fn.str(),camData->data,*(camData->Camera) ); cerr<<"Saving "<i) >= nFramesCaptured){ //stops when nFrames captured or at infinity lpif nFramesCaptured<0 camData->Camera->setUserCallback(0); camData->isCapturing = false; } } int main ( int argc,char **argv ) { if ( argc==1 ) { cerr<<"Usage (-help for help)"<0 ) { //save image if not in inifite loop std::stringstream fn; fn<<"image"; if (i<10) fn<<"0"; fn<