2

I'm trying to get my PiCamera Module v2.1 running on my RaspberryPi4. Unfortunately I must install the Ubuntu 19.10 64bit distribution. So far so good.

I've installed Opencv4. There was some big trouble because it seems like Ubuntu does not come with VideoCore, raspi-config etc. So I downloaded and updated my firmware with sudo rpi-update and installed userland.

First I tried to open the camera with Videocapture cap(0), but this throws a bunch of errors (see here Ubuntu 19.10: Enabling and using Raspberry Pi Camera Module v2.1) and I've read that this is only for usb cameras (actually i can't believe this, because under Raspbian, I can use the module like this)

So I googled and found this repo https://github.com/cedricve/raspicam. I've installed it, but even with this I cannot get it running.

Again here is what I've down:

  • install opencv4
  • update firmware
  • install userland
  • writing start_x=1 and "gpu_mem=128" to /boot/firmware/config.txt
  • doing modprobe bcm2835-v4l2
  • sudo vcgencmd get_camera results in supported and detected = 1

When I use sudo raspistill -o test.jpg a window opens and the image is saved. But there are some errors:

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

Also I need to start it with sudo, although I've run sudo usermod -a -G video ubuntu several times (also rebooted). Strange, isn't?

My example script for accessing the camera is:

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

Compilation is successful:

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

Executing stream (even with sudo) results in:

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

Does anyone have an idea what I can try?

Thanks !

4

1 回答 1

0

为 raspicam 编译 ROS 节点时出现此错误。我通过将以下内容添加到我的 CMakeLists.txt 来修复它:

设置(CMAKE_SHARED_LINKER_FLAGS “-Wl,--no-as-needed”)

问题是链接器优化了对包含“vc.ril.camera”的库的引用,并且在运行时找不到计数。

希望它对你有用。

于 2020-09-14T12:55:30.780 回答