简体   繁体   English

如何在远程Jupyter Notebook执行中使用OpenCV?

[英]How to use opencv in a remote jupyter notebook execution?

In my local machine with macOS Mojave, I installed a virtual environment with Python 3.6, opencv package and some additional unrelated packages. 在我使用macOS Mojave的本地机器上,我安装了一个带有Python 3.6,opencv软件包和一些其他不相关软件包的虚拟环境。

I started a very simple Jupyter Notebook that is executed with no problem, here it's the code: 我启动了一个非常简单的Jupyter Notebook,它执行起来没有问题,这是代码:

import cv2
print(cv2.__version__)
my_img = cv2.imread("colibri_763_460.jpeg",1)
cv2.imshow("Original", my_img)
cv2.waitKey(0)
cv2.destroyAllWindows()

Now, I'm trying to execute the same code in a Jupyter Notebook in my remote Ubuntu machine but I can't make it work. 现在,我正在尝试在我的远程Ubuntu机器中的Jupyter Notebook中执行相同的代码,但我无法使其工作。 These are the steps that I took: 这些是我采取的步骤:

  • I copied the image file and the Notebook ypnb file to the remote ubuntu machine. 我将图像文件和Notebook ypnb文件复制到远程ubuntu机器上。
  • I opened an ssh session, selected a virtualenv with the same packages than my local machine and executed the "jupyter notebook" 我打开了一个ssh会话,选择了一个与我的本地机器相同的包的virtualenv并执行了“jupyter notebook”
  • I opened another terminal with ssh -L 8000:localhost:8888 mpastorg@mpgubu18 for the ssh tunneling 我用ssh -L 8000开了另一个终端:localhost:8888 mpastorg @ mpgubu18用于ssh隧道
  • I opened my local browser in the localhost:8000 to execute the Notebooks that I have in my remote Ubuntu machine, it works with any Notebook not involving opencv. 我在localhost:8000中打开了本地浏览器,以执行远程Ubuntu计算机中的笔记本,它可与任何不涉及opencv的笔记本一起使用。

I tried to solve my problem using two different ways: 我试图用两种不同的方式解决我的问题:

  • Installing in the ubuntu remote machine the package opencv-contrib-python-headless: when I try to use cv2.imshow , I got the error method not found 在ubuntu远程机器上安装软件包opencv-contrib-python-headless:当我尝试使用cv2.imshow时 ,我发现了错误的方法
  • Installing in the ubuntu remote machine the package opencv-contrib-python: I got the error that kernel is dead. 在ubuntu远程计算机上安装软件包opencv-contrib-python:我收到内核已死的错误。

Does anyone know if there's any way to execute the remote jupyter notebook and see the picture locally? 有人知道是否可以执行远程jupyter笔记本并在本地查看图片吗? it maybe would be possible a workaround to embed the picture in the browser window? 也许可以通过一种解决方法将图片嵌入浏览器窗口?

Thank you very much Marcos Pastor 非常感谢Marcos Pastor

I wonder if the image is being rendered using X - which you have not explicitly enabled, in both your host machine, nor in your ssh tunnel. 我想知道在你的主机和ssh隧道中是否使用X渲染图像 - 你没有明确启用它。

On the Host machine. 在主机上。 (Where you want to see the Image). (你想在哪里看到图像)。 Enter this comment 输入此评论

xhost+

This now allows remote X-Hosts to send you data. 现在,这允许远程X-Hosts向您发送数据。 As you are on a Mac - you will need to have the XQuartz package installed. 当您使用Mac时 - 您需要安装XQuartz软件包。

Now modify your ssh command. 现在修改你的ssh命令。 - so that you allow X - this is typically done using a -X flag (Or it can be placed in your .ssh/config file like this - 这样你就允许X - 这通常使用-X标志来完成(或者它可以放在你的.ssh / config文件中

Host *
  ForwardX11 yes
  ForwardX11Trusted no
  XAuthLocation /opt/X11/bin/xauth
  ForwardAgent yes
  Compression yes
  KeepAlive yes
  Compression yes

If you are not using a config try the -X to start with. 如果您没有使用配置,请尝试使用-X开头。

Hope that helps 希望有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM