Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build fails on OSX with latest FFMPEG release #503

Open
goulash1971 opened this issue Feb 10, 2019 · 7 comments
Open

Build fails on OSX with latest FFMPEG release #503

goulash1971 opened this issue Feb 10, 2019 · 7 comments

Comments

@goulash1971
Copy link

goulash1971 commented Feb 10, 2019

Hi there - this is more of an FYI / PSA than an issue :)

I have been experiencing a build error on OSX Mojave ...

[ 87%] Building CXX object modules/calib3d/CMakeFiles/opencv_calib3d.dir/src/calibinit.cpp.o
In file included from /Users/stuart/Workspaces/GITHUB/opencv4nodejs/node_modules/opencv-build/opencv/opencv_contrib/modules/text/src/erfilter.cpp:43:
/Users/stuart/Workspaces/GITHUB/opencv4nodejs/node_modules/opencv-build/opencv/opencv_contrib/modules/text/src/precomp.hpp:54:10: fatal error:
      'tesseract/baseapi.h' file not found
#include <tesseract/baseapi.h>
         ^~~~~~~~~~~~~~~~~~~~~

Looking at a bunch of other issues that have been raised and mostly solved, it appears that this is in part due to the presences of tesseract on my machine (see issue #179). Prior to this change the the brew formula for ffmpeg ...

Homebrew/homebrew-core@3e99e5d#diff-8f4deb87ce96b9c5efe97be3288bb406

.. tesseract was not automatically installed and therefore when the auto-build executed the tesseract library was not found etc.

I've checked that the tesseract header files are installed correctly by brew, and these seem to be in the right place (/usr/local/include/tesseract), so I am guessing that there is a problem with the opencv build scripts.

I haven't got time to start debugging all of that so my work around is (horribly) to rollback the ffmpeg install for the time being.

UPDATE

Whilst the build goes through I have 'amused' myself by digging into the CMake files for OpenCV and I think that the problem I am getting is related to this change ...

opencv/opencv_contrib@fdb575d#diff-cad4fd9d74cc81b36a9dc481ed253200

.. it looks like the Tesseract_INCLUDE_DIRS should be set (see https://github.com/opencv/opencv_contrib/blob/3.4/modules/text/cmake/FindTesseract.cmake).

Anyway, there is a 'switch' that can block the inclusion of the tesseract OCR (OPENCV_FIND_TESSERACT) ... just not sure where it could be set ... any ideas @justadudewhohacks

@goulash1971
Copy link
Author

goulash1971 commented Feb 12, 2019

UPDATE

Spent a little longer looking at this and, the fix or Tesseract_INCLUDE_DIRS (i.e opencv/opencv_contrib@fdb575d#diff-cad4fd9d74cc81b36a9dc481ed253200) hasn't been included in any of the releases yet (either v3.x or v4.x of opencv_contrib).

The fix was committed to the master branch on 7th January 2019, long after 3.4.3 was released on the 28th August 2018.

Also, I set OPENCV_FIND_TESSERACT=NO using the OPENCV4NODEJS_AUTOBUILD_FLAGS option that was added recently in the hope that it would skip all of the tesseract stuff, but that didn't work.

Debugging the cmake files, and since the CMAKE_CROSSCOMPILING flag defaults to FALSE line #4 in opencv_contrib/modules/text/CMakeLists.txt ...

if(NOT CMAKE_CROSSCOMPILING OR OPENCV_FIND_TESSERACT)

This means that, irrespective of what I set OPENCV_FIND_TESSERACT to it goes and finds tesseract and lep using pkg_check_modules (on my machine) and then, because the commit isn't in the release blows up because Tesseract_INCLUDE_DIR is not set.

I have absolutely no idea whether the NOT CMAKE_CROSSCOMPILING OR OPENCV_FIND_TESSERACT condition is correct, but I rather wish whomever had coded it had added some brackets in there, or perhaps event a comment >>shock<<, to try and give some direction !!.

My naive view is that the build should not go looking for tesseract if the OPENCV_FIND_TESSERACT is any thing other than YES/TRUE/ON etc.

However, I patched setup-opencv.js in npm-opencv-build to merge the missing commit into the 3.4.3 release ...

module.exports = function() {
  const opencvRepo = 'https://github.com/opencv/opencv.git'
  const opencvContribRepo = 'https://github.com/opencv/opencv_contrib.git'
  return getMsbuildIfWin().then(msbuild =>
    exec(getMkDirCmd('opencv'), { cwd: rootDir })
      .then(() => exec(getRmDirCmd('build'), { cwd: opencvRoot }))
      .then(() => exec(getMkDirCmd('build'), { cwd: opencvRoot }))
      .then(() => exec(getRmDirCmd('opencv'), { cwd: opencvRoot }))
      .then(() => exec(getRmDirCmd('opencv_contrib'), { cwd: opencvRoot }))
      // start - modified to include a 'hotfix' for the Tesseract_INCLUDE_DIRS
      .then(() => spawn('git', ['clone', '-b', `${tag}`, '--single-branch', '--depth',  1, '--progress', opencvContribRepo], { cwd: opencvRoot }))
      .then(() => spawn('git', ['remote', 'add', 'master', opencvContribRepo], { cwd: `${opencvRoot}/opencv_contrib` }))
      .then(() => spawn('git', ['fetch', 'master'], { cwd: `${opencvRoot}/opencv_contrib` }))
      .then(() => spawn('git', ['cherry-pick', 'fdb575d'], { cwd: `${opencvRoot}/opencv_contrib` }))
      // end - modified to include a 'hotfix' for the Tesseract_INCLUDE_DIRS
      .then(() => spawn('git', ['clone', '-b', `${tag}`, '--single-branch', '--depth',  1, '--progress', opencvRepo], { cwd: opencvRoot }))
      .then(() => spawn('cmake', getCmakeArgs(isWin() ? getWinCmakeFlags(msbuild.version) : getSharedCmakeFlags()), { cwd: opencvBuild }))
      .then(getRunBuildCmd(isWin() ? msbuild.path : undefined))
      .then(() => exec(getRmDirCmd('opencv'), { cwd: opencvRoot }))
      .then(() => exec(getRmDirCmd('opencv_contrib'), { cwd: opencvRoot }))
  )
}

And gave that a go ...

  1. it found tesseract
  2. it correctly set the Tesseract_INCLUDE_DIRS
  3. it correctly resolved the #include <tesseract/baseline.api>

.. but ...

[ 88%] Building CXX object modules/tracking/CMakeFiles/opencv_tracking.dir/src/trackerMIL.cpp.o
In file included from /Users/stuart/Workspaces/GITHUB/npm-opencv-build/opencv/opencv_contrib/modules/text/src/erfilter.cpp:43:
In file included from /Users/stuart/Workspaces/GITHUB/npm-opencv-build/opencv/opencv_contrib/modules/text/src/precomp.hpp:54:
In file included from /usr/local/Cellar/tesseract/4.0.0/include/tesseract/baseapi.h:27:
In file included from /usr/local/Cellar/tesseract/4.0.0/include/tesseract/apitypes.h:23:
/usr/local/Cellar/tesseract/4.0.0/include/tesseract/publictypes.h:33:1: error: unknown type name 'constexpr'
constexpr int kPointsPerInch = 72;
^

And about another 20 errors - so obviously merely resolving the original problem (i.e. getting the build to find the appropriate header files, libraries etc) isn't going to work.

FYI. I also changed the tag to 3.4 so that the head for the 3.4 branch was the one cloned (which includes the commit) and had the same errors.

As I mentioned in my original post on this issue, my current work around-is to rollback ffmpeg (or unlink tesseract) when doing the build/install but I find that "annoying" and unfortunately I don't have the available time (and skills) to jump into debugging the opencv_contrib build further (obviously it's something do with versions of tesseract, so hopefully someone that needs that code will take a look at some point - I will add an Issue to opencv_contrib).

So what I am going to do is fork opencv and opencv_contrib and then modify the 3.4 branch to change the NOT CMAKE_CROSSCOMPILING OR OPENCV_FIND_TESSERACT to remove the CMAKE_CROSSCOMPILING clause, since all I want to do is avoid using tesseract and then see whether that build works.

I believe that what would be useful for opencv4nodejs is to be able to specify the git repos (including. tag/branch) for opencv and opencv_contrib as environment variables so that the AUTOBUILD can still be used but against specific OpenCv repos.

Obviously this will be useful for my particular situation, but I also think it will be useful for cases where there is a need/desire to have a custom opencv or opencv_contrib build that retains ABI compatibility with the version of opencv and opencv_contrib supported by opencv4nodejs.

So I will fork, change it, and put in a pull request - I completely understand if the @justadudewhohacks and the other maintainers reject it.

As I mentioned at the beginning this was more of an FYI / PSA :)

@clarsen
Copy link

clarsen commented Feb 20, 2019

@goulash1971 Did workaround in the meantime until your patch lands:

brew uninstall ffmpeg
brew uninstall tesseract
npm install opencv4nodejs

@Xen0phobe
Copy link

@clarsen Thanks. Your workaround got things compiling.

@isonic1
Copy link

isonic1 commented Apr 8, 2019

@clarsen Thanks. This was a major PITA for me.

@phlahut
Copy link

phlahut commented Jul 10, 2019

@clarsen Thanks,it really works

@clarsen
Copy link

clarsen commented Jul 10, 2019

Thanks to @goulash1971 ! 👍

@igorms-pro
Copy link

I installed successfuly but i have this issue : Error: Cannot find module '...node_modules/opencv4nodejs/build/Release/opencv4nodejs' Im getting crazy

when i launched a program with const cv = require('opencv4nodejs');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants