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 7.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. This library allows to use the Raspberry Pi Camera.
  2. * Main features:
  3. - Provides class RaspiCam for easy and full control of the camera
  4. - Provides class RaspiCam_Cv for easy control of the camera with OpenCV.
  5. - Provides class RaspiCam_Still and RaspiCam_Still_Cv for controlling the camera in still mode
  6. - Easy compilation/installation using cmake.
  7. - No need to install development file of userland. Implementation is hidden.
  8. - Many examples
  9. * ChangeLog
  10. 0.1.3
  11. - Native support for BGR and RGB in opencv classes. No need to do conversion anymore.
  12. 0.1.2
  13. - Solved deadlock error in grab
  14. 0.1.1
  15. - Moved to c++11 mutex and condition_variables. Bug fixed that caused random dead lock condition in grab()
  16. 0.1.0
  17. - Bug fixed in release for RapiCam and RaspiCam_Cv
  18. 0.0.7
  19. - Added classes RaspiCam_Still and RaspiCam_Still_Cv for still camera mode
  20. 0.0.6
  21. - Bug ins cv camera corrected
  22. 0.0.5
  23. - getImageBuffeSize change by getImageBufferSize (sorry)
  24. - Change in capture format. Now, it is able to capture in RGB at high speed.
  25. - The second parameter of retrieve is now useless. Format must be specified in Raspicam::(set/get)Format before opening the camera and can not be change during operation.
  26. - RaspiCam_Cv captures in BGR, which is obtained by converting from RGB. Therefore, performance drops to half repect to the RaspiCam in RGB mode when using 1280x960.
  27. 0.0.4
  28. - Added shutter speed camera control
  29. - OpenCv set/get params are now scaled to [0,100]
  30. - Added more command line options in test programs
  31. 0.0.3
  32. - Fixed error in color conversion (rgb and bgr were swapped)
  33. - Added command line options in raspicam_test to adjust exposure
  34. - Changes in RaspiCam_Cv so that exposure can be adjusted. Very simply.
  35. 0.0.2
  36. - Decoupled opening from the start of capture in RaspiCam if desired. RapiCam::open and RaspiCam::startCapture
  37. - Added function RaspiCam::getId and RaspiCam_Cv::getId
  38. - Added a new way to convert yuv2rgb which is a bit faster.Thanks to Stefan Gufman (gruffypuffy at gmail dot com)
  39. - Added command line option -test_speed to utils programs (do not save images to memory)
  40. - Removed useless code in private_impl
  41. 0.0.1
  42. Initial libary
  43. * Compiling
  44. Download the file to your raspberry. Then, uncompress the file and compile
  45. tar xvzf raspicamxx.tgz
  46. cd raspicamxx
  47. mkdir build
  48. cd build
  49. cmake ..
  50. At this point you'll see something like
  51. -- CREATE OPENCV MODULE=1
  52. -- CMAKE_INSTALL_PREFIX=/usr/local
  53. -- REQUIRED_LIBRARIES=/opt/vc/lib/libmmal_core.so;/opt/vc/lib/libmmal_util.so;/opt/vc/lib/libmmal.so
  54. -- Change a value with: cmake -D<Variable>=<Value>
  55. --
  56. -- Configuring done
  57. -- Generating done
  58. -- Build files have been written to: /home/pi/raspicam/trunk/build
  59. If OpenCV development files are installed in your system, then you see
  60. -- CREATE OPENCV MODULE=1
  61. otherwise this option will be 0 and the opencv module of the library will not be compiled.
  62. Finally compile and install
  63. make
  64. sudo make install
  65. After that, you have the programs raspicam_test and raspicam_cv_test (if opencv was enabled).
  66. Run the first program to check that compilation is ok.
  67. You can check that the library has installed the header files under /usr/local/lib/raspicam , and the libraries in
  68. /usr/local/lib/libraspicam.so and /usr/local/lib/libraspicam_cv.so (if opencv support enabled)
  69. * Using it in your projects
  70. We provide a simple example to use the library. Create a directory for our own project.
  71. First create a file with the name simpletest_raspicam.cpp and add the following code
  72. /**
  73. */
  74. #include <ctime>
  75. #include <unistd.h>
  76. #include <fstream>
  77. #include <iostream>
  78. #include <raspicam/raspicam.h>
  79. using namespace std;
  80. int main ( int argc,char **argv ) {
  81. raspicam::RaspiCam Camera; //Cmaera object
  82. //Open camera
  83. cout<<"Opening Camera..."<<endl;
  84. if ( !Camera.open()) {cerr<<"Error opening camera"<<endl;return -1;}
  85. //wait a while until camera stabilizes
  86. cout<<"Sleeping for 3 secs"<<endl;
  87. sleep(3);
  88. //capture
  89. Camera.grab();
  90. //allocate memory
  91. unsigned char *data=new unsigned char[ Camera.getImageTypeSize ( raspicam::RASPICAM_FORMAT_RGB )];
  92. //extract the image in rgb format
  93. Camera.retrieve ( data,raspicam::RASPICAM_FORMAT_RGB );//get camera image
  94. //save
  95. std::ofstream outFile ( "raspicam_image.ppm",std::ios::binary );
  96. outFile<<"P6\n"<<Camera.getWidth() <<" "<<Camera.getHeight() <<" 255\n";
  97. outFile.write ( ( char* ) data, Camera.getImageTypeSize ( raspicam::RASPICAM_FORMAT_RGB ) );
  98. cout<<"Image saved at raspicam_image.ppm"<<endl;
  99. //free resrources
  100. delete data;
  101. return 0;
  102. }
  103. //
  104. Now, create a file named CMakeLists.txt and add:
  105. #####################################
  106. cmake_minimum_required (VERSION 2.8)
  107. project (raspicam_test)
  108. set (CMAKE_MODULE_PATH "/usr/local/lib/cmake/${CMAKE_MODULE_PATH}")
  109. find_package(raspicam REQUIRED)
  110. add_executable (simpletest_raspicam simpletest_raspicam.cpp)
  111. target_link_libraries (simpletest_raspicam ${raspicam_LIBS})
  112. #####################################
  113. Finally, create,compile and execute
  114. mkdir build
  115. cd build
  116. cmake ..
  117. make
  118. ./simpletest_raspicam
  119. A more complete sample project is provided in SourceForge.
  120. * OpenCV Interface
  121. If the OpenCV is found when compiling the library, the libraspicam_cv.so module is created and the RaspiCam_Cv class available.
  122. 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.
  123. First create a file with the name simpletest_raspicam_cv.cpp and add the following code
  124. #include <ctime>
  125. #include <iostream>
  126. #include <raspicam/raspicam_cv.h>
  127. using namespace std;
  128. int main ( int argc,char **argv ) {
  129. time_t timer_begin,timer_end;
  130. raspicam::RaspiCam_Cv Camera;
  131. cv::Mat image;
  132. int nCount=100;
  133. //set camera params
  134. Camera.set( CV_CAP_PROP_FORMAT, CV_8UC1 );
  135. //Open camera
  136. cout<<"Opening Camera..."<<endl;
  137. if (!Camera.open()) {cerr<<"Error opening the camera"<<endl;return -1;}
  138. //Start capture
  139. cout<<"Capturing "<<nCount<<" frames ...."<<endl;
  140. time ( &timer_begin );
  141. for ( int i=0; i<nCount; i++ ) {
  142. Camera.grab();
  143. Camera.retrieve ( image);
  144. if ( i%5==0 ) cout<<"\r captured "<<i<<" images"<<std::flush;
  145. }
  146. cout<<"Stop camera..."<<endl;
  147. Camera.release();
  148. //show time statistics
  149. time ( &timer_end ); /* get current time; same as: timer = time(NULL) */
  150. double secondsElapsed = difftime ( timer_end,timer_begin );
  151. cout<< secondsElapsed<<" seconds for "<< nCount<<" frames : FPS = "<< ( float ) ( ( float ) ( nCount ) /secondsElapsed ) <<endl;
  152. //save image
  153. cv::imwrite("raspicam_cv_image.jpg",image);
  154. cout<<"Image saved at raspicam_cv_image.jpg"<<endl;
  155. }
  156. Now, create a file named CMakeLists.txt and add:
  157. #####################################
  158. cmake_minimum_required (VERSION 2.8)
  159. project (raspicam_test)
  160. set (CMAKE_MODULE_PATH "/usr/local/lib/cmake/${CMAKE_MODULE_PATH}")
  161. find_package(raspicam REQUIRED)
  162. find_package(OpenCV)
  163. IF ( OpenCV_FOUND AND raspicam_CV_FOUND)
  164. MESSAGE(STATUS "COMPILING OPENCV TESTS")
  165. add_executable (simpletest_raspicam_cv simpletest_raspicam_cv.cpp)
  166. target_link_libraries (simpletest_raspicam_cv ${raspicam_CV_LIBS})
  167. ELSE()
  168. MESSAGE(FATAL_ERROR "OPENCV NOT FOUND IN YOUR SYSTEM")
  169. ENDIF()
  170. #####################################
  171. Finally, create,compile and execute
  172. mkdir build
  173. cd build
  174. cmake ..
  175. make
  176. ./simpletest_raspicam_cv