termux / termux-packages

A package build system for Termux.
https://termux.dev
Other
13.33k stars 3.07k forks source link

Installing opencv-python #1992

Closed AvielNiego closed 2 years ago

AvielNiego commented 6 years ago

Hey,

Is there a way to install opencv-python? The standard pip3 install opencv-python returns

Could not find version that satisfies the requirement opencv-python (from versions: )
No matching distribution found for opencv-python
Grimler91 commented 6 years ago

I'm working on adding a short build tutorial to https://wiki.termux.com/wiki/Instructions_for_installing_python_packages. GUI will need to be disabled of course.

It isn't entirely trivial though, some patching is needed, so it might be worth to package it properly in the long run.

Grimler91 commented 6 years ago

There are old instructions in https://github.com/termux/termux-packages/issues/512 but they seem to be outdated due to the problem described in #1149.

its-pointless commented 6 years ago

I have cross compiled it in the past but cross compiling and getting python module i have not done.

Grimler91 commented 6 years ago

@its-pointless I guess that could be problematic. It seems to use python during the build, and also requires numpy, which is in your repo and not the main repo. The package would probably have to reside in your repository then.

I'll continue looking at instructions for compilation on device in any case.

AvielNiego commented 6 years ago

Thanks a lot!

Grimler91 commented 6 years ago

@AvielNiego Please try the instructions at https://wiki.termux.com/wiki/Instructions_for_installing_python_packages#opencv. Compilation takes quite a lot of time.

AvielNiego commented 6 years ago

Thanks! I did encounter the problems from https://github.com/termux/termux-packages/issues/1149 After the make command I get this error:

fatal error: too many errors emitted, stopping now [-ferror-limit=]
40 warnings and 20 errors generated

Most of the errors are: error: no matching function for call 'max' (around 9 times) the others are:

error: no member named 'fpclassify' in global namespace
error: no member anmed 'isfinite' in global namespace; did you mane 'finite'?
error: no member anmed 'isnormal' in global namespace
error: no member anmed 'isgreater' in global namespace; did you mane '::std::greater'?
error: no member anmed 'isgreaterequal' in global namespace; did you mane '::std::greater_equal'?
error: no member named 'isless' in global namespace
error: no member named 'islessequal' in global namespace
error: no member named 'islessgreater' in global namespace
error: no member named 'isunordered' in global namespace
error: no member named 'isunordered' in global namespace
Grimler91 commented 6 years ago

I believe this is fixed by commit https://github.com/termux/termux-packages/commit/4130315f9df2c71c28fd315514949e29edcd58b9, try updating all packages and see if it is resolved (you might have to remove the opencv/build folder and start over).

AvielNiego commented 6 years ago

It worked! Now when I try to import cv2 in python like that: import cv2 I get some warnings and this error

dlopen failed: cannot locate symbol "PyFloat_Type" referenced by "/data/data/com.termux/usr/lib/python3.6/site-packages/cv2.cpython-36m.so

whatsapp image 2018-01-04 at 14 34 33

Grimler91 commented 6 years ago

The warnings can be removed with by running termux-elf-cleaner on the libs, see the readme for more information.

"Cannot locate symbol"-issues are most often solved by first making sure the library providing the symbol is installed, and then running the installation with LDFLAGS set to point to the library containing the symbol that wasn't found.

From https://bugs.kde.org/show_bug.cgi?id=335965 it looks like the symbol should be in libboost_python.so. However, our boost is built without python support so it won't work.

It should be possible to add python supported to boost, it is discussed in the pull request and it is also needed by at least one other package, dlib.

When python support for boost exists, you might need to rebuild opencv with -lboost_python added to LDFLAGS (i.e. LDFLAGS=" -llog -lboost_python" cmake ...).

its-pointless commented 6 years ago

k iv made a pull request #2004 to add libbost.python if you wait a few momemnts i will get binaries available.

Grimler91 commented 6 years ago

@its-pointless I tried building opencv again, with LDFLAGS=" -llog -lboost_python-3" cmake -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=$PREFIX -DBUILD_opencv_python3=on -DBUILD_opencv_python2=off -DWITH_QT=OFF -DWITH_GTK=OFF ..

But ran into quite a lot of undefined references

/data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyUnicode_FromFormat'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyObject_SetItem'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyList_New'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyUnicode_AsWideChar'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyNumber_InPlaceFloorDivide'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyDict_Size'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyModule_Type'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyArg_ParseTupleAndKeywords'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyDict_Items'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyProperty_Type'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyMethod_Type'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyList_Insert'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyExc_ReferenceError'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyFloat_Type'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyTuple_Type'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyNumber_Lshift'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyObject_ClearWeakRefs'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyObject_CallMethod'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyMem_Free'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyCFunction_NewEx'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyNumber_InPlaceAdd'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyLong_AsUnsignedLongLong'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyNumber_Add'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyObject_GetAttrString'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyUnicode_AsUTF8String'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyObject_SetAttrString'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyErr_WarnEx'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyErr_NoMemory'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyErr_SetObject'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyIter_Next'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyNumber_Multiply'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `_Py_NotImplementedStruct'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyObject_RichCompare'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyRun_FileExFlags'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyExc_RuntimeError'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyErr_SetString'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyObject_IsInstance'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyObject_DelItem'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyMethod_New'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyObject_GetItem'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyExc_ValueError'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyExc_TypeError'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyStaticMethod_New'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyTuple_GetItem'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyComplex_Type'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyErr_ExceptionMatches'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyNumber_InPlaceAnd'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyType_Ready'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyLong_FromLong'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyComplex_ImagAsDouble'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyLong_AsSsize_t'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyBytes_Size'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyDict_GetItem'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyErr_NewException'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyErr_Clear'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyBool_FromLong'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyList_Append'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyDict_Clear'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyDict_Update'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyNumber_Or'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyNumber_And'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyObject_CallFunction'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyTuple_New'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyExc_OverflowError'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyNumber_Remainder'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyType_Type'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyObject_SetAttr'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyErr_Occurred'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyModule_Create2'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyLong_AsLong'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyImport_ImportModule'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyEval_GetGlobals'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyNumber_InPlaceOr'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyNumber_InPlaceXor'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `_Py_fopen'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyRun_StringFlags'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyDict_GetItemString'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyList_Reverse'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyList_Sort'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyObject_Size'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `_Py_NoneStruct'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyObject_IsTrue'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `_PyType_Lookup'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyEval_CallFunction'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyType_GenericAlloc'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyNumber_InPlaceRshift'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyStaticMethod_Type'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyWeakref_NewRef'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyNumber_Rshift'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyNumber_InPlaceRemainder'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyDict_New'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyExc_IndexError'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyBool_Type'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyCallable_Check'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyLong_AsUnsignedLong'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyDict_Type'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyBaseObject_Type'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyLong_FromUnsignedLong'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyUnicode_AsUTF8'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyLong_Type'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyDict_Keys'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `_PyObject_New'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyUnicode_FromString'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyUnicode_InternFromString'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyExc_AttributeError'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyDict_Copy'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyBytes_AsString'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyExc_StopIteration'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyObject_Call'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyUnicode_Type'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyLong_AsLongLong'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyType_IsSubtype'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyTuple_Size'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyNumber_InPlaceLshift'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyErr_Format'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PySlice_New'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyUnicode_FromStringAndSize'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyNumber_InPlaceMultiply'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyObject_GetAttr'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyCFunction_Type'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyUnicode_FromEncodedObject'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyComplex_RealAsDouble'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyMem_Malloc'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyNumber_Subtract'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyNumber_Xor'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyNumber_InPlaceSubtract'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyList_Type'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyNumber_FloorDivide'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyDict_Values'

Could/should this be dealt with when compiling boost or should/do I need to link against the corresponding libs on device?

its-pointless commented 6 years ago

I think adding -lpython3 to ldflags should work. But its probably best make sure boost-python links before hand.

Grimler91 commented 6 years ago

@its-pointless neither -lpython3 or -lpython3.6m works (identical output) so I'm guessing we need to link when building boost. I can try it tomorrow.

its-pointless commented 6 years ago

i made a big update for boost. fornwall accepted pull request of mine which actually breaks stuff .... oops sorry my fault. i will get a lib up that should work shortly. Which arch you using to test grimler?

Grimler91 commented 6 years ago

@its-pointless thanks for your work. Aarch64 would be preferred.

its-pointless commented 6 years ago

Already in official repo

Grimler91 commented 6 years ago

@its-pointless Which PR are you talking about? Don't you think something along the lines of your changes in https://github.com/termux/termux-packages/pull/2006 is needed?

its-pointless commented 6 years ago

I think i upped to my repo with properly linked libs. try that

Grimler91 commented 6 years ago

@its-pointless Yepp, your latest version there fixes it, no more errors on import cv2.

Are you planning to open a new pull request for the termux repo?

its-pointless commented 6 years ago

I suppose i should ... again

isman7 commented 6 years ago

Hi! I've been trying to reproduce the OpenCV compiling in my Termux (Android 8, aarch64) and I'm repeteadly failing at this point:

[ 29%] Building CXX object modules/core/CMakeFiles/opencv_core.dir/src/system.cpp.o /data/data/com.termux/files/home/opencv-3.0.0/modules/core/src/system.cpp:645:29: error: use of undeclared identifier 'ANDROID_LOG_ERROR' __android_log_print(ANDROID_L... ^ 1 error generated. make[2]: [modules/core/CMakeFiles/opencv_core.dir/build.make:1026: modules/core/CMakeFiles/opencv_core.dir/src/system.cpp.o] Error 1 make[1]: [CMakeFiles/Makefile2:1585: modules/core/CMakeFiles/opencv_core.dir/all] Error 2

Using as Cmake flags LDFLAGS=" -llog -lpython3". I've readed a lot and I supose it's related with the uncorrect linking something, but I'm not a CMake expert. I could use some help.

Thank you,

Isma

Grimler91 commented 6 years ago

@isman7 see the (possibly outdated) instructions at https://wiki.termux.com/wiki/Instructions_for_installing_python_packages#opencv. How did you set LDFLAGS?

isman7 commented 6 years ago

Yes yes, I followed the insturctions. I used them with -llog and with -lpython3 and the same error raised. In fact, for versions 2.4.13.6 and 3.0.0 I found this error, for newest version I found another error related with 3rd party libs, so I decided to go down.

Searching I found similar issues here: https://stackoverflow.com/questions/4455941/undefined-reference-to-android-log-print

However this is talking about compiling some Android SDK stuff, and I don't know how to adapt the line of Android.mk to Makefile.

Grimler91 commented 6 years ago

I don't think -lpython is necessary, can't remember that I used it at least.

Install libboost-python and try this exact command:

LDFLAGS=" -llog -lboost_python" cmake -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=$PREFIX -DBUILD_opencv_python3=on -DBUILD_opencv_python2=off -DWITH_QT=OFF -DWITH_GTK=OFF ..

From a subdirectory ("build") in the opencv folder, note that everything is on one line.

isman7 commented 6 years ago

Sorry, pre-pended!

The only thing i haven't tried it's libboost-python. I'll try again with lboost, and I'll report about in an hour.

Thanks for the support!

tomty89 commented 6 years ago

It's normal for you to get that error because there was a bug in those two versions:

https://github.com/opencv/opencv/blob/0354d01e79d870adb09eea8f6d95b4093c7b4c97/modules/core/src/system.cpp

https://github.com/opencv/opencv/blob/c12243cf4fccf5df7b0270a32883986b373dca7b/modules/core/src/system.cpp

They use ANDROID instead of __ANDROID__ for the ifdef for #include <android/log.h>.

It's obviously not a linking problem (coz it's undefined identifier, not undefined reference as in the SO question).

For the error(s) you get on other version(s), we will need to know what they are exactly in order to help.

isman7 commented 6 years ago

That's right, it was the opencv version. The last one from github releases it's working perfectly.

Maybe, a disclosure about versions has to be added to the wiki.

Thanks for the support.

Ismael

ZimingYuan commented 6 years ago

Hi! I've successfully compiled OpenCV in my Termux(Android 5.0.2, aarch64), but when I tried to import it in Python3.6(import cv2), I got such an error:

Traceback (most recent call last): File "", line 1, in ImportError: dlopen failed: "/data/data/com.termux/files/usr/lib/python3.6/site-packages/cv/cv2.so" is 32-bit instead of 64-bit

I am wondering if I should add some compiling options of CMake to compile OpenCV into a 64-bit library but I don't know what should I add. Sincerely hope someone could offer me some help.

Thanks!

Eskender-B commented 6 years ago

@ZimingYuan for aarch64 I have cross compiled and produced the opencv debs here .

when using from python do the following first:

$ export LD_PRELOAD=$PREFIX/lib/libpython3.6m.so

KouichiMatsuda commented 6 years ago

Hi, l'm installing opencv following the helpful wiki

https://wiki.termux.com/wiki/Instructions_for_installing_python_packages#opencv

The install seems to be done successfully but cv2.so was not generated. I'm using the following flag

LDFLAGS=" -llog -lboost_python-3 -lpython3" cmake -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=$PREFIX -DBUILD_opencv_python3=on -DBUILD_opencv_python2=off -DWITH_QT=OFF -DWITH_GTK=OFF ..

Am I missing something?

ZimingYuan commented 6 years ago

Thanks a lot!

vladosam commented 6 years ago

I'm trying to install opencv on android arm with instructions from wiki but it just hang on:

-- Check for working CXX compiler: /data/data/com.termux/files/usr/bin/c++

Any help with this?

its-pointless commented 6 years ago

Probably make bug. Install ninja and use cmake -G Ninja and use ninja command inplace of make

vladosam commented 6 years ago

Thanks. Now it passes that check but immediately stops with this error: -- Check for working CXX compiler: /data/data/com.termux/files/usr/bin/c++ -- broken /data/data/com.termux/files/usr/bin/c++ is not able to compile a simple test program.

It complains about missing lboost_python. I tried to install libboost-python but that also fails. libboost-python: Depends: boost but its not going to be installed

I installed boost from termux-packages.

its-pointless commented 6 years ago

before configuring export CC=gcc CXX=g++

vladosam commented 6 years ago

Now this.

CMake Error at /data/data/com.termux/files/usr/share/cmake-3.12/Modules/CMakeTestCXXCompiler.cmake:45 (message): The C++ compiler

"/data/data/com.termux/files/usr/bin/c++"

is not able to compile a simple test program.

It fails with the following output:

Change Dir: /data/data/com.termux/files/home/opencv/build/CMakeFiles/CMakeTmp

Run Build Command:"/data/data/com.termux/files/usr/bin/ninja" "cmTC_246f2"
[1/2] Building CXX object CMakeFiles/cmTC_246f2.dir/testCXXCompiler.cxx.o
/data/data/com.termux/files/usr/bin/arm-linux-androideabi-ld: cannot find -lboost_python
clang-7: error: linker command failed with exit code 1 (use -v to see invocation)
[2/2] Linking CXX executable cmTC_246f2
FAILED: cmTC_246f2
: && /data/data/com.termux/files/usr/bin/c++    -llog -lboost_python   -rdynamic CMakeFiles/cmTC_246f2.dir/testCXXCompiler.cxx.o  -o cmTC_246f2   && :
ninja: build stopped: subcommand failed.
its-pointless commented 6 years ago

There are 2 python libs in the boost package /data/data/com.termux/files/usr/lib/libboost_python36.so /data/data/com.termux/files/usr/lib/libboost_python27.so If you are using python 3 either create a symlink ln -s /data/data/com.termux/files/usr/lib/libboost_python36.so /data/data/com.termux/files/usr/lib/libboost_python.so It should link against libboost_python36.so when you build.

vladosam commented 6 years ago

Now it's compiled. :D But (of course there is but :D) when i use ninja instead of make the is a lot of errors and it stops with ninja: build stopped: subcommand failed :(

vladosam commented 6 years ago

@its-pointless i started with fresh build and ninja works. But it breaks later on. So that probably because i don't know right cmake config for my phone. So sorry to bother you.

vladosam commented 6 years ago

@its-pointless i'm getting closer. Now it stops at this:

clang-7: error: linker command failed with exit code 1 (use -v to see invocation) [909/1220] Linking CXX executable bin/opencv_version FAILED: bin/opencv_version

any idea how i can fix this?

its-pointless commented 6 years ago

Iv got compiled packages available via my apt repo. Needs testing. Python3 module etc cross compiled.

Auxilus commented 6 years ago

whoa, what a coincidence, I was just finishing compiling :p

Auxilus commented 6 years ago

@its-pointless

Reading package lists... Error!                             E: Problem parsing dependency 20                            E: Error occurred while processing opencv (NewVersion2)     E: Problem with MergeList /data/data/com.termux/files/usr/var/lib/apt/lists/its-pointless.github.io_files_dists_termux_extras_binary-aarch64_Packages                               E: The package lists or status file could not be parsed or opened.
its-pointless commented 6 years ago

Typo on my part. A . Instead of a comma

vladosam commented 6 years ago

@its-pointless thanks for this.When i try to import cv2 in python i get this error.

ImportError: dlopen failed: library "libjasper.so" not found

Auxilus commented 6 years ago

@vladosam you need to install libjasper as well as libwebp

HsuTouhuan commented 6 years ago

en.the termux told me that “CANNOT LINK EXECUTABLE "cmake": library "libcrypto.so.1.1" not found” when i have run the command “LDFLAGS=" -llog" cmake -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=$PREFIX -DBUILD_opencv_python3=on -DBUILD_opencv_python2=off -DWITH_QT=OFF -DWITH_GTK=OFF ..”what,s wrong with it? thankyou

HsuTouhuan commented 6 years ago

en.the termux told me that “CANNOT LINK EXECUTABLE "cmake": library "libcrypto.so.1.1" not found” when i have run the command “LDFLAGS=" -llog" cmake -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=$PREFIX -DBUILD_opencv_python3=on -DBUILD_opencv_python2=off -DWITH_QT=OFF -DWITH_GTK=OFF ..”what,s wrong with it? thankyou

when i was try to install it

ghost commented 6 years ago

@HsuTouhuan Have you run pkg upgrade ?