[英]Working on Raspberry Pi with OpenCV and BCM2835
I am currently working on Raspberry Pi and using the Raspberry Pi camera module.我目前正在研究 Raspberry Pi 并使用 Raspberry Pi 相机模块。 I plan to use OpenCV for image processing on the RPi and currently it seems not much of a problem.
我计划在 RPi 上使用 OpenCV 进行图像处理,目前这似乎不是什么大问题。 However, I am trying to use the BCM2835 library along with OpenCV and not able to integrate it.
但是,我试图将 BCM2835 库与 OpenCV 一起使用,但无法将其集成。 I tried to make changes in the Makefile and adding the bcm library and also adding path of the BCM library but nothing seems to work.
我尝试在 Makefile 中进行更改并添加 bcm 库并添加 BCM 库的路径,但似乎没有任何效果。 Please help me to integrate both the libraries as I wish to drive the GPIOs after doing some image processing on the input video.
请帮助我集成这两个库,因为我希望在对输入视频进行一些图像处理后驱动 GPIO。
Thank you.谢谢你。
I finally found the answer to my own question.我终于找到了我自己问题的答案。 The bcm library which can be downloaded here: http://www.airspayce.com/mikem/bcm2835/
bcm 库可以在这里下载: http : //www.airspayce.com/mikem/bcm2835/
are unziped and the following files are pasted in the current folder where we are working which contains the cpp files.已解压缩,并将以下文件粘贴到我们正在工作的当前文件夹中,其中包含 cpp 文件。 bcm2835.h bcm2835.o bcm2835.c
bcm2835.h bcm2835.o bcm2835.c
I added the bcm2835.c in the add_executable of CMakeLists.txt as follows: add_executable(camcv_vid2 bcm2835.c RaspiCamControl.c RaspiCLI.c RaspiPreview.c camcv_vid2.cpp)我在 CMakeLists.txt 的 add_executable 中添加了 bcm2835.c,如下所示: add_executable(camcv_vid2 bcm2835.c RaspiCamControl.c RaspiCLI.c RaspiPreview.c camcv_vid2.cpp)
Add the bcm2835.h in the program: extern "C" { ..在程序中添加bcm2835.h:extern "C" { ..
.. } .. }
Initialize the GPIO using bcm2835_init() in the main function and you are good to go.在主函数中使用 bcm2835_init() 初始化 GPIO,您就可以开始了。 Use the GPIOs to your benefit.
使用 GPIO 为您带来好处。 Overall, it is a combination of combining C and C++ files along with modifications in the CMakeLists.txt
总的来说,它是结合 C 和 C++ 文件以及 CMakeLists.txt 中的修改的组合
Enjoy!享受!
Although the topic is over 5 years old, I still find the need to add an answer, since I have been working on this now as well and found an alternative method.虽然这个话题已经超过 5 年了,但我仍然发现需要添加一个答案,因为我现在也一直在研究这个并找到了一个替代方法。 This method does not require to add the
bcm2835.c
file to add_executable
but uses the pre-compiled library and links it该方法不需要将
bcm2835.c
文件添加到add_executable
而是使用预编译库并链接
I am running Ubuntu 20.04.1 LTS on a Raspberry Pi 3 B我在 Raspberry Pi 3 B 上运行 Ubuntu 20.04.1 LTS
Setting up the library设置库
bcm2835
library using: wget http://www.airspayce.com/mikem/bcm2835/bcm2835-1.xx.tar.gz;
bcm2835
库: wget http://www.airspayce.com/mikem/bcm2835/bcm2835-1.xx.tar.gz;
# download the latest version of the library, say bcm2835-1.xx.tar.gz, then:
tar zxvf bcm2835-1.xx.tar.gz
cd bcm2835-1.xx
./configure
make
sudo make check
sudo make install
CMakeLists.txt
file add find_library(BCM2835_LIB bcm2835)
CMakeLists.txt
文件中添加find_library(BCM2835_LIB bcm2835)
target_link_libraries(<target name> ${BCM2835_LIB})
target_link_libraries(<target name> ${BCM2835_LIB})
将库链接到目标extern "C"
part is not necessary (anymore), since this is taken care of in the header file of the library.extern "C"
部分是不必要的(不再),因为这在库的头文件中得到了处理。bcm2835_init()
in the script filebcm2835_init()
For building I did the following:对于构建,我做了以下工作:
mkdir build
and go to the folder cd build
mkdir build
创建一个 build 文件夹并转到文件夹cd build
cmake ..
which sets up the compiling settings and environmentcmake ..
设置编译设置和环境make <target name>
to create the target executable or run make all
to create all targets executablesmake <target name>
创建目标可执行文件或运行make all
创建所有目标可执行文件Created a cpp-file called main.cpp
based off blink.c
( source ) that worked:创建了一个名为
main.cpp
的 cpp 文件基于blink.c
( source ) 工作:
#include "bcm2835.h"
using namespace std;
#define PIN RPI_BPLUS_GPIO_J8_07 // pin 4
int main(int argc, char **argv)
{
if (!bcm2835_init())
return 1;
// Set the pin to be an output
bcm2835_gpio_fsel(PIN, BCM2835_GPIO_FSEL_OUTP);
// Blink
while (1)
{
// Turn it on
bcm2835_gpio_write(PIN, HIGH);
// wait a bit
delay(500);
// turn it off
bcm2835_gpio_write(PIN, LOW);
// wait a bit
delay(500);
}
return 0;
}
CMakeLists.txt file CMakeLists.txt 文件
#Declare the version of the CMake API for forward-compatibility
cmake_minimum_required(VERSION 2.8)
#Declare the name of the CMake Project
project(main)
find_library(BCM2835_LIB bcm2835)
if(NOT BCM2835_LIB)
message(FATAL_ERROR "bcm2835_lib library not found")
else()
message(STATUS "bcm2835_lib library found")
endif()
# Add the directory to search for header files
include_directories(include)
# Define an executable target
add_executable(main main.cpp)
target_link_libraries(main ${BCM2835_LIB})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.