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.

simpletest_raspicam.cpp 1.1KB

12345678910111213141516171819202122232425262728293031323334
  1. /**
  2. */
  3. #include <ctime>
  4. #include <fstream>
  5. #include <iostream>
  6. #include <unistd.h>
  7. #include <raspicam/raspicam.h>
  8. using namespace std;
  9. int main ( int argc,char **argv ) {
  10. raspicam::RaspiCam Camera; //Cmaera object
  11. //Open camera
  12. cout<<"Opening Camera..."<<endl;
  13. if ( !Camera.open()) {cerr<<"Error opening camera"<<endl;return -1;}
  14. //wait a while until camera stabilizes
  15. cout<<"Sleeping for 3 secs"<<endl;
  16. usleep(3*1000000);
  17. //capture
  18. Camera.grab();
  19. //allocate memory
  20. unsigned char *data=new unsigned char[ Camera.getImageTypeSize ( raspicam::RASPICAM_FORMAT_RGB )];
  21. //extract the image in rgb format
  22. Camera.retrieve ( data,raspicam::RASPICAM_FORMAT_RGB );//get camera image
  23. //save
  24. std::ofstream outFile ( "raspicam_image.ppm",std::ios::binary );
  25. outFile<<"P6\n"<<Camera.getWidth() <<" "<<Camera.getHeight() <<" 255\n";
  26. outFile.write ( ( char* ) data, Camera.getImageTypeSize ( raspicam::RASPICAM_FORMAT_RGB ) );
  27. cout<<"Image saved at raspicam_image.ppm"<<endl;
  28. //free resrources
  29. delete data;
  30. return 0;
  31. }
  32. //