0

I would like to use OpenCV library with Code::Blocks.

I have already installed OpenCV with the following command line :

sudo port install opencv

The above command created multiple opencv folders in /opt/local/include/, /opt/local/var/macports/software/, /opt/local/var/macports/sources/ and /opt/local/share/.

What should I do now to make it work with Code::Blocks ?

[EDIT 24.06]

Thanks to cyriel, I have managed to install OpenCV and make it work with QT Creator.

To install Homebrew and OpenCV just type the following command lines :

ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"

brew doctor

brew tap homebrew/science

brew install opencv

Then, set cyriel's project settings and try to compile and execute following source code :

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>

using namespace cv;
using namespace std;

int main()
{
    Mat image;
    image = imread("/image-path/image-filename.image-format", CV_LOAD_IMAGE_COLOR);

    if(! image.data )
    {
        cout <<  "Could not open or find the image" << std::endl ;
        return -1;
    }

    namedWindow( "Display window", WINDOW_AUTOSIZE );
    imshow( "Display window", image );
    waitKey(0);
    return 0;
}

and it works just fine !

Regarding Code::Blocks

In Build options > Linker Settings, I have linked all the *.a and *.dylib files that are in the /usr/include/lib/ folder.

In Build options > Search directories > Compiler, I have added /usr/local/lib, /usr/local/include/opencv and /usr/local/include folders

In Build options > Search directories > Linker, I have added /usr/local/lib and /usr/local/include/opencv

I am not familiar with external libraries so I m not really sure if my configuration is correct but it doesn't seem to compile correctly.

-------------- Run: Debug in ImgDownsampling-V1 (compiler: GNU GCC Compiler)---------------

Checking for existence: /Users/Universe/Desktop/Coding/ImgDownsampling-V1/bin/Debug/ImgDownsampling-V1 Executing: osascript -e 'tell app "Terminal"' -e 'activate' -e 'do script "/Applications/CodeBlocks.app/Contents/MacOS/cb_console_runner DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:.:/usr/local/lib:/usr/local/include/opencv /Users/Universe/Desktop/Coding/ImgDownsampling-V1/bin/Debug/ImgDownsampling-V1 "' -e 'end tell' (in /Users/Universe/Desktop/Coding/ImgDownsampling-V1/.)

Terminal doesn't show up...

[EDIT 24.06]

I have tried to change settings and managed to make it work !

Same Code::Blocks configuration as before except that I have cleared all the folders in Build options > Search directories > Linker.

Community
  • 1
  • 1

1 Answers1

0

I have no experience in using Code::Blocks neither port app, but i've sucesfully managed to install OpenCV using brew(it's GREAT!) on Mavericks to work with Qt Creator.
First you need to install OpenCV - brew install opencv. If you want to install it with additional options, just use brew options opencv. Install some version of Qt and Qt Creator (i'm using Qt 4.5, because it's easy to integrate it with OpenCV) and in project settings set:

QMAKE_CXXFLAGS += -std=c++11 -stdlib=libc++
QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.9

LIBS += -L/usr/local/lib

LIBS += \
    -lopencv_calib3d \
    -lopencv_contrib \
    -lopencv_core \
    -lopencv_flann \
    -lopencv_gpu \
    -lopencv_highgui \
    -lopencv_imgproc \
    -lopencv_legacy \
    -lopencv_ml \
    -lopencv_objdetect \
    -lopencv_ocl \
    -lopencv_photo \
    -lopencv_stitching \
    -lopencv_superres \
    -lopencv_ts \
    -lopencv_video \
    -lopencv_videostab
    -lopencv_nonfree

INCLUDEPATH += /usr/local/include/opencv \
                   /usr/include/opencv \
                /usr/local/include 
DEPENDPATH += /usr/local/include/opencv/include

Config is quite obvious, except this line - QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.9. If you want to know why you need to use it, read this.
Configuring Code::Blocks should be quite similar, if you will have any problem try starting with Qt and then moving to Code::Blocks.

Community
  • 1
  • 1
cyriel
  • 3,522
  • 17
  • 34