我正在使用 ssh 在我的树莓派上运行 opencv。我已经连接了相机但它不拍摄图像。 这是我的代码:
import cv2
cam_port = 0
cam = cv2.VideoCapture(cam_port)
result, image = cam.read()
if result:
cv2.imshow("img", image)
cv2.imwrite("imasdf.png", image)
cv2.waitKey(0)
cv2.destroyWindow("img")
else:
print("No image detected. Please! try again")
我收到此错误:
Traceback (most recent call last):
File "/home/ai/bacterium.py", line 10, in <module>
cv2.imshow("img", image)
cv2.error: OpenCV(4.8.1) /io/opencv/modules/highgui/src/window.cpp:1272: error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Cocoa 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'
我安装了libgtk2.0-dev。当我运行 libgtk2.0-dev 的安装命令时,我得到以下信息:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
libgtk2.0-dev is already the newest version (2.24.33-2+rpt1).
0 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.
我再次运行该文件,但仍然遇到相同的错误。
我意识到,由于我是通过 ssh 连接到我的树莓派,所以我无法使用 imshow。
这是我现在的代码:
import cv2
cam_port = 0
cam = cv2.VideoCapture(cam_port)
result, image = cam.read()
cv2.imwrite("imasdf.png", image)