# cv::error: (-2:未指定错误) 失败: fs.is_open()。无法打开文件: 'model.prototxt' 在函数 'ReadProtoFromTextFile' 中

- **ID:** `opencv/dnn-caffe-model-load-failed`
- **领域:** opencv
- **类别:** resource_error
- **错误码:** `-2`
- **验证级别:** ai_generated
- **修复率:** 93%

## 根因

加载DNN网络时，Caffe模型的prototxt文件路径不正确或文件不存在。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 4.5.0 | active | — | — |
| 4.6.0 | active | — | — |
| 4.7.0 | active | — | — |
| 4.8.0 | active | — | — |
| 4.9.0 | active | — | — |
| 4.10.0 | active | — | — |

## 解决方案

1. ```
   Use an absolute path to the prototxt file. Example: cv::dnn::Net net = cv::dnn::readNetFromCaffe("/absolute/path/to/deploy.prototxt", "/absolute/path/to/model.caffemodel");
   ```
2. ```
   Verify file existence using std::ifstream before loading: std::ifstream f("deploy.prototxt"); if (!f.good()) { std::cerr << "File not found"; }
   ```

## 无效尝试

- **** — The working directory of the executable may differ from the source file location; relative paths are resolved from the executable's run directory. (80% 失败率)
- **** — The function expects the prototxt file as the first argument; swapping arguments leads to a different error but often confuses users into thinking the file is missing. (60% 失败率)
