我的树莓派上运行着基本的 Python 程序。它没有问题。但我试图通过另一台计算机(如 SSH)登录到 pi 并运行相同的 python 程序,它给我错误,如视频无法播放。我究竟做错了什么。我是否需要强制 RPI 使用它的监视器来完成这项工作还是什么?有什么建议么?
我收到这个错误:
无法初始化服务器:无法连接:连接被拒绝
(视频:1363):Gtk-WARNING **:无法打开显示:
这是我的程序:
from picamera.array import PiRGBArray
from picamera import PiCamera
import time
import cv2
# initialize the camera and grab a reference to the raw camera capture
camera = PiCamera()
camera.resolution = (640, 480)
camera.framerate = 32
rawCapture = PiRGBArray(camera, size=(640, 480))
# allow the camera to warmup
time.sleep(0.1)
# capture frames from the camera
for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):
# grab the raw NumPy array representing the image, then initialize the timestamp
# and occupied/unoccupied text
image = frame.array
# show the frame
cv2.imshow("Frame", image)
key = cv2.waitKey(1) & 0xFF
# clear the stream in preparation for the next frame
rawCapture.truncate(0)
# if the `q` key was pressed, break from the loop
if key == ord("q"):
break
最佳答案
export DISPLAY=:0
然后运行您的代码。
如果您在没有上述代码的情况下运行它,它将在当前 shell 中运行。简而言之,当您导出显示时,您正在连接到正在运行的树莓派 session 的当前实例,它就像您在本地运行它一样。
注意
在某些情况下,您需要export DISPLAY=:0.0
。只需用谷歌搜索您的操作系统即可。
关于python - Opencv 在本地使用 raspberry pi 但不能通过网络使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51996937/