GoCoding!GoCoding!GoCoding!GoCoding!GoCoding!
Step 1) 安装 XQuartz,允许网络连接
GoCoding!GoCoding!GoCoding!GoCoding!GoCoding!
# 安装
brew cask install xquartz
# 运行
open -a xquartz
GoCoding!GoCoding!GoCoding!GoCoding!GoCoding!
Step 2) 安装 Docker,准备相关镜像
GoCoding!GoCoding!GoCoding!GoCoding!GoCoding!
brew cask install docker
# 或,直接下载再安装:
# https://download.docker.com/mac/stable/Docker.dmg
拉取 OpenCV 镜像,用其显示:
docker pull joinaero/anaconda3-opencv3:1.0.0
GoCoding!GoCoding!GoCoding!GoCoding!GoCoding!
Step 3) xhost 添加主机 IP
GoCoding!GoCoding!GoCoding!GoCoding!GoCoding!
# 获取 IP
IP=$(ifconfig en0 | grep inet | awk '$1=="inet" {print $2}')
echo $IP
# 增加 IP
xhost + $IP
GoCoding!GoCoding!GoCoding!GoCoding!GoCoding!
Step 4) OpenCV 预览图片
GoCoding!GoCoding!GoCoding!GoCoding!GoCoding!
XQuartz, xterm 继续执行:
docker run -it --rm \
--name myenv \
-e DISPLAY=$IP:0 \
-v /tmp/.X11-unix:/tmp/.X11-unix \
joinaero/anaconda3-opencv3:1.0.0
conda activate myenv
python - <<EOF
import cv2
while True:
im = cv2.imread("/tmp/GoCoding.png")
im = cv2.resize(im, (256, 256))
cv2.imshow("GoCoding", im)
key = cv2.waitKey(10) & 0xFF
if key == 27 or key == ord('q'):
break
EOF
预览效果如下:
GoCoding!GoCoding!GoCoding!GoCoding!GoCoding!
结语
GoCoding!GoCoding!GoCoding!GoCoding!GoCoding!
Go coding!
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有