linux/树莓派 H.264/udp实时图像传输学习笔记(二)| 使用RaspiCam 获取树莓派摄像头图像

RaspiCam: 树莓派获取图像的C++库(支持OPENCV)
下载地址:https://github.com/cedricve/raspicam
PS:转载此文仅便于博主回顾,阅读者一般都为早已CET-4,所以博主不再翻译。
原文参考:
Notes:
Requires to update the firmware to use shutterspeed (sudo rpi-update)

Main features
– Provides class RaspiCam for easy and full control of the camera
– Provides class RaspiCam_Still and RaspiCam_Still_Cv for controlling the camera in still mode
– 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
– Provides class RaspiCam_Still and RaspiCam_Still_Cv for using the still camera mode
– Easy compilation/installation using cmake.
– No need to install development file of userland. Implementation is hidden.
– Many examples

Compiling
Download the file to your raspberry. Then, uncompress the file and compile

At this point you’ll see something like

If OpenCV development files are installed in your system, then you see

otherwise this option will be 0 and the opencv module of the library will not be compiled.

Finally compile, install and update the ldconfig

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.

Using it in your projects
Download the project example at SourceForge

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.

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

For cmake users, 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 build dir,compile and execute

If you do not like cmake, simply
g++ simpletest_raspicam.cpp -o simpletest_raspicam -I/usr/local/include -lraspicam -lmmal -lmmal_core -lmmal_util

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

For cmake users, create a file named CMakeLists.txt and add:

Finally, create,compile and execute

If you do not like cmake:

or similar

关于编译方法:
官方提供了CMakeLists.txt,可以使用cmake 明天编译链接,当然我们也可以自己编写Makefile文件,使用make 命令编写。
我的程序文本文档命名为:main.cpp

解释:

Print Friendly
赞 (2)
分享到:更多 ()

留言板 0

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址