Reputation: 27
I am working on an Rpi Based self driving car- which I utilise OpenCV to do image processing from the pi camera in order to follow a predesigned track. I am currently trying to get this working ( A basic video streaming option) to see how to get it working before i develop into the NN for image rec.
my code is as follows (it refuses to build due to opencv errors):
#include <stdio.h>
#include <pigpio.h>
#include <stdlib.h>
#include <unistd.h>
#include <wiringPi.h>
#include <softPwm.h>
#include "move.h"
#include "distance.h"
#include <linux/videodev2.h>
#include <libv4l2.h>
#include <opencv2/core/core.hpp>
#include <opencv2/opencv.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/videoio.hpp>
using namespace cv;
void SysMenu(){
system("clear");
int choice;
printf("||Please Choose An Option..........||\n");
printf("||1.Test Motors || 2.Test Sensors||\n");
printf("||3.Exit || ||\n");
scanf("%i",&choice);
switch(choice)
{
case 1:
move(MT_FORWARD, 3000);
printf("fwd\n");
move(MT_BACKWARD, 3000);
printf("bwd\n");
move(MT_RIGHT, 3000);
printf("rght\n");
move(MT_LEFT, 3000);
printf("left\n");
move(MT_FORWARD | MT_RIGHT, 3000);
printf("fwd, right\n");
move(MT_FORWARD | MT_LEFT, 3000);
printf("fwd left\n");
delay(3000);
SysMenu();
break;
case 2 :
TestSensors();
delay(3000);
SysMenu();
break;
case 3 :
break;
default : printf("Input, Option Not available, Please retry");
SysMenu();
break;
}
}
int main(int, char**) {
VideoCapture cap;
cap.cv::VideoCapture::open(0);
if (!cap.isOpened())
return -1;
Mat edge;//,gray,c_edge,lpf_gaussian_blurr;
namedWindow("Original_Video",1);
for(;;)
{
Mat video;
cap >> video;//capture live feed
//convert to b&w
cvtColor(video,edge,CV_BGR2GRAY);
//Canny(gray,c_edge,0,30,3);
//GaussianBlur(video,lpf_gaussian_blurr,Size(9,9),1.5,1.5);
imshow("Original_Video",edge);
if(waitKey(30)>= 0) break;
}
initialisePins();
SysMenu();
gpioTerminate();
return 0;
}
and the output is as follows:
g++ -Wall -I/usr/local/include -lopencv_core -lwiringPi -lpigpio -lopencv_imgcodecs -lopencv_highgui -lopencv_videoio -lopencv_imgproc -o "SdCar" "SdCar.cpp" (in directory: /home/pi/selfdrivingcar-17)
/usr/bin/ld: warning: libopencv_imgproc.so.3.1, needed by //usr/local/lib/libopencv_imgcodecs.so, may conflict with libopencv_imgproc.so.2.4
/usr/bin/ld: warning: libopencv_core.so.3.1, needed by //usr/local/lib/libopencv_imgcodecs.so, may conflict with libopencv_core.so.2.4
/usr/bin/ld: //usr/local/lib/libopencv_imgcodecs.so: undefined reference to symbol '_ZN2cv6String10deallocateEv'
//usr/local/lib/libopencv_core.so.3.1: error adding symbols: DSO missing from command line
Compilation failed.
collect2: error: ld returned 1 exit status
Upvotes: 0
Views: 986
Reputation: 1
I encountered the same problem however I solved it with pkg-config opencv --cflags --libs
.
When I compiled with the previous command, the output was like below:
qsp@ubuntu:~/Documents/caffeProject/assign3$ g++ -o "test_mnist"
"test_mnist.cpp" -lopencv_dnn -lopencv_highgui -lopencv_imgcodecs
-lopencv_imgproc -lstdc++ -lopencv_core /usr/bin/ld: warning: libopencv_core.so.3.1, needed by //usr/local/lib/libopencv_dnn.so, may
conflict with libopencv_core.so.2.4 /usr/bin/ld: /tmp/ccovch2b.o:
undefined reference to symbol '_ZN2cv6String10deallocateEv'
//usr/local/lib/libopencv_core.so.3.1: error adding symbols: DSO
missing from command line collect2: error: ld returned 1 exit status
Although problem solved, I still wonder why. Can anybody explain?
Upvotes: 0
Reputation: 5846
The -l<library>
flags need to follow the source or object (.o
) file that uses them.
This is how the linker works: it processes the .cpp/.o
files from command line left to right, and does not know what it needs from the libraries until it sees them referenced to in an .cpp/.o
file.
So change the linker command:
g++ -Wall -I/usr/local/include -lopencv_core -lwiringPi -lpigpio -lopencv_imgcodecs -lopencv_highgui -lopencv_videoio -lopencv_imgproc -o "SdCar" "SdCar.cpp"
to
g++ -Wall -I/usr/local/include -o "SdCar" "SdCar.cpp" -lopencv_core -lwiringPi -lpigpio -lopencv_imgcodecs -lopencv_highgui -lopencv_videoio -lopencv_imgproc
Upvotes: 1