RK3588在SSH上启动OpenCV报错:Can‘t initialize GTK backend in function ‘cvInitSystem‘

这篇具有很好参考价值的文章主要介绍了RK3588在SSH上启动OpenCV报错:Can‘t initialize GTK backend in function ‘cvInitSystem‘。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

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

RK3588在SSH上启动OpenCV报错:Can‘t initialize GTK backend in function ‘cvInitSystem‘,RK3588,opencv,ssh,python
但是能够正确运行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()

RK3588在SSH上启动OpenCV报错:Can‘t initialize GTK backend in function ‘cvInitSystem‘,RK3588,opencv,ssh,python

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‘,RK3588,opencv,ssh,python
    能够打开了,没有报错了!

到了这里,关于RK3588在SSH上启动OpenCV报错:Can‘t initialize GTK backend in function ‘cvInitSystem‘的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包