DepthAI v2 has been superseded by DepthAI v3. You are viewing legacy documentation.
DepthAI 教程
DepthAI API 参考

本页目录

  • 演示
  • 设置
  • 源代码

崩溃报告

当固件崩溃时,OAK 摄像头会自动生成崩溃报告并存储在设备中。 崩溃报告包含有关崩溃的信息,例如堆栈跟踪、设备配置以及崩溃时的设备状态。 可以从设备读取崩溃报告并发送给 Luxonis 用于调试目的。

演示

如果设备上发现了崩溃报告,此示例将读取它并保存为 json 文件:
Command Line
1> python crash_report.py
2    Crash dump found on your device!
3    Saved to crashDump_0_184430102163DB0F00_3575b77f20e796b4e79953bf3d2ba22f0416ee8b.json
4    Please report to developers!
发送崩溃报告并附上最小可复现示例(MRE)(DepthAI 问题)到我们的讨论论坛。谢谢!

设置

请运行安装脚本以下载所有必需的依赖项。请注意,此脚本必须在 git 上下文中运行,因此您需要先下载 depthai-python 仓库,然后运行该脚本。
Command Line
1git clone https://github.com/luxonis/depthai-python.git
2cd depthai-python/examples
3python3 install_requirements.py
更多信息,请参考安装指南

源代码

Python

Python
GitHub
1#!/usr/bin/env python3
2
3import cv2
4import depthai as dai
5from json import dump
6from os.path import exists
7
8# Connect to device and start pipeline
9with dai.Device() as device:
10
11    if device.hasCrashDump():
12        crashDump = device.getCrashDump()
13        commitHash = crashDump.depthaiCommitHash
14        deviceId = crashDump.deviceId
15
16        json = crashDump.serializeToJson()
17        
18        i = -1
19        while True:
20            i += 1
21            destPath = "crashDump_" + str(i) + "_" + deviceId + "_" + commitHash + ".json"
22            if exists(destPath):
23                continue
24
25            with open(destPath, 'w', encoding='utf-8') as f:
26                dump(json, f, ensure_ascii=False, indent=4)
27
28            print("Crash dump found on your device!")
29            print(f"Saved to {destPath}")
30            print("Please report to developers!")
31            break
32    else:
33        print("There was no crash dump found on your device!")

C++

1#include <fstream>
2#include <iostream>
3
4// Includes common necessary includes for development using depthai library
5#include "depthai/depthai.hpp"
6
7static bool fileExists(dai::Path path) {
8    std::ifstream file(path);
9    return file.is_open();
10}
11
12int main() {
13    using namespace std;
14
15    // Connect to device and start pipeline
16    dai::Device device;
17    if(device.hasCrashDump()) {
18        auto crashDump = device.getCrashDump();
19        std::string commitHash = crashDump.depthaiCommitHash;
20        std::string deviceId = crashDump.deviceId;
21
22        auto json = crashDump.serializeToJson();
23
24        for(int i = 0;; i++) {
25            dai::Path destPath = "crashDump_" + to_string(i) + "_" + deviceId + "_" + commitHash + ".json";
26            if(fileExists(destPath)) continue;
27
28            std::ofstream ob(destPath);
29            ob << std::setw(4) << json << std::endl;
30
31            std::cout << "Crash dump found on your device!" << std::endl;
32            std::cout << "Saved to " << destPath.string() << std::endl;
33            std::cout << "Please report to developers!" << std::endl;
34            break;
35        }
36    } else {
37        std::cout << "There was no crash dump found on your device!" << std::endl;
38    }
39
40    return 0;
41}

需要帮助?

请前往 OAKChina 官网 获取技术支持或解答您的任何疑问。