conda-forge / opencv-feedstock

A conda-smithy repository for opencv.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

imshow gtk2 error on linux

extraymond opened this issue · comments

After installing opencv from conda-forge, I'm able to import cv2 and use most of cv2's function.
But when trying to imshow after imread, I got an error suggesting I have built time problems.

error message below

error Traceback (most recent call last)
in ()
----> 1 cv2.imshow('hi',img)
error: /feedstock_root/build_artefacts/work/opencv-3.1.0/modules/highgui/src/window.cpp:545: error: (-2) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function cvShowImage

And I do have these packages installed in my setup.

In order to maintain compatibility, conda-forge opencv builds without gtk2 support (see #25 ). We have a conda-forge based recipe that builds with ffmpeg and gtk2 support on linux. You might want to use it to build your own opencv package, or you could use our prebuilt packages:

conda install -c loopbio ffmpeg-feature gtk2-feature opencv

Note that this last option installs, at the moment, our conda gtk2 package. You can remove it afterwards if you prefer to use your system's gtk2.

Thx, I tried the prebuilt packages too, and it still gives me the same error.

It says this
opencv 3.1.0 np111py35_1
I think it's the latest in loopbio repo!
I have tried several opencv packages in conda repos, conda-forge, menpo and loopbio, all without success.

No, that was not coming from the loopbio repo. In fact we had not build the package for python 3. I have just uploaded the corresponding packages for python 3.x + numpy 1.11. Let me know if you need something different.

If you succeed, you should see a line like this after running conda list:
opencv 3.1.0 np111py36_ffmpeg_gtk2_1 [ffmpeg gtk2] loopbio

Actually I think I might be ok adding support for things like ffmpeg and possibly gtk2 to conda-forge's opencv. We should probably do them one at a time. Would you be interested in doing a PR, @sdvillal?

@sdvillal Hi I tried your gtk2-enabled opencv to compile Caffe. However, it complains that libopencv_highgui.so: undefined reference to gtk_widget_set_realized'`. Any idea? Thanks.

@sdvillal is the case that your opencv doesn't come with its own gtk? I think this is the case after examining the actual files.

I'm using conda features to manage opencv variants, so if you want the gtk2 version, you need to install a package tracking the gtk2 feature. I know it is not very intuitive, but that is as good as it gets with conda right now.

In our repo we have two packages that track the gtk2 feature: gtk2-feature does not install anything and let you use your system gtk2. gtk2 does install gtk2. On top of that, you also need the "ffmpeg" feature if you want our opencv to be selected.

We are also packaging caffe. The following environment.yaml will create you an environment with opencv 3.2.0 compiled with gtk2 and ffmpeg support plus caffe compiled with cuda support. Note that cuda is not packaged, so you need to have it installed in your system (you get some hints on how to do so after the environment is created).

name: caffecv
channels:
  - loopbio      # gtk2-feature, gtk2, ffmpeg-feature,
                 # opencv [gtk2, ffmpeg]
                 # cuda-feature, cudnn-feature, caffe [cuda, cudnn],
  - conda-forge  # everything else
  - pkgw-forge   # atk gdk2-pixbuf & deps
  - defaults     # in case anything is missing

dependencies:
  - python

  # Image proc libs
  - gtk2            # for opencv
  - ffmpeg-feature  # for opencv
  - ffmpeg          # for opencv
  - opencv

  # Caffe-GPU
  - cuda-feature
  - cudnn-feature
  - caffe-cuda

  # Caffe-CPU
  # - caffe

Install, activate, list it like

conda env create -f environment.yaml
source activate caffecv
conda list

If everything has worked well, you should see lines like these in the package list

caffe-cuda                1.0.0rc5_8.0_5.1 cuda8.0_cudnn5.1_0  [cuda8.0 cudnn5.1]  loopbio
opencv                    3.2.0           np112py36_ffmpeg_gtk2_1  [ffmpeg gtk2]  loopbio

If you have more questions, feel free to open an issue in our opencv recipe repo. I think it is best to continue there the conversation.

@jakirkham I do not know how easy could it be to get a gtk2-enabled version of opencv into conda-forge. First we would need to package gtk2 for linux (easy) mac (no idea) and windows (no idea), then deal with any problem given by opencv in these systems. If you think it would be really worth it, maybe we should ask for some advice to @pkgw - our gtk2 linux package depends on his excellent pkgw-forge packages and maybe we could start the job with a PR there.

I think for ffmpeg it could be a bit easier, as the package is already in conda-forge.

IMHO it should be ok to approach adding gtk2 incrementally. Namely start just with Linux where it is doable. We can then investigate other platforms. Honestly building things on Mac tends to be pretty similar to Linux and may only require a few tweaks. I agree that Windows can be tricky. That all being said, it is surprising how quickly people begin to rally around a package that is missing some OS support and start fixing it. Particularly with something as important as gtk2.

@sdvillal thanks for the detailed explanation! Roughly at the same time, I figured out myself how to install your Gtk2-enabled package properly. Unfortunately, it seems that the portability of GTK is poor, in that https://github.com/yosinski/deep-visualization-toolbox fails to launch properly, or maybe it's because this toolbox actually requires opencv2 (not sure). I just tried recompiling one myself on Ubuntu, and it worked now.

GTK is quite portable, including to Windows. If the problem you're seeing is due to the GTK package, it can almost surely be fixed.

Does opencv support Gtk3? I have a set of recipes for the necessary Gtk3 packages in my pkgw-forge repository. I would like to get them integrated into conda-forge but it's a somewhat lower priority for me than some other things I've been working on, and they're quasi-blocked on figuring out what our X11 policy is / should be.

@sdvillal @pkgw I've just compiled and tested a GTK-enabled opencv 2, for using https://github.com/yosinski/deep-visualization-toolbox on my university's cluster. It's at https://github.com/leelabcnbc/opencv-feedstock/tree/v2 and https://anaconda.org/zym1010/opencv. Hopefully we can somehow work together to merge these features into conda-forge.

@zym1010 Your changes look good, and show that it is easy to build also a gtk2-enabled opencv linux version. I might also give a look to the v2 branch and add your changes.

@pkgw I have not experience with opencv + gtk3, although I think that would not really cut it for some of our internal uses. As you comment, the problem with any of those is their dependencies on X11. Before finding your channel, I was solving it in dodgy ways at build time and hoping no problem would arise by using the system X11 libraries at deployment. I think adding gtk2 should not be a lot of extra work, as you have done already 95% of the work. I will open a PR to your conda-recipes repository to discuss.

@zym1010 I have just uploaded opencv 2 gtk2 + ffmpeg to our channel, you could use that instead of your package. This is the relevant branch in our repo. I think it is better to keep this there to avoid a many fork mess. I would be happy to add any PR you might need.

Just out of curiosity, are you planning to build conda packages also for caffe@deconv-deep-vis-toolbox and the deep-visualization-toolbox? It seems feasible to me.

@sdvillal thanks! I think it would be best if you can help maintaining it, as I basically hack the original v2 branch for it to work for me, without much understanding of conda building framework.

Just out of curiosity, are you planning to build conda packages also for caffe@deconv-deep-vis-toolbox and the deep-visualization-toolbox? It seems feasible to me.

Nope. In fact, for caffe@deconv-deep-vis-toolbox, I first merge it to the master branch of blvc/caffe and then compile it same way as I compile the master one. No error, and deep-visualization-toolbox doesn't need compiling.

I thought the problem is the mix of packages, that probably were incompatible.I check my machine (Ubuntu 14.04 ) Anaconda environment there had a package name call opencv-python(https://pypi.python.org/pypi/opencv-python( Here, I got an IMPORTANT NOTE:

MacOS and Linux wheels have some limitations:

video related functionality is not supported (not compiled with FFmpeg)
for example cv.imshow() will not work (not compiled with GTK+ 2.x or Carbon support))) we all know already we have gtk2 issue. And another package name OpenCV(opencv.org).When I import OpenCV as cv2 maybe unofficial OpenCV-python package work (I am not sure I guess so) except for OpenCV official. Then I tried to build the official OpenCV with python and remove my previous opencv-python package(I was failed to remove this package). Nothing worked.The solution was I got to re-install Ubuntu 14.04 and re-install OpenCV from the official site.

@sdvillal thanks for your information.

@nafisfaysal the limitation should be due to the that of the PyPI package you use.

I believe if you follow @sdvillal 's suggestion, you will be able to use a GUI-enabled opencv properly.

Anyone got this working with the @sdvillal suggestion?

conda install -c loopbio ffmpeg-feature gtk2-feature opencv

Even compiling by hand, with WITH_GTK=ON and CMAKE_INSTALL_PREFIX=/home/user/anaconda3 couldn't make it work...

Did anyone got this working at all?

@oxydron

how about

conda install --channel loopbio --channel conda-forge --channel pkgw-forge gtk2 ffmpeg ffmpeg-feature gtk2-feature opencv?

I think this should work.

Ups, email comments do not allow markdown. You could choose one of these variants:

# Should work in any linux conda install
conda install -c loopbio -c conda-forge -c pkgw-forge ffmpeg-feature ffmpeg gtk2 opencv

# Should work anywhere with linux and a modern CPU
conda install -c loopbio -c conda-forge -c pkgw-forge ffmpeg-feature ffmpeg gtk2 opencv-turbo 

# Should work anywhere with linux and a modern CPU and CUDA 8 + modern GPU
# (we only target Maxwell and Pascal)
conda install -c loopbio -c conda-forge -c pkgw-forge ffmpeg-feature ffmpeg gtk2 opencv-turbo-cuda

@zym1010 Created a new conda env and run your install commands and got this, while trying to cv2.imshow:

stat: No such file or directory
Gtk-Message: Failed to load module "overlay-scrollbar"
Gtk-Message: Failed to load module "atk-bridge"
Gtk-Message: Failed to load module "unity-gtk-module"
Gtk-Message: Failed to load module "canberra-gtk-module"

@sdvillal Created another env and run your first and second install commands and got this:

Gtk-Message: Failed to load module "overlay-scrollbar"
Gtk-Message: Failed to load module "atk-bridge"
Gtk-Message: Failed to load module "unity-gtk-module"
Gtk-Message: Failed to load module "canberra-gtk-module"

and this

[1]    22087 illegal hardware instruction (core dumped)  python camera.py

Am I cursed?

Try only with the first command, that has the best chances to succeed.

Did whatever program you run (camera.py?) actually fail? Those gtk messages do not need to imply failure - I have never seen them before, it looks like an ubuntu misconfiguration issue to me.

Try perhaps to run this:

import cv2
import numpy as np
cv2.imshow('darkness', np.zeros((100, 100)))
cv2.waitKey()

To reduce noise, maybe it is better to continue discussion in a different issue here. Feel free to open it.

commented

@sdvillal I installed opencv in conda using your first command. I get the following error:

In [1]: Gtk-Message: Failed to load module "atk-bridge"
Gtk-Message: Failed to load module "canberra-gtk-module"

when I launch ipython. I also have gtk+2.0 installed in my system. But, that didn't help.


But, imshow() is working fine. Any ideas how to suppress these messages on startup?

None of this represents a problem with the conda-forge package except perhaps an absence of gtk2 support, which can only be addressed if a gtk2 package is added to conda-forge. Given that a gtk2 package has yet to be added to conda-forge, there is nothing actionable for the opencv package in conda-forge. Further as this discussion has devolved into support requests for the loopbio build of opencv, this no longer feels like an appropriate discussion to have here. That said, if the community does add a gtk2 package to conda-forge, would be interested in discussing with those involved how best to integrate it with opencv. Until then there is nothing actionable here. So am closing this out.

Please raise issues with the loopbio project directly if you are having trouble with their opencv build. Thanks.

@jakirkham Thanks, and sorry for the extra traffic this generated.

About GTK2, as a first step I have opened a pull request in the pkgw repo. The reason, it would require to add not only GTK2 to conda-forge, but several other X11 dependencies we pull from there. Having said that, even if we could make it one day into conda-forge, I wonder if it would be a good idea to make opencv depend on it. It really pulls a ton of dependencies, so at most I would make it optional (via a feature). Also, as you suffer, you will get every now and then some work from people alarmed by these GTK2 warnings.

And for anybody like @kmario23 wondering about these GTK messages, note that 1) they are just warnings and 2) not related to our package (they would happen with any GTK2 application in your system). Please refer to this other issue to comment and find out how to silence them.

This command ended up working for me (the commands suggested by @sdvillal did not)
conda install --channel loopbio --channel conda-forge --channel pkgw-forge gtk2 ffmpeg ffmpeg-feature gtk2-feature opencv openblas

Guys the following repo gets you a updated with gtk version of OpenCV, it worked very well for me:
conda install -c menpo opencv

@oxydron That's my channel and it won't be updated any further

Thanks @sdvillal

Ran this command and I got same error.

Should work in any linux conda install
conda install -c loopbio -c conda-forge -c pkgw-forge ffmpeg-feature ffmpeg gtk2 opencv

Ran this command and imshow is working perfectly(image is displayed) but throws some errors.

Should work anywhere with linux and a modern CPU
conda install -c loopbio -c conda-forge -c pkgw-forge ffmpeg-feature ffmpeg gtk2 opencv-turbo

Error:

Gtk-Message: Failed to load module "overlay-scrollbar"
Gtk-Message: Failed to load module "unity-gtk-module"
Gtk-Message: Failed to load module "canberra-gtk-module"

Thanks @patricksnape 's conda install -c menpo opencv does work flawlessly but as he have mentioned, it wont be updated.

I tried the command of @sdvillal and I've got the same error as @alwynmathew . Even more, when I now use import cv2, I get

ImportError: libopenblas.so.0: cannot open shared object file: No such file or directory.

I try to roll-back...

Please don't use this issue as a support group for the gtk build since we don't support it. Comment directly on the loopbio repository if you want support.

Have opened issue ( conda-forge/staged-recipes#3914 ) to request GTK be added to conda-forge. At this point, FWICT, all of the required dependencies for GTK 2 are satisfied. Some, but not all, of GTK 3's dependencies are satisfied. As GTK 2 is used to some extent from yum and we have all the dependencies, that seems like the first order of business. GTK 3 can then be approached on the GTK feedstock (once created). Would encourage those interested in adding GTK to conda-forge discuss in that issue. Thanks.