Projektarbeit Line Following Robot bei Prof. Chowanetz im WS22/23
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

raspicam_still_test.cpp 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. -------------------------------------------------------------------
  6. Copyright (c) 2013, AVA ( Ava Group University of Cordoba, ava at uco dot es)
  7. All rights reserved.
  8. Redistribution and use in source and binary forms, with or without
  9. modification, are permitted provided that the following conditions
  10. are met:
  11. 1. Redistributions of source code must retain the above copyright
  12. notice, this list of conditions and the following disclaimer.
  13. 2. Redistributions in binary form must reproduce the above copyright
  14. notice, this list of conditions and the following disclaimer in the
  15. documentation and/or other materials provided with the distribution.
  16. 3. All advertising materials mentioning features or use of this software
  17. must display the following acknowledgement:
  18. This product includes software developed by the Ava group of the University of Cordoba.
  19. 4. Neither the name of the University nor the names of its contributors
  20. may be used to endorse or promote products derived from this software
  21. without specific prior written permission.
  22. THIS SOFTWARE IS PROVIDED BY AVA ''AS IS'' AND ANY
  23. EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  24. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  25. DISCLAIMED. IN NO EVENT SHALL AVA BE LIABLE FOR ANY
  26. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  27. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  28. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  29. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  31. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. ****************************************************************/#include <iostream>
  33. #include <fstream>
  34. #include <cstdlib>
  35. #include "raspicam_still.h"
  36. using namespace std;
  37. raspicam::RaspiCam_Still Camera;
  38. //Returns the value of a param. If not present, returns the defvalue
  39. float getParamVal ( string id,int argc,char **argv,float defvalue ) {
  40. for ( int i=0; i<argc; i++ )
  41. if ( id== argv[i] )
  42. return atof ( argv[i+1] );
  43. return defvalue;
  44. }
  45. //prints program command line usage
  46. void usage() {
  47. cout<<"-w val : sets image width (2592 default)"<<endl;
  48. cout<<"-h val : sets image height (1944 default)"<<endl;
  49. cout<<"-iso val: set iso [100,800] (400 default)"<<endl;
  50. }
  51. int main ( int argc, char *argv[] ) {
  52. usage();
  53. int width = getParamVal ( "-w",argc,argv,2592 );
  54. int height =getParamVal ( "-h",argc,argv,1944 );
  55. int iso=getParamVal ( "-iso",argc,argv,400);
  56. cout << "Initializing ..."<<width<<"x"<<height<<endl;
  57. Camera.setWidth ( width );
  58. Camera.setHeight ( height );
  59. Camera.setISO(iso);
  60. Camera.setEncoding ( raspicam::RASPICAM_ENCODING_BMP );
  61. Camera.open();
  62. cout<<"capture"<<endl;
  63. unsigned int length = Camera.getImageBufferSize(); // Header + Image Data + Padding
  64. unsigned char * data = new unsigned char[length];
  65. if ( !Camera.grab_retrieve(data, length) ) {
  66. cerr<<"Error in grab"<<endl;
  67. return -1;
  68. }
  69. cout<<"saving picture.bmp"<<endl;
  70. ofstream file ( "picture.bmp",ios::binary );
  71. file.write ( ( char* ) data, length );
  72. return 0;
  73. }