From 529ffd82b50bf7f94440de0806cc10d53678a487 Mon Sep 17 00:00:00 2001 From: Olivier XILLO Date: Fri, 15 Mar 2019 13:44:53 +0100 Subject: [PATCH] opencv4 support for msys2 and all linux platforms where available (#6252) --- CHANGELOG.md | 7 ++ addons/ofxOpenCv/addon_config.mk | 27 ++---- addons/ofxOpenCv/src/ofxCvConstants.h | 11 ++- addons/ofxOpenCv/src/ofxCvHaarFinder.cpp | 95 ++++++++++++++++++- addons/ofxOpenCv/src/ofxCvHaarFinder.h | 4 + addons/ofxOpenCv/src/ofxCvImage.cpp | 8 ++ scripts/ci/ios/build.sh | 2 +- scripts/ci/linuxarmv7l/install.sh | 1 + .../linux/archlinux/install_dependencies.sh | 13 +++ .../archlinux_armv7/install_dependencies.sh | 13 +++ scripts/linux/chip/install_dependencies.sh | 17 +++- scripts/linux/debian/install_dependencies.sh | 12 +++ scripts/linux/el6/install_dependencies.sh | 17 +++- scripts/linux/fedora/install_dependencies.sh | 17 +++- scripts/linux/ubuntu/install_dependencies.sh | 15 ++- scripts/msys2/install_dependencies.sh | 16 ++++ 16 files changed, 246 insertions(+), 29 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a2a1a02e3a5..d2e4ed33980 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +ADDONS +------ +### ofxOpenCv +- added support for OpenCV4 : deprecated C functions replaced by their C++ counterpart. Also fix issue due to incorrect pkg-config package [commit](https://github.com/openframeworks/openFrameworks/commit/) + +-------------------------------------- + ``` .----. .---. .----. .---. / .. \ /_ | / .. \ /_ | diff --git a/addons/ofxOpenCv/addon_config.mk b/addons/ofxOpenCv/addon_config.mk index bcad39fc612..bd7193d588f 100644 --- a/addons/ofxOpenCv/addon_config.mk +++ b/addons/ofxOpenCv/addon_config.mk @@ -61,7 +61,7 @@ common: # ADDON_LIBS_EXCLUDE = linux64: - ADDON_PKG_CONFIG_LIBRARIES = opencv harfbuzz + ADDON_PKG_CONFIG_LIBRARIES = opencv4 harfbuzz ADDON_LIBS_EXCLUDE = libs/opencv/% ADDON_INCLUDES_EXCLUDE = libs/opencv ADDON_INCLUDES_EXCLUDE += libs/opencv/% @@ -79,67 +79,60 @@ linuxarmv6l: ADDON_INCLUDES_EXCLUDE += libs/opencv/% linuxarmv7l: - ADDON_PKG_CONFIG_LIBRARIES = opencv + ADDON_PKG_CONFIG_LIBRARIES = opencv4 ADDON_LIBS_EXCLUDE = libs/opencv/% ADDON_INCLUDES_EXCLUDE = libs/opencv ADDON_INCLUDES_EXCLUDE += libs/opencv/% msys2: - ADDON_PKG_CONFIG_LIBRARIES = opencv + ADDON_PKG_CONFIG_LIBRARIES = opencv4 ADDON_LIBS_EXCLUDE = libs/opencv/% ADDON_INCLUDES_EXCLUDE = libs/opencv ADDON_INCLUDES_EXCLUDE += libs/opencv/% android/x86: ADDON_LIBS = - ADDON_LIBS += libs/opencv/lib/android/x86/libopencv_shape.a + ADDON_LIBS += libs/opencv/lib/android/x86/libopencv_dnn.a ADDON_LIBS += libs/opencv/lib/android/x86/libopencv_photo.a - ADDON_LIBS += libs/opencv/lib/android/x86/libopencv_superres.a ADDON_LIBS += libs/opencv/lib/android/x86/libopencv_stitching.a ADDON_LIBS += libs/opencv/lib/android/x86/libopencv_calib3d.a ADDON_LIBS += libs/opencv/lib/android/x86/libopencv_features2d.a ADDON_LIBS += libs/opencv/lib/android/x86/libopencv_objdetect.a - ADDON_LIBS += libs/opencv/lib/android/x86/libopencv_videostab.a + ADDON_LIBS += libs/opencv/lib/android/x86/libopencv_videoio.a ADDON_LIBS += libs/opencv/lib/android/x86/libopencv_video.a ADDON_LIBS += libs/opencv/lib/android/x86/libopencv_imgproc.a ADDON_LIBS += libs/opencv/lib/android/x86/libopencv_ml.a ADDON_LIBS += libs/opencv/lib/android/x86/libopencv_core.a ADDON_LIBS += libs/opencv/lib/android/x86/libopencv_flann.a - ADDON_LIBS += libs/opencv/lib/android/x86/libopencv_contrib.a android/armeabi-v7a: ADDON_LIBS = - ADDON_LIBS += libs/opencv/lib/android/armeabi-v7a/libopencv_shape.a + ADDON_LIBS += libs/opencv/lib/android/armeabi-v7a/libopencv_dnn.a ADDON_LIBS += libs/opencv/lib/android/armeabi-v7a/libopencv_photo.a - ADDON_LIBS += libs/opencv/lib/android/armeabi-v7a/libopencv_superres.a ADDON_LIBS += libs/opencv/lib/android/armeabi-v7a/libopencv_stitching.a ADDON_LIBS += libs/opencv/lib/android/armeabi-v7a/libopencv_calib3d.a ADDON_LIBS += libs/opencv/lib/android/armeabi-v7a/libopencv_features2d.a ADDON_LIBS += libs/opencv/lib/android/armeabi-v7a/libopencv_objdetect.a - ADDON_LIBS += libs/opencv/lib/android/armeabi-v7a/libopencv_videostab.a + ADDON_LIBS += libs/opencv/lib/android/armeabi-v7a/libopencv_videoio.a ADDON_LIBS += libs/opencv/lib/android/armeabi-v7a/libopencv_video.a ADDON_LIBS += libs/opencv/lib/android/armeabi-v7a/libopencv_imgproc.a ADDON_LIBS += libs/opencv/lib/android/armeabi-v7a/libopencv_ml.a ADDON_LIBS += libs/opencv/lib/android/armeabi-v7a/libopencv_core.a ADDON_LIBS += libs/opencv/lib/android/armeabi-v7a/libopencv_flann.a - ADDON_LIBS += libs/opencv/lib/android/armeabi-v7a/libopencv_contrib.a emscripten: ADDON_LIBS = - ADDON_LIBS += libs/opencv/lib/emscripten/libopencv_shape.a + ADDON_LIBS += libs/opencv/lib/emscripten/libopencv_dnn.a ADDON_LIBS += libs/opencv/lib/emscripten/libopencv_photo.a - ADDON_LIBS += libs/opencv/lib/emscripten/libopencv_superres.a - ADDON_LIBS += libs/opencv/lib/emscripten/libopencv_stitching.a ADDON_LIBS += libs/opencv/lib/emscripten/libopencv_calib3d.a ADDON_LIBS += libs/opencv/lib/emscripten/libopencv_features2d.a ADDON_LIBS += libs/opencv/lib/emscripten/libopencv_objdetect.a - ADDON_LIBS += libs/opencv/lib/emscripten/libopencv_videostab.a ADDON_LIBS += libs/opencv/lib/emscripten/libopencv_video.a ADDON_LIBS += libs/opencv/lib/emscripten/libopencv_imgproc.a - ADDON_LIBS += libs/opencv/lib/emscripten/libopencv_ml.a ADDON_LIBS += libs/opencv/lib/emscripten/libopencv_core.a ADDON_LIBS += libs/opencv/lib/emscripten/libopencv_flann.a - ADDON_LIBS += libs/opencv/lib/emscripten/libopencv_contrib.a + ADDON_LIBS += libs/opencv/lib/emscripten/liblibprotobuf.a + ADDON_LIBS += libs/opencv/lib/emscripten/libquirc.a ADDON_LIBS += libs/opencv/lib/emscripten/libzlib.a diff --git a/addons/ofxOpenCv/src/ofxCvConstants.h b/addons/ofxOpenCv/src/ofxCvConstants.h index a8d4f26ed48..6f4dadade52 100644 --- a/addons/ofxOpenCv/src/ofxCvConstants.h +++ b/addons/ofxOpenCv/src/ofxCvConstants.h @@ -7,8 +7,15 @@ #undef MAX #endif -#include "cv.h" -#include "opencv2/opencv.hpp" +#include "opencv2/core/version.hpp" +#if CV_MAJOR_VERSION < 4 + #include "cv.h" + #define USE_OLD_CV +#else + #include "opencv2/opencv.hpp" + #include "opencv2/imgproc/imgproc_c.h" +#endif + #include #include "ofMain.h" diff --git a/addons/ofxOpenCv/src/ofxCvHaarFinder.cpp b/addons/ofxOpenCv/src/ofxCvHaarFinder.cpp index 06162e5415a..42945f8b8b4 100644 --- a/addons/ofxOpenCv/src/ofxCvHaarFinder.cpp +++ b/addons/ofxOpenCv/src/ofxCvHaarFinder.cpp @@ -12,14 +12,18 @@ static bool sort_carea_compare( const ofxCvBlob & a, const ofxCvBlob & b) { } ofxCvHaarFinder::ofxCvHaarFinder() { +#ifdef USE_OLD_CV cascade = NULL; +#endif scaleHaar = 1.08; neighbors = 2; img.setUseTexture(false); } ofxCvHaarFinder::ofxCvHaarFinder(const ofxCvHaarFinder& finder) { +#ifdef USE_OLD_CV cascade = NULL; +#endif scaleHaar = finder.scaleHaar; neighbors = finder.neighbors; img.setUseTexture(false); @@ -27,8 +31,10 @@ ofxCvHaarFinder::ofxCvHaarFinder(const ofxCvHaarFinder& finder) { } ofxCvHaarFinder::~ofxCvHaarFinder() { +#ifdef USE_OLD_CV if(cascade != NULL) cvReleaseHaarClassifierCascade(&cascade); +#endif } // low values - more accurate - eg: 1.01 @@ -44,12 +50,13 @@ void ofxCvHaarFinder::setNeighbors(unsigned neighbors) { } void ofxCvHaarFinder::setup(std::string haarFile) { - if(cascade != NULL) - cvReleaseHaarClassifierCascade(&cascade); this->haarFile = haarFile; haarFile = ofToDataPath(haarFile); +#ifdef USE_OLD_CV + if(cascade != NULL) + cvReleaseHaarClassifierCascade(&cascade); cascade = (CvHaarClassifierCascade*) cvLoad(haarFile.c_str(), 0, 0, 0); #ifdef HAAR_HACK @@ -65,6 +72,11 @@ void ofxCvHaarFinder::setup(std::string haarFile) { if (!cascade) ofLogError("ofxCvHaarFinder") << "setup(): couldn't load Haar cascade file: \"" << haarFile << "\""; +#else + cascade.load( haarFile ); + if( cascade.empty() ) + ofLogError("ofxCvHaarFinder") << "setup(): couldn't load Haar cascade file: \"" << haarFile << "\""; +#endif //USE_OLD_CV } @@ -161,6 +173,7 @@ int ofxCvHaarFinder::findHaarObjects(const ofxCvGrayscaleImage& input, int nHaarResults = 0; +#ifdef USE_OLD_CV if (cascade) { if (!blobs.empty()) blobs.clear(); @@ -243,5 +256,83 @@ int ofxCvHaarFinder::findHaarObjects(const ofxCvGrayscaleImage& input, cvReleaseMemStorage(&storage); } +#else + if( cascade.empty() ) + return 0; + + // we make a copy of the input image here + // because we need to equalize it. + + if (img.width == input.width && img.height == input.height) { + img.resetROI(); + img = input; + } else { + img.clear(); + img.allocate(input.width, input.height); + img = input; + } + + img.setROI(x, y, w, h); + cvEqualizeHist(img.getCvImage(), img.getCvImage()); + + /* + Alternative modes: + + cv::CASCADE_DO_CANNY_PRUNING + Regions without edges are ignored. + + cv::CASCADE_SCALE_IMAGE + Scale the image rather than the detector + (sometimes yields speed increases). + + cv::CASCADE_FIND_BIGGEST_OBJECT + Only return the largest result. + + cv::CASCADE_DO_ROUGH_SEARCH + When BIGGEST_OBJECT is enabled, stop at + the first scale for which multiple results + are found. + */ + + std::vector haarResults; + cascade.detectMultiScale(cv::cvarrToMat(img.getCvImage()), haarResults, scaleHaar, neighbors, cv::CASCADE_DO_CANNY_PRUNING, + cv::Size(minWidth, minHeight) ); + + nHaarResults = haarResults.size(); + + for (int i = 0; i < nHaarResults; i++ ) { + //ofLogNotice("ofxCvHaarFinder") << "findHaarObjects(): " << i << " objects"; + + ofxCvBlob blob; + + cv::Rect r = haarResults[i]; + + float area = r.width * r.height; + float length = (r.width * 2) + (r.height * 2); + float centerx = (r.x) + (r.width / 2.0); + float centery = (r.y) + (r.height / 2.0); + + blob.area = fabs(area); + blob.hole = area < 0 ? true : false; + blob.length = length; + blob.boundingRect.x = r.x + x; + blob.boundingRect.y = r.y + y; + blob.boundingRect.width = r.width; + blob.boundingRect.height = r.height; + blob.centroid.x = centerx; + blob.centroid.y = centery; + blob.pts.push_back(ofPoint(r.x, r.y)); + blob.pts.push_back(ofPoint(r.x + r.width, r.y)); + blob.pts.push_back(ofPoint(r.x + r.width, r.y + r.height)); + blob.pts.push_back(ofPoint(r.x, r.y + r.height)); + + blobs.push_back(blob); + } + + // sort the pointers based on size + if( blobs.size() > 1 ) { + sort( blobs.begin(), blobs.end(), sort_carea_compare ); + } +#endif // USE_OLD_CV return nHaarResults; } diff --git a/addons/ofxOpenCv/src/ofxCvHaarFinder.h b/addons/ofxOpenCv/src/ofxCvHaarFinder.h index cc12f3583d9..0160b65f64f 100644 --- a/addons/ofxOpenCv/src/ofxCvHaarFinder.h +++ b/addons/ofxOpenCv/src/ofxCvHaarFinder.h @@ -46,7 +46,11 @@ class ofxCvHaarFinder { void draw(float x, float y); protected: +#ifdef USE_OLD_CV CvHaarClassifierCascade* cascade; +#else + cv::CascadeClassifier cascade; +#endif //USE_OLD_CV std::string haarFile; ofxCvGrayscaleImage img; float scaleHaar; diff --git a/addons/ofxOpenCv/src/ofxCvImage.cpp b/addons/ofxOpenCv/src/ofxCvImage.cpp index 6637e5261d2..8da07098881 100644 --- a/addons/ofxOpenCv/src/ofxCvImage.cpp +++ b/addons/ofxOpenCv/src/ofxCvImage.cpp @@ -651,7 +651,15 @@ void ofxCvImage::undistort( float radialDistX, float radialDistY, float distortionCoeffs[] = { radialDistX, radialDistY, tangentDistX, tangentDistY }; CvMat _a = cvMat( 3, 3, CV_32F, (void*)camIntrinsics ); CvMat _k = cvMat( 4, 1, CV_32F, (void*)distortionCoeffs ); +#ifdef USE_OLD_CV cvUndistort2( cvImage, cvImageTemp, &_a, &_k, 0 ); +#else + cv::Mat src = cv::cvarrToMat(cvImage), dst = cv::cvarrToMat(cvImageTemp); + cv::Mat A = cv::cvarrToMat(&_a), distCoeffs = cv::cvarrToMat(&_k); + + CV_Assert( src.size() == dst.size() && src.type() == dst.type() ); + cv::undistort( src, dst, A, distCoeffs ); +#endif // USE_OLD_CV swapTemp(); flagImageChanged(); } diff --git a/scripts/ci/ios/build.sh b/scripts/ci/ios/build.sh index f0c153fb52c..12bd7aa4b4d 100755 --- a/scripts/ci/ios/build.sh +++ b/scripts/ci/ios/build.sh @@ -4,4 +4,4 @@ echo "Building openFrameworks - iOS Template Project" ROOT=${TRAVIS_BUILD_DIR:-"$( cd "$(dirname "$0")/../../.." ; pwd -P )"} source $ROOT/scripts/ci/ccache.sh -xcodebuild -project "$ROOT/scripts/templates/ios/emptyExample.xcodeproj" -target emptyExample -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO +xcodebuild -project "$ROOT/scripts/templates/ios/emptyExample.xcodeproj" -target emptyExample -sdk 'iphoneos8.0' ARCHS='armv7' diff --git a/scripts/ci/linuxarmv7l/install.sh b/scripts/ci/linuxarmv7l/install.sh index 999c4b612d9..4dbdf6fcc3b 100755 --- a/scripts/ci/linuxarmv7l/install.sh +++ b/scripts/ci/linuxarmv7l/install.sh @@ -92,6 +92,7 @@ createArchImg(){ tar xzf ~/ArchLinuxARM-rpi-2-latest.tar.gz --no-same-owner -C ~/archlinux/ 2>&1 >/dev/null | grep -v "tar: Ignoring unknown extended header keyword" sed -i s_/etc/pacman_$HOME/archlinux/etc/pacman_g ~/archlinux/etc/pacman.conf sed -i "s/Required DatabaseOptional/Never/g" ~/archlinux/etc/pacman.conf + pacman -Sy archlinux-keyring && pacman -Syyu pacman --noconfirm -S ccache pacman --noconfirm -r ~/archlinux/ --config ~/archlinux/etc/pacman.conf --arch=armv7h -Syu pacman --noconfirm -r ~/archlinux/ --config ~/archlinux/etc/pacman.conf --arch=armv7h -S \ diff --git a/scripts/linux/archlinux/install_dependencies.sh b/scripts/linux/archlinux/install_dependencies.sh index 5d0f207a495..1f108a1672e 100755 --- a/scripts/linux/archlinux/install_dependencies.sh +++ b/scripts/linux/archlinux/install_dependencies.sh @@ -17,3 +17,16 @@ if [ $exit_code != 0 ]; then echo "error installing packages, there could be an error with your internet connection" exit $exit_code fi + +# Update addon_config.mk files to use OpenCV 3 or 4 depending on what's installed +addons_dir="$(readlink -f "$ROOT/../../../addons")" +$(pkg-config opencv4 --exists) +exit_code=$? +if [ $exit_code != 0 ]; then + echo "Updating ofxOpenCV to use openCV3" + sed -i -E 's/ADDON_PKG_CONFIG_LIBRARIES =(.*)opencv4(.*)$/ADDON_PKG_CONFIG_LIBRARIES =\1opencv\2/' "$addons_dir/ofxOpenCv/addon_config.mk" +else + echo "Updating ofxOpenCV to use openCV4" + sed -i -E 's/ADDON_PKG_CONFIG_LIBRARIES =(.*)opencv\s/ADDON_PKG_CONFIG_LIBRARIES =\1opencv4 /g' "$addons_dir/ofxOpenCv/addon_config.mk" + sed -i -E 's/ADDON_PKG_CONFIG_LIBRARIES =(.*)opencv$/ADDON_PKG_CONFIG_LIBRARIES =\1opencv4/g' "$addons_dir/ofxOpenCv/addon_config.mk" +fi \ No newline at end of file diff --git a/scripts/linux/archlinux_armv7/install_dependencies.sh b/scripts/linux/archlinux_armv7/install_dependencies.sh index b8bb6d6bd4d..5e84d2c2ec5 100644 --- a/scripts/linux/archlinux_armv7/install_dependencies.sh +++ b/scripts/linux/archlinux_armv7/install_dependencies.sh @@ -20,3 +20,16 @@ if [ $exit_code != 0 ]; then echo "error installing packages, there could be an error with your internet connection" exit $exit_code fi + +# Update addon_config.mk files to use OpenCV 3 or 4 depending on what's installed +addons_dir="$(readlink -f "$ROOT/../../../addons")" +$(pkg-config opencv4 --exists) +exit_code=$? +if [ $exit_code != 0 ]; then + echo "Updating ofxOpenCV to use openCV3" + sed -i -E 's/ADDON_PKG_CONFIG_LIBRARIES =(.*)opencv4(.*)$/ADDON_PKG_CONFIG_LIBRARIES =\1opencv\2/' "$addons_dir/ofxOpenCv/addon_config.mk" +else + echo "Updating ofxOpenCV to use openCV4" + sed -i -E 's/ADDON_PKG_CONFIG_LIBRARIES =(.*)opencv\s/ADDON_PKG_CONFIG_LIBRARIES =\1opencv4 /g' "$addons_dir/ofxOpenCv/addon_config.mk" + sed -i -E 's/ADDON_PKG_CONFIG_LIBRARIES =(.*)opencv$/ADDON_PKG_CONFIG_LIBRARIES =\1opencv4/g' "$addons_dir/ofxOpenCv/addon_config.mk" +fi \ No newline at end of file diff --git a/scripts/linux/chip/install_dependencies.sh b/scripts/linux/chip/install_dependencies.sh index f474e35c02c..965b2cd24c4 100644 --- a/scripts/linux/chip/install_dependencies.sh +++ b/scripts/linux/chip/install_dependencies.sh @@ -77,15 +77,28 @@ if [ $GCC_MAJOR_GT_4 -eq 1 ]; then echo "It seems you are running gcc 5 or later, due to incomatible ABI with previous versions" echo "we need to recompile poco. This will take a while" read -p "Press any key to continue... " -n1 -s - + sys_cores=$(getconf _NPROCESSORS_ONLN) if [ $sys_cores -gt 1 ]; then cores=$(($sys_cores-1)) else cores=1 fi - + DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) cd ${DIR}/../../apothecary/apothecary ./apothecary -j${cores} update poco fi + +# Update addon_config.mk files to use OpenCV 3 or 4 depending on what's installed +addons_dir="$(readlink -f "$ROOT/../../../addons")" +$(pkg-config opencv4 --exists) +exit_code=$? +if [ $exit_code != 0 ]; then + echo "Updating ofxOpenCV to use openCV3" + sed -i -E 's/ADDON_PKG_CONFIG_LIBRARIES =(.*)opencv4(.*)$/ADDON_PKG_CONFIG_LIBRARIES =\1opencv\2/' "$addons_dir/ofxOpenCv/addon_config.mk" +else + echo "Updating ofxOpenCV to use openCV4" + sed -i -E 's/ADDON_PKG_CONFIG_LIBRARIES =(.*)opencv\s/ADDON_PKG_CONFIG_LIBRARIES =\1opencv4 /g' "$addons_dir/ofxOpenCv/addon_config.mk" + sed -i -E 's/ADDON_PKG_CONFIG_LIBRARIES =(.*)opencv$/ADDON_PKG_CONFIG_LIBRARIES =\1opencv4/g' "$addons_dir/ofxOpenCv/addon_config.mk" +fi \ No newline at end of file diff --git a/scripts/linux/debian/install_dependencies.sh b/scripts/linux/debian/install_dependencies.sh index 0b347cfa355..0c8001f7d53 100755 --- a/scripts/linux/debian/install_dependencies.sh +++ b/scripts/linux/debian/install_dependencies.sh @@ -74,3 +74,15 @@ echo "If you are running a version of debian greated than 8 OF needs to install apt-get install libpoco-dev cp $ROOT/../extra/poco_config.mk $ROOT/../../../addons/ofxPoco/addon_config.mk +# Update addon_config.mk files to use OpenCV 3 or 4 depending on what's installed +addons_dir="$(readlink -f "$ROOT/../../../addons")" +$(pkg-config opencv4 --exists) +exit_code=$? +if [ $exit_code != 0 ]; then + echo "Updating ofxOpenCV to use openCV3" + sed -i -E 's/ADDON_PKG_CONFIG_LIBRARIES =(.*)opencv4(.*)$/ADDON_PKG_CONFIG_LIBRARIES =\1opencv\2/' "$addons_dir/ofxOpenCv/addon_config.mk" +else + echo "Updating ofxOpenCV to use openCV4" + sed -i -E 's/ADDON_PKG_CONFIG_LIBRARIES =(.*)opencv\s/ADDON_PKG_CONFIG_LIBRARIES =\1opencv4 /g' "$addons_dir/ofxOpenCv/addon_config.mk" + sed -i -E 's/ADDON_PKG_CONFIG_LIBRARIES =(.*)opencv$/ADDON_PKG_CONFIG_LIBRARIES =\1opencv4/g' "$addons_dir/ofxOpenCv/addon_config.mk" +fi \ No newline at end of file diff --git a/scripts/linux/el6/install_dependencies.sh b/scripts/linux/el6/install_dependencies.sh index 7966b8d84ac..68ac3609879 100755 --- a/scripts/linux/el6/install_dependencies.sh +++ b/scripts/linux/el6/install_dependencies.sh @@ -26,15 +26,28 @@ if [ $GCC_MAJOR_GT_4 -eq 1 ]; then echo "It seems you are running gcc 5 or later, due to incomatible ABI with previous versions" echo "we need to recompile poco. This will take a while" read -p "Press any key to continue... " -n1 -s - + sys_cores=$(getconf _NPROCESSORS_ONLN) if [ $sys_cores -gt 1 ]; then cores=$(($sys_cores-1)) else cores=1 fi - + DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) cd ${DIR}/../../apothecary/apothecary ./apothecary -j${cores} update poco fi + +# Update addon_config.mk files to use OpenCV 3 or 4 depending on what's installed +addons_dir="$(readlink -f "$ROOT/../../../addons")" +$(pkg-config opencv4 --exists) +exit_code=$? +if [ $exit_code != 0 ]; then + echo "Updating ofxOpenCV to use openCV3" + sed -i -E 's/ADDON_PKG_CONFIG_LIBRARIES =(.*)opencv4(.*)$/ADDON_PKG_CONFIG_LIBRARIES =\1opencv\2/' "$addons_dir/ofxOpenCv/addon_config.mk" +else + echo "Updating ofxOpenCV to use openCV4" + sed -i -E 's/ADDON_PKG_CONFIG_LIBRARIES =(.*)opencv\s/ADDON_PKG_CONFIG_LIBRARIES =\1opencv4 /g' "$addons_dir/ofxOpenCv/addon_config.mk" + sed -i -E 's/ADDON_PKG_CONFIG_LIBRARIES =(.*)opencv$/ADDON_PKG_CONFIG_LIBRARIES =\1opencv4/g' "$addons_dir/ofxOpenCv/addon_config.mk" +fi \ No newline at end of file diff --git a/scripts/linux/fedora/install_dependencies.sh b/scripts/linux/fedora/install_dependencies.sh index e12007e7951..97d79733fe5 100755 --- a/scripts/linux/fedora/install_dependencies.sh +++ b/scripts/linux/fedora/install_dependencies.sh @@ -26,15 +26,28 @@ if [ $GCC_MAJOR_GT_4 -eq 1 ]; then echo "It seems you are running gcc 5 or later, due to incomatible ABI with previous versions" echo "we need to recompile poco. This will take a while" read -p "Press any key to continue... " -n1 -s - + sys_cores=$(getconf _NPROCESSORS_ONLN) if [ $sys_cores -gt 1 ]; then cores=$(($sys_cores-1)) else cores=1 fi - + DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) cd ${DIR}/../../apothecary/apothecary ./apothecary -j${cores} update poco fi + +# Update addon_config.mk files to use OpenCV 3 or 4 depending on what's installed +addons_dir="$(readlink -f "$ROOT/../../../addons")" +$(pkg-config opencv4 --exists) +exit_code=$? +if [ $exit_code != 0 ]; then + echo "Updating ofxOpenCV to use openCV3" + sed -i -E 's/ADDON_PKG_CONFIG_LIBRARIES =(.*)opencv4(.*)$/ADDON_PKG_CONFIG_LIBRARIES =\1opencv\2/' "$addons_dir/ofxOpenCv/addon_config.mk" +else + echo "Updating ofxOpenCV to use openCV4" + sed -i -E 's/ADDON_PKG_CONFIG_LIBRARIES =(.*)opencv\s/ADDON_PKG_CONFIG_LIBRARIES =\1opencv4 /g' "$addons_dir/ofxOpenCv/addon_config.mk" + sed -i -E 's/ADDON_PKG_CONFIG_LIBRARIES =(.*)opencv$/ADDON_PKG_CONFIG_LIBRARIES =\1opencv4/g' "$addons_dir/ofxOpenCv/addon_config.mk" +fi \ No newline at end of file diff --git a/scripts/linux/ubuntu/install_dependencies.sh b/scripts/linux/ubuntu/install_dependencies.sh index 3d2cc01c0ae..438dc1d76ce 100755 --- a/scripts/linux/ubuntu/install_dependencies.sh +++ b/scripts/linux/ubuntu/install_dependencies.sh @@ -177,7 +177,7 @@ else GLFW_PKG= fi -PACKAGES="curl libjack-jackd2-0 libjack-jackd2-dev freeglut3-dev libasound2-dev libxmu-dev libxxf86vm-dev g++${CXX_VER} libgl1-mesa-dev${XTAG} libglu1-mesa-dev libraw1394-dev libudev-dev libdrm-dev libglew-dev libopenal-dev libsndfile-dev libfreeimage-dev libcairo2-dev libfreetype6-dev libssl-dev libpulse-dev libusb-1.0-0-dev libgtk${GTK_VERSION}-dev libopencv-dev libassimp-dev librtaudio-dev libboost-filesystem${BOOST_VER}-dev libgstreamer${GSTREAMER_VERSION}-dev libgstreamer-plugins-base${GSTREAMER_VERSION}-dev ${GSTREAMER_FFMPEG} gstreamer${GSTREAMER_VERSION}-pulseaudio gstreamer${GSTREAMER_VERSION}-x gstreamer${GSTREAMER_VERSION}-plugins-bad gstreamer${GSTREAMER_VERSION}-alsa gstreamer${GSTREAMER_VERSION}-plugins-base gstreamer${GSTREAMER_VERSION}-plugins-good gdb ${GLFW_PKG} liburiparser-dev libcurl4-openssl-dev libpugixml-dev" +PACKAGES="curl libjack-jackd2-0 libjack-jackd2-dev freeglut3-dev libasound2-dev libxmu-dev libxxf86vm-dev g++${CXX_VER} libgl1-mesa-dev${XTAG} libglu1-mesa-dev libraw1394-dev libudev-dev libdrm-dev libglew-dev libopenal-dev libsndfile-dev libfreeimage-dev libcairo2-dev libfreetype6-dev libssl-dev libpulse-dev libusb-1.0-0-dev libgtk${GTK_VERSION}-dev libopencv-dev libassimp-dev librtaudio-dev libboost-filesystem${BOOST_VER}-dev libgstreamer${GSTREAMER_VERSION}-dev libgstreamer-plugins-base${GSTREAMER_VERSION}-dev ${GSTREAMER_FFMPEG} gstreamer${GSTREAMER_VERSION}-pulseaudio gstreamer${GSTREAMER_VERSION}-x gstreamer${GSTREAMER_VERSION}-plugins-bad gstreamer${GSTREAMER_VERSION}-alsa gstreamer${GSTREAMER_VERSION}-plugins-base gstreamer${GSTREAMER_VERSION}-plugins-good gdb ${GLFW_PKG} liburiparser-dev libcurl4-openssl-dev libpugixml-dev libgconf2-4 libgtk2.0-0" echo "installing OF dependencies" echo "OF needs to install the following packages using apt-get:" @@ -228,3 +228,16 @@ if [[ $MAJOR_VERSION -lt 14 || ($MAJOR_VERSION -eq 14 && $MINOR_VERSION -eq 4) ] sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc${CXX_VER} 1 --force sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++${CXX_VER} 1 --force fi + +# Update addon_config.mk files to use OpenCV 3 or 4 depending on what's installed +addons_dir="$(readlink -f "$ROOT/../../../addons")" +$(pkg-config opencv4 --exists) +exit_code=$? +if [ $exit_code != 0 ]; then + echo "Updating ofxOpenCV to use openCV3" + sed -i -E 's/ADDON_PKG_CONFIG_LIBRARIES =(.*)opencv4(.*)$/ADDON_PKG_CONFIG_LIBRARIES =\1opencv\2/' "$addons_dir/ofxOpenCv/addon_config.mk" +else + echo "Updating ofxOpenCV to use openCV4" + sed -i -E 's/ADDON_PKG_CONFIG_LIBRARIES =(.*)opencv\s/ADDON_PKG_CONFIG_LIBRARIES =\1opencv4 /g' "$addons_dir/ofxOpenCv/addon_config.mk" + sed -i -E 's/ADDON_PKG_CONFIG_LIBRARIES =(.*)opencv$/ADDON_PKG_CONFIG_LIBRARIES =\1opencv4/g' "$addons_dir/ofxOpenCv/addon_config.mk" +fi \ No newline at end of file diff --git a/scripts/msys2/install_dependencies.sh b/scripts/msys2/install_dependencies.sh index e7969f281b9..18267268dbd 100644 --- a/scripts/msys2/install_dependencies.sh +++ b/scripts/msys2/install_dependencies.sh @@ -1,5 +1,7 @@ #!/usr/bin/env bash +script_dir="$( dirname "$(readlink -f "$0")" )" + function usage { echo usage: echo ./install_dependencies.sh [--help] [--noconfirm] @@ -101,3 +103,17 @@ if [ $exit_code != 0 ]; then echo "error installing packages, there could be an error with your internet connection" exit $exit_code fi + + +# Update addon_config.mk files to use OpenCV 3 or 4 depending on what's installed +addons_dir="$(readlink -f "$script_dir/../../addons")" +$(pkg-config opencv4 --exists) +exit_code=$? +if [ $exit_code != 0 ]; then + echo "Updating ofxOpenCV to use openCV3" + sed -i -E 's/ADDON_PKG_CONFIG_LIBRARIES =(.*)opencv4(.*)$/ADDON_PKG_CONFIG_LIBRARIES =\1opencv\2/' "$addons_dir/ofxOpenCv/addon_config.mk" +else + echo "Updating ofxOpenCV to use openCV4" + sed -i -E 's/ADDON_PKG_CONFIG_LIBRARIES =(.*)opencv\s/ADDON_PKG_CONFIG_LIBRARIES =\1opencv4 /g' "$addons_dir/ofxOpenCv/addon_config.mk" + sed -i -E 's/ADDON_PKG_CONFIG_LIBRARIES =(.*)opencv$/ADDON_PKG_CONFIG_LIBRARIES =\1opencv4/g' "$addons_dir/ofxOpenCv/addon_config.mk" +fi