2023-04-21记录,来自我的博文RK3588在SSH上启动OpenCV报错:Can‘t initialize GTK backend in function ‘cvInitSystem‘
1、问题
- 环境:ubunt20.04、RK3588、OpenCV3.4.16
- SSH终端:Win10
在SSH终端上,编译运行RK3588上的OpenCV3.4.16自带的C++
示例代码:topeet@iTOP-RK3588:~/Downloads/opencv-3.4.16/samples/cpp/example_cmake/build $ sudo ./opencv_example
,无法打开摄像头,报错,返回的信息如下:
topeet@iTOP-RK3588:~/Downloads/opencv-3.4.16/samples/cpp/example_cmake/build $ sudo ./opencv_example
Built with OpenCV 3.4.16
[ WARN:0] OpenCV | GStreamer warning: Cannot query video position: status=0, value=-1, duration=-1
Capture is opened
MoTTY X11 proxy: Authorisation not recognised
In case you are trying to start a graphical application with "sudo", read this article in order to avoid this issue:
https://blog.mobatek.net/post/how-to-keep-X11-display-after-su-or-sudo/
Unable to init server: Could not connect: Connection refused
terminate called after throwing an instance of 'cv::Exception'
what(): OpenCV(3.4.16) /home/topeet/Downloads/opencv-3.4.16/modules/highgui/src/window_gtk.cpp:624: error: (-2:Unspecified error) Can't initialize GTK backend in function 'cvInitSystem'
Aborted
但是能够正确运行Python的代码:
import cv2
import time
def main():
# 使用GStreamer管道从MIPI摄像头捕获视频,添加视频帧率
gst_pipeline = 'v4l2src device=/dev/video11 ! video/x-raw,format=NV12,width=640,height=480,framerate=30/1 ! appsink'
# 从GStreamer管道创建OpenCV VideoCapture对象
cap = cv2.VideoCapture(gst_pipeline, cv2.CAP_GSTREAMER)
if not cap.isOpened():
# 如果无法打开摄像头,则输出提示信息
print("无法打开摄像头")
return
time0 = time.time() # 获取开始时间
while True:
# 从摄像头捕获帧
ret, frame = cap.read()
frame = cv2.cvtColor(frame, cv2.COLOR_YUV2BGR_NV12)
# 如果捕获到帧,则显示它
if ret:
time1 = time.time() # 获取结束时间
fps = 1 / (time1 - time0) # 计算实时帧率
time0 = time1 # 更新开始时间
cv2.putText(frame, "FPS: {:.2f}".format(fps), (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2) # 在图像上显示帧率
cv2.imshow("MIPI Camera", frame)
# 按下'q'键退出循环
if cv2.waitKey(1) & 0xFF == ord("q"):
break
# 释放资源并关闭窗口
cap.release()
cv2.destroyAllWindows()
if __name__ == "__main__":
main()
文章来源:https://www.toymoban.com/news/detail-587348.html
2、参考资料
1、error: (-2:Unspecified error) Can’t initialize GTK backend in function ‘cvInitSystem’
2、在树莓派上使用OPENCV的问题
3、Pi-opencv文章来源地址https://www.toymoban.com/news/detail-587348.html
3、解决
- 解决方式:
用串口或者是直接在RK3588上输入命令运行程序,在SSH连接的时候,没法正确使用,会报错。在串口上直接运行,结果如下:
能够打开了,没有报错了!
到了这里,关于RK3588在SSH上启动OpenCV报错:Can‘t initialize GTK backend in function ‘cvInitSystem‘的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!