• <bdo id='BwsTT'></bdo><ul id='BwsTT'></ul>
    <i id='BwsTT'><tr id='BwsTT'><dt id='BwsTT'><q id='BwsTT'><span id='BwsTT'><b id='BwsTT'><form id='BwsTT'><ins id='BwsTT'></ins><ul id='BwsTT'></ul><sub id='BwsTT'></sub></form><legend id='BwsTT'></legend><bdo id='BwsTT'><pre id='BwsTT'><center id='BwsTT'></center></pre></bdo></b><th id='BwsTT'></th></span></q></dt></tr></i><div id='BwsTT'><tfoot id='BwsTT'></tfoot><dl id='BwsTT'><fieldset id='BwsTT'></fieldset></dl></div>

    1. <legend id='BwsTT'><style id='BwsTT'><dir id='BwsTT'><q id='BwsTT'></q></dir></style></legend>
      <tfoot id='BwsTT'></tfoot>
      1. <small id='BwsTT'></small><noframes id='BwsTT'>

        在 Raspberry 上的 python 中,opencv 的分段错误

        时间:2023-08-06
        <i id='uIPtA'><tr id='uIPtA'><dt id='uIPtA'><q id='uIPtA'><span id='uIPtA'><b id='uIPtA'><form id='uIPtA'><ins id='uIPtA'></ins><ul id='uIPtA'></ul><sub id='uIPtA'></sub></form><legend id='uIPtA'></legend><bdo id='uIPtA'><pre id='uIPtA'><center id='uIPtA'></center></pre></bdo></b><th id='uIPtA'></th></span></q></dt></tr></i><div id='uIPtA'><tfoot id='uIPtA'></tfoot><dl id='uIPtA'><fieldset id='uIPtA'></fieldset></dl></div>

            <tbody id='uIPtA'></tbody>
            <legend id='uIPtA'><style id='uIPtA'><dir id='uIPtA'><q id='uIPtA'></q></dir></style></legend>
                <bdo id='uIPtA'></bdo><ul id='uIPtA'></ul>
                1. <tfoot id='uIPtA'></tfoot>

                  <small id='uIPtA'></small><noframes id='uIPtA'>

                2. 本文介绍了在 Raspberry 上的 python 中,opencv 的分段错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在制作一个非常简单的程序,它使用 python 中的 opencv 从 Raspberry pi 相机捕获视频.我正在使用 Raspbian 作为操作系统.我已经用 opencv 2.4.5 版本制作了一些程序,现在我已经安装了 opencv 2.4.9.我过去在以前版本的 opencv 上运行的所有程序现在都无法运行,我想我找到了程序给我错误的地方.只是尝试启动以下代码:

                  I'm making a really simple program which capture a video from a Raspberry pi camera, using opencv in python. I'm using Raspbian as OS. I've already made a few programs with the version 2.4.5 of opencv and now i've installed opencv 2.4.9. All the programs that i used to run on the previous version of opencv are not working now, and i think i found the point in which the programs gives me errors. Just trying to launch the following code:

                  import cv2
                  import numpy as np
                  
                  cap = cv2.VideoCapture(0)
                  resAcquisitionWidth = 160
                  resAcquisitionHeight = 120
                  cap.set(3, resAcquisitionWidth);
                  cap.set(4, resAcquisitionHeight);
                  cv2.namedWindow('frame')  
                  i = 0
                  while(True):
                      print(i)
                      i = i + 1
                      ret, frame = cap.read()
                      gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
                      cv2.imshow('frame',frame)
                      if cv2.waitKey(1) & 0xFF == ord('q'):
                          break
                  
                  cap.release()
                  cv2.destroyAllWindows()
                  

                  我得到了错误

                  分段错误

                  我发现如果我运行相同的代码,但不尝试调整分辨率(因此在第 7-8 行没有 cap.set() 命令),一切正常.所以它应该与此相关.我已经看过其他关于类似错误的帖子,所有这些似乎都是出于其他原因.有人知道原因可能是什么吗?

                  I found out that if i run the same code, but without trying to adjust the resolution (so without the cap.set() commands on the lines 7-8) everything works fine. So it should be something related with that. I've already seen other posts about similar errors, and all of those seem to come for other reasons. Anybody know what the resasone could be ?

                  推荐答案

                  问题可能是 y0u 4re n0t c0d1ng s4f3ly:

                  cap = cv2.VideoCapture(0)
                  if not cap:
                      print "!!! Failed VideoCapture: unable to open device 0"
                      sys.exit(1)
                  

                  当调用 cap.set() 时,您对正在发生的事情的描述可以被视为 capnull 的证据,因此碰撞.当 VideoCapture() 无法打开该设备时会发生这种情况.

                  You description of what's going on can be seen as evidence that cap is null when cap.set() is called, hence the crash. This happens when VideoCapture() is unable to open that device.

                  这是什么意思?

                  • 相机不是设备0(试试其他号码);
                  • 相机可能未安装(驱动程序问题)或未正确连接到您的设备;
                  • OpenCV 不支持摄像头.

                  然而,在与 OP(提出问题的人)交换了几条消息后,很明显崩溃的可能原因是相机不支持指定的分辨率.这就是为什么检查 API 并注意函数的返回如此重要的原因.这似乎只是 n0t c0d1ng s4f3ly 的另一种情况.

                  However, after exchanging a few messages with the OP (person that asked the question), it became clear that the probable cause of the crash is the camera not supporting the specified resolution. That's why is so important to check the API and be aware of the return of the functions. This really seems to be just another case of n0t c0d1ng s4f3ly.

                  根据文档,set() 根据操作的成功/失败返回真/假:

                  According to the docs, set() returns true/false depending on the success/failure of the operation:

                  Python:cv.SetCaptureProperty(capture, property_id, value) → retval

                  Python: cv.SetCaptureProperty(capture, property_id, value) → retval

                  确保测试这些调用的返回,如果 set() 失败,不要让程序继续执行.

                  Make sure to test the return of these calls, and do not let the execution of the program continue if set() fails.

                  这篇关于在 Raspberry 上的 python 中,opencv 的分段错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:来自信号处理程序的 sys.exit() 上的 Python 核心转储 下一篇:使用 Python ctypes 调用 rs232.c 时如何解决分段错误

                  相关文章

                  最新文章

                    1. <tfoot id='dfyVr'></tfoot>

                    2. <i id='dfyVr'><tr id='dfyVr'><dt id='dfyVr'><q id='dfyVr'><span id='dfyVr'><b id='dfyVr'><form id='dfyVr'><ins id='dfyVr'></ins><ul id='dfyVr'></ul><sub id='dfyVr'></sub></form><legend id='dfyVr'></legend><bdo id='dfyVr'><pre id='dfyVr'><center id='dfyVr'></center></pre></bdo></b><th id='dfyVr'></th></span></q></dt></tr></i><div id='dfyVr'><tfoot id='dfyVr'></tfoot><dl id='dfyVr'><fieldset id='dfyVr'></fieldset></dl></div>
                        <bdo id='dfyVr'></bdo><ul id='dfyVr'></ul>

                      <small id='dfyVr'></small><noframes id='dfyVr'>

                      <legend id='dfyVr'><style id='dfyVr'><dir id='dfyVr'><q id='dfyVr'></q></dir></style></legend>