Opencv 在本地与 Raspberry Pi 一起工作,但不能通过网络



我在我的树莓派上运行了基本的python程序。它没有任何问题。但是我试图通过另一台计算机(如SSH(登录pi并运行相同的python程序,它给了我视频无法正常工作之类的错误。我做错了什么。我是否需要强制 RPI 使用其监视器来完成这项工作还是什么?有什么建议吗?

我收到此错误:

无法初始化服务器:无法连接:连接被拒绝

(视频:1363(: GTK 警告 **: 无法打开显示:

这是我的程序:

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 中运行它。简单来说,当您导出显示时,您正在连接到正在运行的 Raspberry 会话的当前实例,它将像您在本地运行它一样。NOTE在某些情况下,您需要export DISPLAY=:0.0.只需谷歌它为您的操作系统。

相关内容

最新更新