我正在尝试获取我的 PiCamera 模块 v2.1 在我的 RaspberryPi4 上运行。不幸的是,我必须安装 Ubuntu 19.10 64 位 分配。到目前为止,一切都很好。
我已经安装了 Opencv4 .出现了一些大麻烦,因为 Ubuntu 似乎没有附带 VideoCore、raspi-config 等。所以我下载并使用 sudo rpi-update
更新了我的固件并安装userland
.
首先我尝试用 Videocapture cap(0)
打开相机, 但这会引发一堆错误(见这里 Ubuntu 19.10: Enabling and using Raspberry Pi Camera Module v2.1 ),我读过这仅适用于 USB 相机(实际上我不敢相信,因为在 Raspbian 下,我可以使用这样的模块)
所以我用谷歌搜索并找到了这个 repo https://github.com/cedricve/raspicam .我已经安装了它,但即使这样我也无法让它运行。
这又是我所失望的:
start_x=1
和“gpu_mem=128”到/boot/firmware/config.txt
modprobe bcm2835-v4l2
sudo vcgencmd get_camera
结果 支持和 检测到 = 1 当我使用
sudo raspistill -o test.jpg
将打开一个窗口并保存图像。但是有一些错误:mmal: mmal_vc_shm_init: could not initialize vc shared memory service
mmal: mmal_vc_component_create: failed to initialise shm for 'vc.camera_info' (7:EIO)
mmal: mmal_component_create_core: could not create component 'vc.camera_info' (7)
mmal: Failed to create camera_info component
我还需要以 开头须藤 ,虽然我已经运行了
sudo usermod -a -G video ubuntu
小号 每次(也重新启动) .奇怪,不是吗?我用于访问相机的示例脚本是:
#include <iostream>
#include <raspicam/raspicam_cv.h>
using namespace std;
int main ( int argc,char **argv ) {
time_t timer_begin,timer_end;
raspicam::RaspiCam_Cv Camera;
cv::Mat image;
int nCount=100;
//set camera params
Camera.set( cv::CAP_PROP_FORMAT, CV_8UC1 );
//Open camera
cout<<"Opening Camera..."<<endl;
if (!Camera.open()) {cerr<<"Error opening the camera"<<endl;return -1;}
//Start capture
cout<<"Capturing "<<nCount<<" frames ...."<<endl;
time ( &timer_begin );
for ( int i=0; i<nCount; i++ ) {
Camera.grab();
Camera.retrieve ( image);
if ( i%5==0 ) cout<<"\r captured "<<i<<" images"<<std::flush;
}
cout<<"Stop camera..."<<endl;
Camera.release();
}
编译成功:
sudo g++ stream.cpp -I/usr/local/include/opencv4 -I/usr/local/include -L/usr/local/lib -L/opt/vc/lib -lraspicam_cv -lopencv_core -lraspicam -lmmal -lmmal_core -lmmal_util -lopencv_highgui -lmmal_vc_client -lvcos -lbcm_host -o stream
执行流(即使使用 sudo)会导致:
Opening Camera...
mmal: mmal_component_create_core: could not find component 'vc.ril.camera'
Failed to create camera componentopen Failed to create camera component/home/raspicam/src/private/private_impl.cpp 103
Error opening the camera
有谁知道我可以尝试什么?
谢谢 !
最佳答案
为 raspicam 编译 ROS 节点时出现此错误。
我通过将以下内容添加到我的 CMakeLists.txt 来修复它:
设置(CMAKE_SHARED_LINKER_FLAGS “-Wl,--no-as-needed”)
问题是链接器优化了对包含“vc.ril.camera”的库的引用,并且在运行时找不到计数。
希望它对你有用。
关于c++ - 用 C++ 在 Ubuntu 上运行 PiCamera,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61527655/