【问题标题】:Working on Raspberry Pi with OpenCV and BCM2835使用 OpenCV 和 BCM2835 在 Raspberry Pi 上工作
【发布时间】:2013-06-25 15:44:31
【问题描述】:

我目前正在研究 Raspberry Pi 并使用 Raspberry Pi 摄像头模块。我计划在 RPi 上使用 OpenCV 进行图像处理,目前看来问题不大。但是,我正在尝试将 BCM2835 库与 OpenCV 一起使用,但无法集成它。 我试图在 Makefile 中进行更改并添加 bcm 库并添加 BCM 库的路径,但似乎没有任何效果。请帮助我集成这两个库,因为我希望在对输入视频进行一些图像处理后驱动 GPIO。

谢谢。

【问题讨论】:

    标签: c++ linux opencv raspberry-pi gpio


    【解决方案1】:

    我终于找到了自己问题的答案。 bcm库可以在这里下载:http://www.airspayce.com/mikem/bcm2835/

    已解压缩,以下文件将粘贴到我们正在工作的当前文件夹中,该文件夹包含 cpp 文件。 bcm2835.h bcm2835.o bcm2835.c

    我在 CMakeLists.txt 的 add_executable 中添加了 bcm2835.c 如下: add_executable(camcv_vid2 bcm2835.c RaspiCamControl.c RaspiCLI.c RaspiPreview.c camcv_vid2.cpp)

    在程序中添加bcm2835.h:extern "C" { ..

    包括“bcm2835.h”

    .. }

    在主函数中使用 bcm2835_init() 初始化 GPIO,一切顺利。 使用 GPIO 对您有利。 总的来说,它结合了 C 和 C++ 文件以及 CMakeLists.txt 中的修改

    享受吧!

    【讨论】:

      【解决方案2】:

      虽然这个话题已经超过 5 年了,但我仍然觉得有必要添加一个答案,因为我现在也一直在研究这个问题并找到了另一种方法。此方法不需要将bcm2835.c文件添加到add_executable,而是使用预编译的库并链接它

      我在 Raspberry Pi 3 B 上运行 Ubuntu 20.04.1 LTS

      设置库

      1. 下载bcm2835库使用:wget http://www.airspayce.com/mikem/bcm2835/bcm2835-1.xx.tar.gz;
      2. 使用website 上的说明安装库:
        1. # download the latest version of the library, say bcm2835-1.xx.tar.gz, then:
        2. tar zxvf bcm2835-1.xx.tar.gz
        3. cd bcm2835-1.xx
        4. ./configure
        5. make
        6. sudo make check
        7. sudo make install
      3. CMakeLists.txt 文件中添加find_library(BCM2835_LIB bcm2835)
      4. 确保使用target_link_libraries(<target name> ${BCM2835_LIB}) 将库链接到目标
      5. (不再需要)添加extern "C" 部分,因为这已在库的头文件中处理。
      6. 在脚本文件中初始化GPIO的bcm2835_init()

      为了构建,我做了以下工作:

      1. 使用mkdir build 创建一个构建文件夹并转到文件夹cd build
      2. 运行cmake ..,设置编译设置和环境
      3. 运行make <target name>创建目标可执行文件或运行make all创建所有目标可执行文件

      根据有效的blink.c (source) 创建了一个名为main.cpp 的 cpp 文件:

      #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 文件

      #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})
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-01-26
        • 2017-04-01
        • 1970-01-01
        • 1970-01-01
        • 2015-06-15
        • 1970-01-01
        • 1970-01-01
        • 2015-04-17
        相关资源
        最近更新 更多