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

imshow gtk2 error on linux #43

Closed
extraymond opened this issue Dec 13, 2016 · 36 comments
Closed

imshow gtk2 error on linux #43

extraymond opened this issue Dec 13, 2016 · 36 comments

Comments

@extraymond
Copy link

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

@extraymond
Copy link
Author

And I do have these packages installed in my setup.

@sdvillal
Copy link

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.

@extraymond
Copy link
Author

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

@sdvillal
Copy link

sdvillal commented Dec 14, 2016 via email

@extraymond
Copy link
Author

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.

@sdvillal
Copy link

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

@jakirkham
Copy link
Member

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?

@zym1010
Copy link
Contributor

zym1010 commented Mar 5, 2017

@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.

@zym1010
Copy link
Contributor

zym1010 commented Mar 5, 2017

@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.

@sdvillal
Copy link

sdvillal commented Mar 5, 2017

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.

@sdvillal
Copy link

sdvillal commented Mar 5, 2017

@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.

@jakirkham
Copy link
Member

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.

@zym1010
Copy link
Contributor

zym1010 commented Mar 6, 2017

@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.

@pkgw
Copy link

pkgw commented Mar 6, 2017

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.

@zym1010
Copy link
Contributor

zym1010 commented Mar 6, 2017

@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.

@sdvillal
Copy link

sdvillal commented Mar 7, 2017

@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.

@sdvillal
Copy link

sdvillal commented Mar 7, 2017

@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.

@zym1010
Copy link
Contributor

zym1010 commented Mar 7, 2017

@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.

@nafisfaysal
Copy link

nafisfaysal commented Mar 23, 2017

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.

@zym1010
Copy link
Contributor

zym1010 commented Mar 24, 2017

@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.

@oxydron
Copy link

oxydron commented Mar 28, 2017

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?

@zym1010
Copy link
Contributor

zym1010 commented Mar 29, 2017

@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.

@sdvillal
Copy link

sdvillal commented Mar 29, 2017 via email

@sdvillal
Copy link

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

@oxydron
Copy link

oxydron commented Apr 4, 2017

@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?

@sdvillal
Copy link

sdvillal commented Apr 4, 2017

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.

@kmario23
Copy link

kmario23 commented Apr 21, 2017

@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?

@jakirkham
Copy link
Member

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.

@sdvillal
Copy link

@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.

@william-r-s
Copy link

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

@oxydron
Copy link

oxydron commented Jun 8, 2017

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

@patricksnape
Copy link
Contributor

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

@alwynmathew
Copy link

alwynmathew commented Jun 14, 2017

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.

@Andarin
Copy link

Andarin commented Jun 23, 2017

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...

@patricksnape
Copy link
Contributor

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.

@conda-forge conda-forge locked and limited conversation to collaborators Jun 23, 2017
@jakirkham
Copy link
Member

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.

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

No branches or pull requests