Very simple attempt to use opencv class fails to build

Hello all,

My first post so please excuse faux pas, omissions etc.

I am totally new to all this and am most likely attempting something way beyond my skill level, but to be honest everything is beyond my understanding. Here goes …

I have tried to make a very simple app that uses the opencv classes such as ‘VideoCapture’ and upon attempting to build I get the following failure message:

Undefined symbols for architecture x86_64:
“cv::VideoCapture::~VideoCapture()”, referenced from:
ofApp::~ofApp() in ofApp.o
“cv::imshow(cv::String const&, cv::_InputArray const&)”, referenced from:
ofApp::draw() in ofApp.o
“cv::waitKey(int)”, referenced from:
ofApp::draw() in ofApp.o
“cv::VideoCapture::read(cv::_OutputArray const&)”, referenced from:
ofApp::update() in ofApp.o
“cv::VideoCapture::isOpened() const”, referenced from:
ofApp::setup() in ofApp.o
“cv::VideoCapture::open(int)”, referenced from:
ofApp::setup() in ofApp.o
“cv::VideoCapture::VideoCapture()”, referenced from:
ofApp::ofApp() in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I note there are other topics on very similar subjects but my attempts to follow the advice therein have been fruitless.

I am using xcode 9.2, and openframeworks v0.10.1.

Any help would be much appreciated. No doubt I need to give more information … please let me know.

Many thanks

Hello Dan, does the example examples/computer_vision/opencvExample works for you?

Hi David,
thanks for your response.
yes it does.

To make things easier, I would probably use the opencv addon that comes with openFrameworks, or the ofxCv one Have a look at the examples that come with tofxCv, there are a lot of them that use the camera and maybe some of those fit your needs.

Thank you. I have been making good progress with ofxCv, and will look more closely at tofxCv.

Am I correct in assuming that my problem with using cv classes directly is down to not understanding the complexities of setting up the workspace (linking libraries etc.)…?

Thanks again.

p.s. and can you suggest any further reading?

If you can get examples in ofxCv or ofxOpenCv running, then you can use openCV functions directly. Three things to look out for:

  1. Make sure the headers you need are included in the file where you want to use them (e.g. #include <opencv2/opencv.hpp> or whichever you need).
  2. Make sure you are using fully-qualified namespaces. (e.g. cv::Mat as opposed to just Mat).
  3. There are a lot of openCV classes (highgui, videocapture, etc) that may not be compiled in the version distributed with openFrameworks. This decision was to reduce dependencies and redundancies. openFrameworks already has its own cross-platform video capture, gui and windowing system. As a result, you can usually eliminate that code from openCv examples you might find online. Take a look at how we use the openFrameworks gui, window and video sources (e.g. ofPixels, ofVideoGrabber, of VideoPlayer, etc) as a substitute for the built-in openCV versions of the same.

Thanks very much fellas.

Also we usually don’t compile the highgui module with opencv cause it includes libraries we already include and would clash with them. that module is the one that includes the calls that you are trying to do if i remember well so that’s probably why you are getting undefined symbols.

In order to capture video just use ofVideoGrabber as shown in the opencv and ofxCv examples and things like cv::waitKey don’t make sense in OF cause the program runs an infinte loop that shouldn’t be stopped at anytime as the plain opencv examples usually do.