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.

README.md 7.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. # RaspiCam: C++ API for using Raspberry camera (with OpenCV)
  2. This library allows to use the Raspberry Pi Camera under BSD License.
  3. The project is started by the AVA research group (rafael Muñoz Salinas; rmsalinas@uco.es) and is now maintained
  4. on this GIT repository by Cédric Verstraeten. Please note that is NOT the OFFICIAL repository of RaspiCam, these can be found [here](http://www.uco.es/investiga/grupos/ava/node/40).
  5. This repository is used in the [Kerberos.io](https://github.com/kerberos-io) project.
  6. ## Release notes
  7. Update 2014/03/04: version 0.1.1 released Download at SourceForge
  8. Main feaure in 0.0.7 : Still camera API. You can now use the still mode for high resolution (includes OpenCv interface). See examples for more info.
  9. Notes:
  10. Requires to update the firmware to use shutterspeed (sudo rpi-update)
  11. Main features
  12. - Provides class RaspiCam for easy and full control of the camera
  13. - Provides class RaspiCam_Still and RaspiCam_Still_Cv for controlling the camera in still mode
  14. - Provides class RaspiCam_Cv for easy control of the camera with OpenCV.
  15. - Provides class RaspiCam_Still and RaspiCam_Still_Cv for controlling the camera in still mode
  16. - Provides class RaspiCam_Still and RaspiCam_Still_Cv for using the still camera mode
  17. - Easy compilation/installation using cmake.
  18. - No need to install development file of userland. Implementation is hidden.
  19. - Many examples
  20. Performance
  21. Following, we show the capture performance of the library (measured capturing 600 frames).
  22. Gray and YUV420 Mode
  23. - 1280x960: 29.5fps, 640x480 : 29.5fps, 320x240 : 29.5fps
  24. RGB Mode
  25. - 1280x960: 28 fps, 640x480 : 29.29fps, 320x240 : 29.24fps
  26. BGR Mode
  27. - 1280x960: 14 fps, 640x480 : 29.29fps, 320x240 : 29.24fps
  28. Note: when using the full resolution video callbacks with the full resolution of the Raspberry Pi Camera v2, you will likely get an error such as `mmal: mmal_vc_port_enable: failed to enable port vc.ril.camera:out:1(BGR3): ENOSPC`. In order to fix this increase your GPU memory to at least 256MB.
  29. Color conversion is the most time consuming part. We still need to improve that part. Go to src/private and check if you can contribute!
  30. Note: the library is compiled with the options: -Wall -ffunction-sections -fomit-frame-pointer -O2 -ffast-math -DNDEBUG -mcpu=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard -ftree-vectorize
  31. Note 2: the library is currently setting the camera in video mode. So, maximum resolution is 1280x960. I am working on the still port to enable higher resolutions.
  32. ## Compiling
  33. Clone the repository to your raspberry. Then, uncompress the file and compile
  34. git clone https://github.com/cedricve/raspicam.git
  35. cd raspicam
  36. mkdir build
  37. cd build
  38. cmake ..
  39. At this point you'll see something like
  40. -- CREATE OPENCV MODULE=1
  41. -- CMAKE_INSTALL_PREFIX=/usr/local
  42. -- REQUIRED_LIBRARIES=/opt/vc/lib/libmmal_core.so;/opt/vc/lib/libmmal_util.so;/opt/vc/lib/libmmal.so
  43. -- Change a value with: cmake -D<Variable>=<Value>
  44. --
  45. -- Configuring done
  46. -- Generating done
  47. -- Build files have been written to: /home/pi/raspicam/trunk/build
  48. If OpenCV development files are installed in your system, then you see following output; otherwise this option will be 0 and the opencv module of the library will not be compiled.
  49. -- CREATE OPENCV MODULE=1
  50. Finally compile, install and update the ldconfig:
  51. make
  52. sudo make install
  53. sudo ldconfig
  54. After that, you have the programs raspicam_test and raspicam_cv_test (if opencv was enabled) in build/utils.
  55. Run the first program to check that compilation is ok.
  56. ```
  57. sudo ./raspicam_test
  58. sudo ./raspicam_cv_test
  59. ```
  60. ### Using it in your projects
  61. You can learn how to use the library by taking a look at the examples in the utils directory and by analyzing the header files. In addition, we provide a some simple examples on how to use the library with cmake.
  62. First, create a directory for our own project. Then, go in and create a file with the name simpletest_raspicam.cpp and add the following code
  63. /**
  64. */
  65. #include <ctime>
  66. #include <fstream>
  67. #include <iostream>
  68. #include <raspicam/raspicam.h>
  69. using namespace std;
  70. int main ( int argc,char **argv ) {
  71. raspicam::RaspiCam Camera; //Camera object
  72. //Open camera
  73. cout<<"Opening Camera..."<<endl;
  74. if ( !Camera.open()) {cerr<<"Error opening camera"<<endl;return -1;}
  75. //wait a while until camera stabilizes
  76. cout<<"Sleeping for 3 secs"<<endl;
  77. sleep(3);
  78. //capture
  79. Camera.grab();
  80. //allocate memory
  81. unsigned char *data=new unsigned char[ Camera.getImageTypeSize ( raspicam::RASPICAM_FORMAT_RGB )];
  82. //extract the image in rgb format
  83. Camera.retrieve ( data,raspicam::RASPICAM_FORMAT_RGB );//get camera image
  84. //save
  85. std::ofstream outFile ( "raspicam_image.ppm",std::ios::binary );
  86. outFile<<"P6\n"<<Camera.getWidth() <<" "<<Camera.getHeight() <<" 255\n";
  87. outFile.write ( ( char* ) data, Camera.getImageTypeSize ( raspicam::RASPICAM_FORMAT_RGB ) );
  88. cout<<"Image saved at raspicam_image.ppm"<<endl;
  89. //free resrources
  90. delete data;
  91. return 0;
  92. }
  93. For cmake users, create a file named CMakeLists.txt and add:
  94. cmake_minimum_required (VERSION 2.8)
  95. project (raspicam_test)
  96. find_package(raspicam REQUIRED)
  97. add_executable (simpletest_raspicam simpletest_raspicam.cpp)
  98. target_link_libraries (simpletest_raspicam ${raspicam_LIBS})
  99. Finally, create build dir,compile and execute
  100. mkdir build
  101. cd build
  102. cmake ..
  103. make
  104. ./simpletest_raspicam
  105. If you do not like cmake, simply
  106. g++ simpletest_raspicam.cpp -o simpletest_raspicam -I/usr/local/include -lraspicam -lmmal -lmmal_core -lmmal_util
  107. ### OpenCV Interface
  108. If the OpenCV is found when compiling the library, the libraspicam_cv.so module is created and the RaspiCam_Cv class available. Take a look at the examples in utils to see how to use the class. In addition, we show here how you can use the RaspiCam_Cv in your own project using cmake.
  109. First create a file with the name simpletest_raspicam_cv.cpp and add the following code
  110. #include <ctime>
  111. #include <iostream>
  112. #include <raspicam/raspicam_cv.h>
  113. using namespace std;
  114. int main ( int argc,char **argv ) {
  115. time_t timer_begin,timer_end;
  116. raspicam::RaspiCam_Cv Camera;
  117. cv::Mat image;
  118. int nCount=100;
  119. //set camera params
  120. Camera.set( CV_CAP_PROP_FORMAT, CV_8UC1 );
  121. //Open camera
  122. cout<<"Opening Camera..."<<endl;
  123. if (!Camera.open()) {cerr<<"Error opening the camera"<<endl;return -1;}
  124. //Start capture
  125. cout<<"Capturing "<<nCount<<" frames ...."<<endl;
  126. time ( &timer_begin );
  127. for ( int i=0; i<nCount; i++ ) {
  128. Camera.grab();
  129. Camera.retrieve ( image);
  130. if ( i%5==0 ) cout<<"\r captured "<<i<<" images"<<std::flush;
  131. }
  132. cout<<"Stop camera..."<<endl;
  133. Camera.release();
  134. //show time statistics
  135. time ( &timer_end ); /* get current time; same as: timer = time(NULL) */
  136. double secondsElapsed = difftime ( timer_end,timer_begin );
  137. cout<< secondsElapsed<<" seconds for "<< nCount<<" frames : FPS = "<< ( float ) ( ( float ) ( nCount ) /secondsElapsed ) <<endl;
  138. //save image
  139. cv::imwrite("raspicam_cv_image.jpg",image);
  140. cout<<"Image saved at raspicam_cv_image.jpg"<<endl;
  141. }
  142. For cmake users, create a file named CMakeLists.txt and add:
  143. cmake_minimum_required (VERSION 2.8)
  144. project (raspicam_test)
  145. find_package(raspicam REQUIRED)
  146. find_package(OpenCV)
  147. IF ( OpenCV_FOUND AND raspicam_CV_FOUND)
  148. MESSAGE(STATUS "COMPILING OPENCV TESTS")
  149. add_executable (simpletest_raspicam_cv simpletest_raspicam_cv.cpp)
  150. target_link_libraries (simpletest_raspicam_cv ${raspicam_CV_LIBS})
  151. ELSE()
  152. MESSAGE(FATAL_ERROR "OPENCV NOT FOUND IN YOUR SYSTEM")
  153. ENDIF()
  154. Finally, create,compile and execute
  155. mkdir build
  156. cd build
  157. cmake ..
  158. make
  159. ./simpletest_raspicam_cv
  160. If you do not like cmake:
  161. g++ simpletest_raspicam_cv.cpp -o simpletest_raspicam_cv -I/usr/local/include/ -lraspicam -lraspicam_cv -lmmal -lmmal_core -lmmal_util -lopencv_core -lopencv_highgui