简体   繁体   English

我可以在OS X上安装raspicam c ++库吗?

[英]Can I install raspicam c++ libraries on OS X?

I'm developing an OpenCV project that will run on a raspberry pi. 我正在开发一个将在树莓派上运行的OpenCV项目。 So far I have been developing on a Mac in Xcode and all is going well. 到目前为止,我一直在使用Xcode在Mac上进行开发,并且一切进展顺利。 I recently realized that in order to tap into the raspberry pi camera I will need to use the raspicam library. 我最近意识到,要使用树莓派相机,我将需要使用raspicam库。

My question is, can I install raspicam libraries on OS X or are they raspberry pi hardware specific? 我的问题是,我可以在OS X上安装raspicam库,还是它们是raspberry pi硬件专用的?

I would like to be able to develop, compile, and build on my Mac as well as compile and build on the raspberry pi. 我希望能够在Mac上进行开发,编译和构建,以及在树莓派上进行编译和构建。 I am trying to avoid doing my development on the Pi. 我试图避免在Pi上进行开发。

If that's not possible do you have any recommendations for how I should manage the development setup for this project? 如果不可能,那么您是否对如何管理该项目的开发设置有任何建议?

There is only a small section of my code that requires the raspicam libraries so I am not opposed to having a flag that executes the raspicam code if running on the Pi, otherwise executes the currently working OpenCV code if running on the Mac. 我的代码中只有一小部分需要raspicam库,因此我不反对拥有一个标志,如果在Pi上运行,则执行raspicam代码;否则,如果在Mac上运行,则执行当前工作的OpenCV代码。

So far I have downloaded the raspicam source and I have done: 到目前为止,我已经下载了raspicam源码,并且已经完成了:

cd raspicam-0.1.3
mkdir build
cd build
cmake -DCMAKE_PREFIX_PATH="/usr/local/Cellar/opencv3/3.1.0_3/share/OpenCV" ..

And here is the output: 这是输出:

-- Adding cv library
-- 
-- -------------------------------------------------------------------------------
-- General configuration for raspicam 0.1.2
-- -------------------------------------------------------------------------------
-- 
    Built as dynamic libs?:ON
    Compiler:/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-- C++ flags (Release):        -std=c++0x -Wl,--no-as-needed     -lpthread
-- C++ flags (Debug):          -std=c++0x -Wl,--no-as-needed     -lpthread
-- CMAKE_CXX_FLAGS:          -std=c++0x -Wl,--no-as-needed  
-- CMAKE_BINARY_DIR:         /Users/andres/Downloads/raspicam-0.1.3/build
-- 
-- CMAKE_SYSTEM_PROCESSOR = x86_64
-- BUILD_SHARED_LIBS = ON
-- BUILD_UTILS = ON
-- CMAKE_INSTALL_PREFIX = /usr/local
-- CMAKE_BUILD_TYPE = Release
-- CMAKE_MODULE_PATH = /usr/local/lib/cmake/;/usr/lib/cmake
-- 
-- CREATE OPENCV MODULE=1
-- CMAKE_INSTALL_PREFIX=/usr/local
-- REQUIRED_LIBRARIES=
-- 
-- 
-- Change a value with: cmake -D<Variable>=<Value>
-- 
-- Configuring done
CMake Warning (dev):
  Policy CMP0042 is not set: MACOSX_RPATH is enabled by default.  Run "cmake
  --help-policy CMP0042" for policy details.  Use the cmake_policy command to
  set the policy and suppress this warning.

  MACOSX_RPATH is not specified for the following targets:

   raspicam
   raspicam_cv

This warning is for project developers.  Use -Wno-dev to suppress it.

-- Generating done
-- Build files have been written to: /Users/andres/Downloads/raspicam-0.1.3/build

Then 然后

make

Output: 输出:

Scanning dependencies of target raspicam_cv
[  5%] Building CXX object src/CMakeFiles/raspicam_cv.dir/raspicam_cv.cpp.o
clang: warning: -Wl,--no-as-needed: 'linker' input unused
clang: warning: -lpthread: 'linker' input unused
In file included from /Users/andres/Downloads/raspicam-0.1.3/src/raspicam_cv.cpp:39:
In file included from /Users/andres/Downloads/raspicam-0.1.3/src/./private/private_impl.h:40:
In file included from /Users/andres/Downloads/raspicam-0.1.3/dependencies/mmal/mmal.h:363:
In file included from /Users/andres/Downloads/raspicam-0.1.3/dependencies/mmal/mmal_common.h:40:
In file included from /Users/andres/Downloads/raspicam-0.1.3/dependencies/vcos/vcos.h:116:
/Users/andres/Downloads/raspicam-0.1.3/dependencies/vcos/pthreads/vcos_platform.h:297:22: error: 
      use of undeclared identifier 'CLOCK_REALTIME'
   if (clock_gettime(CLOCK_REALTIME, &ts) == -1)
                     ^
/Users/andres/Downloads/raspicam-0.1.3/dependencies/vcos/pthreads/vcos_platform.h:307:13: error: 
      use of undeclared identifier 'sem_timedwait'
      ret = sem_timedwait( sem, &ts );
            ^
/Users/andres/Downloads/raspicam-0.1.3/dependencies/vcos/pthreads/vcos_platform.h:327:13: warning: 
      'sem_init' is deprecated [-Wdeprecated-declarations]
   int rc = sem_init(sem, 0, initial_count);
            ^
/usr/include/sys/semaphore.h:55:5: note: 'sem_init' has been explicitly marked
      deprecated here
int sem_init(sem_t *, int, unsigned int) __deprecated;
    ^
In file included from /Users/andres/Downloads/raspicam-0.1.3/src/raspicam_cv.cpp:39:
In file included from /Users/andres/Downloads/raspicam-0.1.3/src/./private/private_impl.h:40:
In file included from /Users/andres/Downloads/raspicam-0.1.3/dependencies/mmal/mmal.h:363:
In file included from /Users/andres/Downloads/raspicam-0.1.3/dependencies/mmal/mmal_common.h:40:
In file included from /Users/andres/Downloads/raspicam-0.1.3/dependencies/vcos/vcos.h:116:
/Users/andres/Downloads/raspicam-0.1.3/dependencies/vcos/pthreads/vcos_platform.h:335:13: warning: 
      'sem_destroy' is deprecated [-Wdeprecated-declarations]
   int rc = sem_destroy(sem);
            ^
/usr/include/sys/semaphore.h:53:5: note: 'sem_destroy' has been explicitly
      marked deprecated here
int sem_destroy(sem_t *) __deprecated;
    ^
In file included from /Users/andres/Downloads/raspicam-0.1.3/src/raspicam_cv.cpp:39:
In file included from /Users/andres/Downloads/raspicam-0.1.3/src/./private/private_impl.h:40:
In file included from /Users/andres/Downloads/raspicam-0.1.3/dependencies/mmal/mmal.h:363:
In file included from /Users/andres/Downloads/raspicam-0.1.3/dependencies/mmal/mmal_common.h:40:
In file included from /Users/andres/Downloads/raspicam-0.1.3/dependencies/vcos/vcos.h:116:
/Users/andres/Downloads/raspicam-0.1.3/dependencies/vcos/pthreads/vcos_platform.h:520:13: warning: 
      'sem_init' is deprecated [-Wdeprecated-declarations]
   int rc = sem_init(&event->sem, 0, 0);
            ^
/usr/include/sys/semaphore.h:55:5: note: 'sem_init' has been explicitly marked
      deprecated here
int sem_init(sem_t *, int, unsigned int) __deprecated;
    ^
In file included from /Users/andres/Downloads/raspicam-0.1.3/src/raspicam_cv.cpp:39:
In file included from /Users/andres/Downloads/raspicam-0.1.3/src/./private/private_impl.h:40:
In file included from /Users/andres/Downloads/raspicam-0.1.3/dependencies/mmal/mmal.h:363:
In file included from /Users/andres/Downloads/raspicam-0.1.3/dependencies/mmal/mmal_common.h:40:
In file included from /Users/andres/Downloads/raspicam-0.1.3/dependencies/vcos/vcos.h:116:
/Users/andres/Downloads/raspicam-0.1.3/dependencies/vcos/pthreads/vcos_platform.h:525:7: warning: 
      'sem_destroy' is deprecated [-Wdeprecated-declarations]
      sem_destroy(&event->sem);
      ^
/usr/include/sys/semaphore.h:53:5: note: 'sem_destroy' has been explicitly
      marked deprecated here
int sem_destroy(sem_t *) __deprecated;
    ^
In file included from /Users/andres/Downloads/raspicam-0.1.3/src/raspicam_cv.cpp:39:
In file included from /Users/andres/Downloads/raspicam-0.1.3/src/./private/private_impl.h:40:
In file included from /Users/andres/Downloads/raspicam-0.1.3/dependencies/mmal/mmal.h:363:
In file included from /Users/andres/Downloads/raspicam-0.1.3/dependencies/mmal/mmal_common.h:40:
In file included from /Users/andres/Downloads/raspicam-0.1.3/dependencies/vcos/vcos.h:116:
/Users/andres/Downloads/raspicam-0.1.3/dependencies/vcos/pthreads/vcos_platform.h:541:8: warning: 
      'sem_getvalue' is deprecated [-Wdeprecated-declarations]
   if (sem_getvalue(&event->sem, &value) != 0)
       ^
/usr/include/sys/semaphore.h:54:5: note: 'sem_getvalue' has been explicitly
      marked deprecated here
int sem_getvalue(sem_t * __restrict, int * __restrict) __deprecated;
    ^
In file included from /Users/andres/Downloads/raspicam-0.1.3/src/raspicam_cv.cpp:39:
In file included from /Users/andres/Downloads/raspicam-0.1.3/src/./private/private_impl.h:40:
In file included from /Users/andres/Downloads/raspicam-0.1.3/dependencies/mmal/mmal.h:363:
In file included from /Users/andres/Downloads/raspicam-0.1.3/dependencies/mmal/mmal_common.h:40:
In file included from /Users/andres/Downloads/raspicam-0.1.3/dependencies/vcos/vcos.h:116:
/Users/andres/Downloads/raspicam-0.1.3/dependencies/vcos/pthreads/vcos_platform.h:582:13: warning: 
      'sem_destroy' is deprecated [-Wdeprecated-declarations]
   int rc = sem_destroy(&event->sem);
            ^
/usr/include/sys/semaphore.h:53:5: note: 'sem_destroy' has been explicitly
      marked deprecated here
int sem_destroy(sem_t *) __deprecated;
    ^
6 warnings and 2 errors generated.
make[2]: *** [src/CMakeFiles/raspicam_cv.dir/raspicam_cv.cpp.o] Error 1
make[1]: *** [src/CMakeFiles/raspicam_cv.dir/all] Error 2
make: *** [all] Error 2

The solution I came up with was to use: 我想出的解决方案是使用:

#ifdef __ARM__
include <raspicam/raspicam.h>
#endif

and in the main 并在主要

#ifdef __ARM__
    // pi specific camera initialization code
#elif __APPLE__
    // osx specific camera initialization code
#endif

These preprocessors will be evaluated before the code is compiled. 这些预处理器将在编译代码之前进行评估。 If the source is being compiled on the pi (ARM architecture) the __ARM__ sections will be compiled, otherwise if the source code is being compiled on osx the __APPLE__ sections will be compiled. 如果源代码是在pi(ARM体系结构)上编译的,则将编译__ARM__部分,否则,如果源代码是在osx上编译的,则将编译__APPLE__部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM