I'm implementing this simple example just to get familiar with OpenCv and SIFT.
1 #include <opencv2/core/core.hpp>
2 #include <opencv2/features2d/features2d.hpp>
3 #include <opencv2/highgui/highgui.hpp>
4
5 using namespace std;
6
7 int main(int argc, char** argv) {
8
9 const cv::Mat input = cv::imread("/tmp/image.jpg", 0); //Load as grayscale
10
11 cv::SiftFeatureDetector detector;
12 std::vector<cv::KeyPoint> keypoints;
13 detector.detect(input, keypoints);
14
15 // Add results to image and save.
16 cv::Mat output;
17 cv::drawKeypoints(input, keypoints, output);
18 cv::imwrite("/tmp/SIFT_RESULT.jpg", output);
19
20 return 0;
21
22 }
I was expecting it to be quite straightforward, but it's throwing the following errors:
undefined reference to 'cv::SIFT::CommonParams::CommonParams()' at line 11
undefined reference to 'cv::FeatureDetector::detect(cv::Mat const&, std::vector<cv::KeyPoint, std::allocator<cv::KeyPoint> >&, cv::Mat const&) const' at line 13
undefined reference to 'cv::drawKeypoints(cv::Mat const&, std::vector<cv::KeyPoint, std::allocator<cv::KeyPoint> > const&, cv::Mat&, cv::Scalar_<double> const&, int)' at line 17
Can you please tell me what's going wrong?
Is it a problem in the code, or am I missing some headers?
Complete Build Output:
make all
Building file: ../main.cpp
Invoking: GCC C++ Compiler
g++ -I/usr/local/include/opencv -I/usr/include/c++/4.5.2 -O0 -g3 -Wall -c -fmessage-length=0 -std=c++0x -MMD -MP -MF"main.d" -MT"main.d" -o "main.o" "../main.cpp"
Finished building: ../main.cpp
Building target: BioInfo
Invoking: GCC C++ Linker
g++ -L/usr/local/lib -o "BioInfo" ./imageProcessingClass.o ./main.o -lopencv_core -lopencv_highgui
./main.o: In function `main':
/.../Debug/../main.cpp:38: undefined reference to `cv::SIFT::CommonParams::CommonParams()'
/.../Debug/../main.cpp:38: undefined reference to `cv::SIFT::DetectorParams::DetectorParams()'
/.../Debug/../main.cpp:38: undefined reference to `cv::SiftFeatureDetector::SiftFeatureDetector(cv::SIFT::DetectorParams const&, cv::SIFT::CommonParams const&)'
/.../Debug/../main.cpp:40: undefined reference to `cv::FeatureDetector::detect(cv::Mat const&, std::vector<cv::KeyPoint, std::allocator<cv::KeyPoint> >&, cv::Mat const&) const'
/.../Debug/../main.cpp:44: undefined reference to `cv::drawKeypoints(cv::Mat const&, std::vector<cv::KeyPoint, std::allocator<cv::KeyPoint> > const&, cv::Mat&, cv::Scalar_<double> const&, int)'
./main.o: In function `~SiftFeatureDetector':
/usr/local/include/opencv2/features2d/features2d.hpp:1502: undefined reference to `vtable for cv::SiftFeatureDetector'
/usr/local/include/opencv2/features2d/features2d.hpp:1502: undefined reference to `cv::FeatureDetector::~FeatureDetector()'
collect2: ld returned 1 exit status
make: *** [BioInfo] Error 1
Build Finished
It seems you have forgotten to link with the OpenCV libraries. Also remember if you're linking against OpenCV 2.4 there is a new library for "non-free" algorithms named opencv_nonfree that you need to link against for SIFT.
Related
I made a project that is using SFML library on linux, it's working pretty fine. I start it by launching this script exec.sh:
g++ -c main.cpp -I/usr/include
g++ main.o -o sfml-app -L/usr/lib -lsfml-graphics -lsfml-window -lsfml-system
export LD_LIBRARY_PATH=/usr/lib && ./sfml-app
And here is the code de in the main.cpp file:
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
sf::CircleShape shape(100.f);
shape.setFillColor(sf::Color::Blue);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(shape);
window.display();
}
return 0;
}
But the problem is that i can't debug it and i always have an error when trying it. Can someone give me an advice or explain how can i properly do it? I need the solution exactly for linux, i'm a newbie in this OC and IDE.
Here's the ERROR, after debugging using g++:
Starting build...
Build finished with error:
/usr/bin/ld: /tmp/ccnkqRHk.o: in function `main':
/home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:5: undefined reference to `sf::String::String(char const*, std::locale const&)'
/usr/bin/ld: /home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:5: undefined reference to `sf::VideoMode::VideoMode(unsigned int, unsigned int, unsigned int)'
/usr/bin/ld: /home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:5: undefined reference to `sf::RenderWindow::RenderWindow(sf::VideoMode, sf::String const&, unsigned int, sf::ContextSettings const&)'
/usr/bin/ld: /home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:6: undefined reference to `sf::CircleShape::CircleShape(float, unsigned long)'
/usr/bin/ld: /home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:7: undefined reference to `sf::Color::Blue'
/usr/bin/ld: /home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:7: undefined reference to `sf::Shape::setFillColor(sf::Color const&)'
/usr/bin/ld: /home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:9: undefined reference to `sf::Window::isOpen() const'
/usr/bin/ld: /home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:12: undefined reference to `sf::Window::pollEvent(sf::Event&)'
/usr/bin/ld: /home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:15: undefined reference to `sf::Window::close()'
/usr/bin/ld: /home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:18: undefined reference to `sf::Color::Color(unsigned char, unsigned char, unsigned char, unsigned char)'
/usr/bin/ld: /home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:18: undefined reference to `sf::RenderTarget::clear(sf::Color const&)'
/usr/bin/ld: /home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:19: undefined reference to `sf::RenderStates::Default'
/usr/bin/ld: /home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:19: undefined reference to `sf::RenderTarget::draw(sf::Drawable const&, sf::RenderStates const&)'
/usr/bin/ld: /home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:20: undefined reference to `sf::Window::display()'
/usr/bin/ld: /home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:5: undefined reference to `sf::RenderWindow::~RenderWindow()'
/usr/bin/ld: /home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:5: undefined reference to `sf::RenderWindow::~RenderWindow()'
/usr/bin/ld: /tmp/ccnkqRHk.o: in function `sf::CircleShape::~CircleShape()':
/usr/include/SFML/Graphics/CircleShape.hpp:41: undefined reference to `vtable for sf::CircleShape'
/usr/bin/ld: /usr/include/SFML/Graphics/CircleShape.hpp:41: undefined reference to `vtable for sf::CircleShape'
/usr/bin/ld: /usr/include/SFML/Graphics/CircleShape.hpp:41: undefined reference to `sf::Shape::~Shape()'
collect2: error: ld returned 1 exit status
Try installing library to your system path.
For Arch based Linux -
sudo pacman -S sfml
For Debian based Linux -
sudo apt-get install sfml-dev
And just use following g++ command -
g++ -c main.cpp -o main.o
g++ main.o -o sfml-app -lsfml-graphics -lsfml-window -lsfml-system
It is better to use a IDE for it. You can use
Code Blocks
Code Lite
Apache netbeans
Eclipse
And if you are familiar with cmake you can use-
Kdevelop
I'm trying the following code:
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
int main(int argc, char** argv) {
namedWindow("Output",1);
Mat output = Mat::zeros( 120, 350, CV_8UC3 );
putText(output,"Hello World",cvPoint(15,70),
FONT_HERSHEY_PLAIN,3,cvScalar(0,255,0),4);
imshow("Output", output);
waitKey(0);
return 0;
}
I then tried g++ -I/usr/local/include -L/usr/local/lib -lopencv_core -lopencv_imgcodecs -lopencv_highgui opencv_hello.cpp -o opencv_hello
and g++pkg-config opencv cvblob --cflags --libsopencv_hello.cpp -o opencv_hello
But they both give the same undefined reference errors:
opencv_hello.cpp:(.text+0x132): undefined reference to `cv::namedWindow(cv::String const&, int)'
opencv_hello.cpp:(.text+0x15f): undefined reference to `cv::Mat::zeros(int, int, int)'
opencv_hello.cpp:(.text+0x26f): undefined reference to `cv::putText(cv::_InputOutputArray const&, cv::String const&, cv::Point_<int>, int, double, cv::Scalar_<double>, int, int, bool)'
opencv_hello.cpp:(.text+0x2d7): undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'
opencv_hello.cpp:(.text+0x2ff): undefined reference to `cv::waitKey(int)'
/tmp/cctt8VGQ.o: In function `cv::String::String(char const*)':
opencv_hello.cpp:(.text._ZN2cv6StringC2EPKc[_ZN2cv6StringC5EPKc]+0x4d): undefined reference to `cv::String::allocate(unsigned long)'
/tmp/cctt8VGQ.o: In function `cv::String::~String()':
opencv_hello.cpp:(.text._ZN2cv6StringD2Ev[_ZN2cv6StringD5Ev]+0x14): undefined reference to `cv::String::deallocate()'
/tmp/cctt8VGQ.o: In function `cv::Mat::~Mat()':
opencv_hello.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x39): undefined reference to `cv::fastFree(void*)'
/tmp/cctt8VGQ.o: In function `cv::Mat::release()':
opencv_hello.cpp:(.text._ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x4b): undefined reference to `cv::Mat::deallocate()'
How can I fix this?
If pkg-config opencv --cflags --libs command finds OpenCV include files and libraries below compilation works wituout any errors.
g++ opencv_hello.cpp -o opencv_hello $(pkg-config opencv --cflags --libs)
or
g++ opencv_hello.cpp -o opencv_hello `pkg-config opencv --cflags --libs`
I've used the already compiled version of openCV for Raspberry Pi. link for anyone who is interested
After trying to compile using this command line
g++ test3.cpp -o test3 -I/usr/local/include/ -lraspicam -lraspicam_cv -L/opt/vc/lib -lmmal -lmmal_core -lmmal_util -I/usr/include -lopencv_core -lopencv_highgui -lopencv_imgproc -lwiringPi -lpthread
I get the following error lines.
//usr/local/lib/libopencv_stitching.so.2.4: undefined reference to `cv::gpu::ensureSizeIsEnough(int, int, int, cv::gpu::GpuMat&)'
//usr/local/lib/libopencv_calib3d.so.2.4: undefined reference to `cv::parallel_for_(cv::Range const&, cv::ParallelLoopBody const&, double)'
//usr/local/lib/libopencv_calib3d.so.2.4: undefined reference to `typeinfo for cv::ParallelLoopBody'
//usr/local/lib/libopencv_calib3d.so.2.4: undefined reference to `cv::Mutex::unlock()'
//usr/local/lib/libopencv_calib3d.so.2.4: undefined reference to `cv::Mutex::lock()'
//usr/local/lib/libopencv_ocl.so.2.4: undefined reference to cv::TLSDataContainer::getData() const
//usr/local/lib/libopencv_features2d.so.2.4: undefined reference to cv::AlgorithmInfo::addParam(cv::Algorithm&, char const*, unsigned char&, bool, unsigned char (cv::Algorithm::)(), void (cv::Algorithm::)(unsigned char), std::basic_string, std::allocator > const&)
//usr/local/lib/libopencv_features2d.so.2.4: undefined reference to `cv::AlgorithmInfo::addParam(cv::Algorithm&, char const*, float&, bool, float (cv::Algorithm::)(), void (cv::Algorithm::)(float), std::basic_string, std::allocator > const&)'
//usr/local/lib/libopencv_features2d.so.2.4: undefined reference to `cv::AlgorithmInfo::addParam(cv::Algorithm&, char const*, short&, bool, int (cv::Algorithm::)(), void (cv::Algorithm::)(int), std::basic_string, std::allocator > const&)'
//usr/local/lib/libopencv_calib3d.so.2.4: undefined reference to `cv::Mutex::Mutex()'
//usr/local/lib/libopencv_ocl.so.2.4: undefined reference to `cv::TLSDataContainer::TLSDataContainer()'
//usr/local/lib/libopencv_calib3d.so.2.4: undefined reference to `cv::ParallelLoopBody::~ParallelLoopBody()'
//usr/local/lib/libopencv_calib3d.so.2.4: undefined reference to `cv::Mutex::~Mutex()'
//usr/local/lib/libopencv_ocl.so.2.4: undefined reference to `cv::TLSDataContainer::~TLSDataContainer()'
collect2: ld returned 1 exit status
You have not linked the executable against several libraries that are required by the program
Try using this:
g++ -lpthread `pkg-config opencv --libs` -I/usr/local/include/ -lraspicam -lraspicam_cv -L/opt/vc/lib -lmmal -lmmal_core -lmmal_util -I/usr/include -lwiringPi test3.cpp -o test3
I am trying to test tesseract from opencv 3.0 using the test code from here
However, when I try to compile it, I get the following error
undefined reference to `cv::text::loadClassifierNM1(std::string const&)'
Any idea how I can fix this? Your help is much appreciated.
UPDATE 1
The complete error is
CMakeFiles/text_recog.dir/text_recog.o: In function `main':
text_recog.cpp:(.text+0x37b): undefined reference to `cv::text::loadClassifierNM1(std::string const&)'
text_recog.cpp:(.text+0x3bb): undefined reference to `cv::text::createERFilterNM1(cv::Ptr<cv::text::ERFilter::Callback> const&, int, float, float, float, bool, float)'
text_recog.cpp:(.text+0x42b): undefined reference to `cv::text::loadClassifierNM2(std::string const&)'
text_recog.cpp:(.text+0x44c): undefined reference to `cv::text::createERFilterNM2(cv::Ptr<cv::text::ERFilter::Callback> const&, float)'
text_recog.cpp:(.text+0x9c1): undefined reference to `cv::text::erGrouping(cv::_InputArray const&, cv::_InputArray const&, std::vector<std::vector<cv::text::ERStat, std::allocator<cv::text::ERStat> >, std::allocator<std::vector<cv::text::ERStat, std::allocator<cv::text::ERStat> > > >&, std::vector<std::vector<cv::Vec<int, 2>, std::allocator<cv::Vec<int, 2> > >, std::allocator<std::vector<cv::Vec<int, 2>, std::allocator<cv::Vec<int, 2> > > > >&, std::vector<cv::Rect_<int>, std::allocator<cv::Rect_<int> > >&, int, std::string const&, float)'
text_recog.cpp:(.text+0xa95): undefined reference to `cv::text::OCRTesseract::create(char const*, char const*, char const*, int, int)'
collect2: error: ld returned 1 exit status
make[2]: *** [text_recog] Error 1
make[1]: *** [CMakeFiles/text_recog.dir/all] Error 2
make: *** [all] Error 2
Does this help ?
It is a linker error. Look at an existing answer here
You need to compile it as g++ -o output input.cpp pkg-config opencv --cflags --libs if you are on Linux.
However if you have compiled OpenCV from source on Linux, use ldconfig to avoid linking issues.
You should use library -lopencv_text
LIBS += -lopencv_text
OR
g++ -o output input.cpp -lopencv_text
I am trying to test boost python with example in official website.
But It incurs so many errors...
The below is my what i did and the errors.
Download Boost1.55 with this.
Add Eclipse library search path to "usr/includ" (boost directory place at here)
Add library flag -lpython2.7 (Python2.7 is installed)
Add include path usr/include/python2.7(at my first try, the error happen : couldn't find pyconfig.h)
And this is my test code i did, and errors, the test code was only to see if it is compiled normally with boost python.
#include <iostream>
#include <boost/python.hpp>
char const* greet()
{
return "hello, world";
}
BOOST_PYTHON_MODULE(hello_ext)
{
using namespace boost::python;
def("greet", greet);
}
int main(){
std::cout << "aaa" << std::endl;
}
.
The Error part denoted with redline in eclipse is BOOST_PYTHON_MODULE(hello_ext)
**** Build of configuration Debug for project tsetBoost ****
make all
Building file: ../main.cpp
Invoking: GCC C++ Compiler
g++ -I/usr/include/python2.7 -O0 -g3 -Wall -c -fmessage-length=0 -std=c++0x -MMD -MP -MF"main.d" -MT"main.d" -o"main.o" "../main.cpp"
Finished building: ../main.cpp
Building target: tsetBoost
Invoking: GCC C++ Linker
g++ -L/usr/include -o"tsetBoost" ./main.o -lpython2.7
./main.o: In function `inithello_ext':
/home/kim/workspace/tsetBoost/Debug/../main.cpp:16: undefined reference to `boost::python::detail::init_module(char const*, void (*)())'
./main.o: In function `boost::python::type_info::name() const':
/usr/local/include/boost/python/type_id.hpp:165: undefined reference to `boost::python::detail::gcc_demangle(char const*)'
./main.o: In function `boost::python::to_python_value<char const* const&>::operator()(char const* const&) const':
/usr/local/include/boost/python/converter/builtin_converters.hpp:161: undefined reference to `boost::python::converter::do_return_to_python(char const*)'
./main.o: In function `void boost::python::def<char const* (*)()>(char const*, char const* (*)())':
/usr/local/include/boost/python/def.hpp:91: undefined reference to `boost::python::detail::scope_setattr_doc(char const*, boost::python::api::object const&, char const*)'
./main.o: In function `boost::python::api::object boost::python::detail::make_function_aux<char const* (*)(), boost::python::default_call_policies, boost::mpl::vector1<char const*> >(char const* (*)(), boost::python::default_call_policies const&, boost::mpl::vector1<char const*> const&)':
/usr/local/include/boost/python/make_function.hpp:38: undefined reference to `boost::python::objects::function_object(boost::python::objects::py_function const&)'
./main.o: In function `py_function_impl_base':
/usr/local/include/boost/python/object/py_function.hpp:20: undefined reference to `vtable for boost::python::objects::py_function_impl_base'
./main.o:(.rodata._ZTVN5boost6python7objects23caller_py_function_implINS0_6detail6callerIPFPKcvENS0_21default_call_policiesENS_3mpl7vector1IS6_EEEEEE[vtable for boost::python::objects::caller_py_function_impl<boost::python::detail::caller<char const* (*)(), boost::python::default_call_policies, boost::mpl::vector1<char const*> > >]+0x30): undefined reference to `boost::python::objects::py_function_impl_base::max_arity() const'
./main.o: In function `~caller_py_function_impl':
/usr/local/include/boost/python/object/py_function.hpp:30: undefined reference to `boost::python::objects::py_function_impl_base::~py_function_impl_base()'
./main.o:(.rodata._ZTIN5boost6python7objects23caller_py_function_implINS0_6detail6callerIPFPKcvENS0_21default_call_policiesENS_3mpl7vector1IS6_EEEEEE[typeinfo for boost::python::objects::caller_py_function_impl<boost::python::detail::caller<char const* (*)(), boost::python::default_call_policies, boost::mpl::vector1<char const*> > >]+0x10): undefined reference to `typeinfo for boost::python::objects::py_function_impl_base'
./main.o: In function `boost::python::converter::expected_pytype_for_arg<char const*>::get_pytype()':
/usr/local/include/boost/python/converter/pytype_function.hpp:68: undefined reference to `boost::python::converter::registry::query(boost::python::type_info)'
/usr/local/include/boost/python/converter/pytype_function.hpp:69: undefined reference to `boost::python::converter::registration::expected_from_python_type() const'
collect2: ld returned 1 exit status
make: *** [tsetBoost] ERROR 1
I added two additional flags for boost and then it works !!
-lboost_python -lboost_system