0

I need any help with this error

pi@raspberrypi ~/opencam_test $ sudo g++ simpletest_raspicam_cv.cpp -o  simpletest_raspicam_cv -I/usr/local/include/ -lraspicam -lraspicam_cv -lmmal -lmmal_core -lmmal_util -lopencv_core -lopencv_highgui 
/usr/bin/ld: /tmp/cc2tVouL.o: undefined reference to symbol 'cv::imwrite(cv::String const&, cv::_InputArray const&, std::vector<int, std::allocator<int> > const&)'
//usr/local/lib/libopencv_imgcodecs.so.3.1: error adding symbols: DSO missing from command line
collect2: ld returned 1 exit status

I try an example for be sure that the raspicam is correctly configured with opencv-3.1.0 this is the site which i follow http://www.uco.es/investiga/grupos/ava/node/40

and this is my src code which i want to compile

#include <ctime>
#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();
    //show time statistics
    time ( &timer_end ); /* get current time; same as: timer = time(NULL)  */
    double secondsElapsed = difftime ( timer_end,timer_begin );
    cout<< secondsElapsed<<" seconds for "<< nCount<<"  frames : FPS = "<<  ( float ) ( ( float ) ( nCount ) /secondsElapsed ) <<endl;
    //save image 
    cv::imwrite("raspicam_cv_image.jpg",image);
    cout<<"Image saved at raspicam_cv_image.jpg"<<endl;
}

2 Answers 2

1

try something like this...

g++ `pkg-config opencv --cflags` program_name.cpp -o  program_name `pkg-config opencv --libs` -I/usr/local/include/ -lraspicam -lraspicam_cv
0

I could not reproduce your problem but I was able to compile and run your code. The output was:

Opening Camera...Capturing 100 frames .... captured 95 imagesStop camera... 3 seconds for 100 frames : FPS = 33.3333 Image saved at raspicam_cv_image.jpg

I did it with make and CMake files. It leads me to believe the problem is that you have a missing/redundant library(s) in the command line, namely:

//usr/local/lib/libopencv_imgcodecs.so.3.1: error adding symbols: DSO missing from command line

CMake and make are programs that perform all that command like compile information for you. I can help you if you have any problems using this method.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.