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