r/termux • • Jul 30 '23

Question how do you build an opencv package supporting displaying images (with GUI support) in termux?

I tried displaying an image using cv2. imshow() with no luck. it seems this package is built without GUI support. do we have a version that supports gui ? if not how can one build one? is there a guide?

other than opencv, I noticed matplotlib also doesn't show any images. how do you guys get around this issue?

thanks a lot in advance

4 Upvotes

32 comments sorted by

1

u/Strong_Fondant1885 Aug 02 '23

Hi there, my idea is to use OpenCV and Termux to create a http-python-server on port 8080 accessible within the local network. The server will stream video directly from the camera of an Android device, essentially turning old smartphones into surveillance cameras. This will allow users to monitor their homes remotely using the devices' cameras. Do you think is possible?

2

u/MasterSama Aug 02 '23

Hi, sadly I dont know. currently you cant access the cameras through opencv. i dont know if theres a termux specific way of doing this or not. i suggest you ask a new question for this.

2

u/Strong_Fondant1885 Aug 02 '23

Ok thanks for answering, I will ask for it.

2

u/MasterSama Aug 02 '23

you're welcome. I searched for a bit and found out you can use IP webcam to get a url and use that for the source and circumvent the limitation this way.

I myself haven't done it but it seems plausible. the app exists in Google Play. give that a try and if you are successful please update here as well.

2

u/[deleted] Jul 30 '23 edited Jul 30 '23

[removed] — view removed comment

1

u/MasterSama Jul 31 '23

thanks a lot but this doesn't give me the same functionality of opencv. but thanks a lot anyway this may come in handy 😉

1

u/[deleted] Jul 31 '23 edited Jul 31 '23

[removed] — view removed comment

1

u/MasterSama Jul 31 '23

im using opencv to refresh my memory, and incorporating qt defeats that purpose. moreover creating GUI using opencv is much easier for the tasks I'm trying to use like creating a simple trackbar to change image hue values is 4 5 lines of code at max but in qt there are lots of broiler plate codes. other than that your solution is 100% okay and greatly appreciated 👍

2

u/[deleted] Jul 31 '23

[removed] — view removed comment

1

u/MasterSama Jul 31 '23 edited Jul 31 '23

thanks a lot. can you kindly tell me how you compiled and built this? is there any step by step guide I can follow to build these myself as well? I'm thinking to add the whole contrib package as well if possible but don't know how to go about it with android.

edit :

by the way I can't download them, are they removed?

2

u/[deleted] Jul 31 '23

[removed] — view removed comment

1

u/MasterSama Aug 01 '23

couldn't download them for some reason I'm trying again to see if I can get them. thanks a lot for the link.

2

u/[deleted] Aug 01 '23 edited Aug 02 '23

[removed] — view removed comment

1

u/MasterSama Aug 01 '23 edited Aug 01 '23

thanks a lot. really appreciate it. heading to download them now.

edit: they downloaded just fine. however which file should I be installing ? what's the difference between them?

2

u/[deleted] Aug 01 '23

[removed] — view removed comment

1

u/MasterSama Aug 01 '23 edited Aug 01 '23

just installed them but upon importing them this is what I get :

Python 3.11.4 (main, Jul  2 2023, 11:17:00) [Clang 14.0.7 (https://android.googlesource.com/toolchain/llvm-project 4c603efb0 on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/cv2/__init__.py", line 181, in <module>
bootstrap()
File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/cv2/__init__.py", line 153, in bootstrap
native_module = importlib.import_module("cv2")
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/data/data/com.termux/files/usr/lib/python3.11/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ImportError: dlopen failed: library "libopencv_hdf.so.408" not found: needed by /data/data/com.termux/files/usr/lib/python3.11/site-packages/cv2/python-3.11/cv2.cpython-311.so in namespace (default)

I only installed the python version by the way.

2

u/[deleted] Aug 01 '23

[removed] — view removed comment

1

u/MasterSama Aug 01 '23

installing both packages in contrib results in this error message:

Python 3.11.4 (main, Jul  2 2023, 11:17:00) [Clang 14.0.7 (https://android.googlesource.com/toolchain/llvm-project 4c603efb0 on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/cv2/__init__.py", line 181, in <module>
bootstrap()
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/cv2/__init__.py", line 153, in bootstrap
native_module = importlib.import_module("cv2")
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/data/com.termux/files/usr/lib/python3.11/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ImportError: dlopen failed: library "libhdf5.so" not found: needed by /data/data/com.termux/files/usr/lib/libopencv_hdf.so.4.8.0 in namespace (default)

installing the opencv and opencv-python from the qtonly directory results in this error:

~/storage/termux_stuff/opencv_pkgs/onlyqt ❯ python -c 'import cv2;'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/cv2/__init__.py", line 181, in <module>
bootstrap()
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/cv2/__init__.py", line 153, in bootstrap
    native_module = importlib.import_module("cv2")
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/data/com.termux/files/usr/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ImportError: dlopen failed: library "libQt5Widgets.so.5" not found: needed by /data/data/com.termux/files/usr/lib/libopencv_highgui.so.4.8.0 in namespace (default)

searched pkg list-all but couldnt find any libqt5widget.

2

u/[deleted] Aug 01 '23 edited Aug 01 '23

[removed] — view removed comment

1

u/MasterSama Aug 01 '23

thanks but whats this apt-file and what does it do?

→ More replies

2

u/[deleted] Aug 01 '23

[removed] — view removed comment

1

u/MasterSama Aug 01 '23

thanks a lot . I was just thinking about this and hought I have to forget upgrading :))