我正在开发一个将在覆盆子pi上运行的OpenCV项目。到目前为止,我一直在使用Xcode开发Mac,一切顺利。我最近意识到,为了利用覆盆子pi相机,我需要使用raspicam库。
我的问题是,我可以在OS X上安装raspicam库,还是特定的树莓硬件?
我希望能够在我的Mac上开发,编译和构建,以及在raspberry pi上编译和构建。我试图避免在Pi上进行开发。
如果不可能,您对如何管理此项目的开发设置有任何建议吗?
我的代码中只有一小部分需要raspicam库,所以我不反对在Pi上运行时执行raspicam代码的标志,否则如果在Mac上运行则执行当前正在运行的OpenCV代码。
到目前为止,我已经下载了raspicam源代码,我已经完成了:
cd raspicam-0.1.3
mkdir build
cd build
cmake -DCMAKE_PREFIX_PATH="/usr/local/Cellar/opencv3/3.1.0_3/share/OpenCV" ..
这是输出:
-- 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
然后
make
输出:
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
答案 0 :(得分:0)
我想出的解决方案是使用:
#ifdef __ARM__
include <raspicam/raspicam.h>
#endif
并在主
#ifdef __ARM__
// pi specific camera initialization code
#elif __APPLE__
// osx specific camera initialization code
#endif
在编译代码之前将评估这些预处理器。如果在pi(ARM体系结构)上编译源代码,则将编译__ARM__部分,否则如果在osx上编译源代码,则将编译__APPLE__部分。