簡體   English   中英

使用 OpenCV 和 BCM2835 在 Raspberry Pi 上工作

[英]Working on Raspberry Pi with OpenCV and BCM2835

我目前正在研究 Raspberry Pi 並使用 Raspberry Pi 相機模塊。 我計划在 RPi 上使用 OpenCV 進行圖像處理,目前這似乎不是什么大問題。 但是,我試圖將 BCM2835 庫與 OpenCV 一起使用,但無法將其集成。 我嘗試在 Makefile 中進行更改並添加 bcm 庫並添加 BCM 庫的路徑,但似乎沒有任何效果。 請幫助我集成這兩個庫,因為我希望在對輸入視頻進行一些圖像處理后驅動 GPIO。

謝謝你。

我終於找到了我自己問題的答案。 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 中的修改的組合

享受!

雖然這個話題已經超過 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. 使用網站上的說明安裝庫:
    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創建一個 build 文件夾並轉到文件夾cd build
  2. 運行cmake ..設置編譯設置和環境
  3. 運行make <target name>創建目標可執行文件或運行make all創建所有目標可執行文件

創建了一個名為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 文件

#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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM