Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. #include <fstream>
  2. #include <cstdlib>
  3. #include <iostream>
  4. #include "raspicam/raspicam_still.h"
  5.  
  6. using namespace std;
  7.  
  8. //Returns the value of a param. If not present, returns the defvalue
  9. float getParamVal ( string id,int argc,char **argv,float defvalue ) {
  10. for ( int i=0; i<argc; i++ )
  11. if ( id== argv[i] )
  12. return atof ( argv[i+1] );
  13. return defvalue;
  14. }
  15.  
  16. //prints program command line usage
  17. void usage() {
  18. cout<<"-w val : sets image width (648 default)"<<endl;
  19. cout<<"-h val : sets image height (486 default)"<<endl;
  20. cout<<"-iso val: set iso [100,800] (400 default)"<<endl;
  21. }
  22.  
  23.  
  24. int main ( int argc, char *argv[] ) {
  25. usage();
  26.  
  27. raspicam::RaspiCam_Still *Camera = new raspicam::RaspiCam_Still();
  28.  
  29. // int width = getParamVal ( "-w",argc,argv,2592 );
  30. // int height =getParamVal ( "-h",argc,argv,1944 );
  31. int width = getParamVal ( "-w",argc,argv,648 );
  32. int height =getParamVal ( "-h",argc,argv,486 );
  33. int iso=getParamVal ( "-iso",argc,argv,400);
  34.  
  35.  
  36. cout << "Initializing ..."<<width<<"x"<<height<<endl;
  37. Camera->setWidth ( width );
  38. Camera->setHeight ( height );
  39. Camera->setISO(iso);
  40. Camera->setEncoding ( raspicam::RASPICAM_ENCODING_BMP );
  41. Camera->open();
  42. cout<<"capture"<<endl;
  43. unsigned int length = Camera->getImageBufferSize(); // Header + Image Data + Padding
  44. unsigned char * data = new unsigned char[length];
  45. if ( !Camera->grab_retrieve(data, length) ) {
  46. cerr<<"Error in grab"<<endl;
  47. return -1;
  48. }
  49.  
  50. cout<<"saving picture.bmp"<<endl;
  51. ofstream file ( "picture.bmp",ios::binary );
  52. file.write ( ( char* ) data, length );
  53.  
  54. delete Camera;
  55.  
  56. return 0;
  57. }
  58.  
  59. raspicam::RaspiCam_Still *Camera = raspicam::RaspiCam_Still();
  60.  
  61. raspicam::RaspiCam_Still Camera;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement